;*************************************************************************** ;****** ;****** PIC12F675. TCI ignition ;****** ;****** SPORTDEVICES AUG/19/2009 ;****** ;****** Tested on Kymco MXU250 ATV ;****** ;**************************************************************************** list p=12F675 #include p12F675.inc radix dec __CONFIG _HS_OSC & _WDT_OFF & _MCLRE_OFF & _PWRTE_ON ;setup values #define prescaler 8 ;2^8=256 #define dwell_time 5000 ;us #define delay_multiple 8 ;8 us, min 3 us #define max_rpm 9000 ;max rpm value #define idle_rpm 2000 #define min_rpm 200 ;min rpm value, if lower the program starts again #define rpm_cte 60*10000000/4/256 #define idle rpm_cte/idle_rpm #define min_period rpm_cte/max_rpm #define max_period rpm_cte/min_rpm ;(2^prescaler) #define dwell_constant dwell_time/102 ;1e6 /(10e6 / 4 / 256) #define pickup_hi GPIO,3 ;pin 4 #define pickup_lo GPIO,2 ;pin 5 #define coil GPIO,1 ;pin 6 #define low_rpm pack,0 #define hi_rpm pack,1 cblock 0x20 ;first free memory address!!! del,delh,per,perh,dwell,dwellh,tmr0h,pack tmp,tmph W_TEMP,STATUS_TEMP endc org 0x00 MOVLW 00 MOVWF 0x0A GOTO MAIN ;0A8 org 0x04 MOVWF W_TEMP SWAPF STATUS,W MOVWF STATUS_TEMP BTFSS INTCON,INTF GOTO L24 ;low pulse ext: BCF coil ;fire or turn off the coil BCF INTCON,INTF ;** L24: BTFSS INTCON,T0IF GOTO L25 timer0: INCF tmr0h,F MOVF tmr0h,W ; if(tmr0h>2) low_rpm=true; SUBLW 02 BTFSS STATUS,C BSF low_rpm ;low_rpm=true; MOVF tmr0h,W ;if(tmr0h>(max_period/256)) SUBLW max_period/256 BTFSS STATUS,C BCF coil ; output_low(coil); ;turn off the coil (residual spark will be made) BCF INTCON,T0IF ;** L25: SWAPF STATUS_TEMP,W MOVWF STATUS SWAPF W_TEMP,F SWAPF W_TEMP,W RETFIE read_array: addwf PCL,f ignition_start: ;9000 rpm retlw 20 retlw 21 retlw 22 retlw 23 retlw 24 retlw 25 retlw 26 retlw 27 ;8000 rpm retlw 28 retlw 29 retlw 33 retlw 38 retlw 44 retlw 50 retlw 55 retlw 60 retlw 65 retlw 70 ;7000 rpm retlw 69 retlw 74 retlw 77 retlw 80 retlw 81 retlw 82 retlw 83 retlw 84 retlw 85 retlw 86 retlw 87 retlw 89 retlw 91 retlw 93 ;6000 rpm retlw 97 retlw 100 retlw 103 retlw 107 retlw 113 retlw 119 retlw 124 retlw 131 retlw 137 retlw 140 retlw 145 retlw 150 retlw 157 retlw 160 retlw 165 retlw 170 retlw 175 retlw 176 retlw 177 retlw 178 ;5000 rpm ignition_end: ;.................... wait_pulse: L83: BTFSC pickup_hi ;while (input(pickup_hi)); ;wait line goes low GOTO L83 ;wait dwell BTFSC low_rpm ;if(!low_rpm) GOTO L8C BTFSC hi_rpm ;&&(!hi_rpm) GOTO L8C waitd: ;{ do: MOVF tmr0h,W ; tmp=make16(tmr0h,TMR0); MOVWF tmph MOVF TMR0,W MOVWF tmp MOVF tmph,W ;while((tmpidle) SUBLW (idle >> 8)-1 BTFSC STATUS,C GOTO midle XORLW 0xFF BTFSS STATUS,Z GOTO mult MOVF per,W SUBLW (idle & 0xff) BTFSC STATUS,C GOTO midle mult: BCF STATUS,C ; per=per<<1; RLF per,F RLF perh,F midle: INCF perh,F INCF per,F loop2: NOP ;delay_cycles(9); NOP NOP NOP NOP NOP NOP NOP NOP DECFSZ per,F GOTO loop2 DECFSZ perh,F GOTO loop2 ;} nofire: BTFSS low_rpm ;if(!low_rpm) BCF coil ; output_low(coil); ;fire or turn off the coil MOVLW dwell_constant & 0xff ;dwell-=(unsigned int16)dwell_constant; SUBWF dwell,F MOVLW (dwell_constant >> 8) BTFSS STATUS,C MOVLW (dwell_constant >> 8)+1 SUBWF dwellh,F ;silent_time, 768 us (256*3) CLRF del silent: DECFSZ del,F GOTO silent GOTO MAIN_LOOP END