Professional Documents
Culture Documents
PIC16f84 Ignition
PIC16f84 Ignition
hall effect sensor is employed near the flywheel to catch the first pulse by the
magnet.
trigger to the ignition driving mosfet/SCR is done by the microcontroller "RB0"
pin.
http://ot40.com/cdi_ignition.htm <- all the schematics are here
;=========================================================================
;;CDI for model engines
;Based on "Bike Advance" 4.23
;V1.0 09.14.2005 Jon-Magne Johansen
;=========================================================================
;==========================================================================
Title "Bike Advance"
; http://www.perso.wanadoo.fr/transmic/
; 01 11 04 Version 4.23 for 16F84a Thierry.P
; -------------------------------------------------------------------------
; Adaptation of the program Ign.txt "Auto Advance" from A. Nixon
; Title "Auto Advance" for 16c54
; 24 08 94 Version 1.0 A. Nixon
;==========================================================================
;
; Ign advance starts at 1500 engine RPM
;
; Ign full advance is at 16000 engine RPM
;
; dwell time is fixed at 1mS, = 10 X 100uS loops
;
; After 1500 RPM, the ignition advance is calculated in 116 steps.
; This continues up until 16000 RPM is reached.
;
;
; At a engine speed of 1200 RPM;
;
; 1200 / 60 = 20 revs per second
; 1 / 20 = 50mS per rev
; 1 rev = 360 degrees
;
; 36 degrees at 1200 RPM = (36 / 360) X 50 = 5mS
;
; Therefore maximum retard at 1200 RPM = 5mS after the firing
; point is reached. This figure remains constant down to 0 RPM.
;
; At a engine speed of 16000 RPM, maximum advance will have been reached,
; and ignition is immediately after the firing point is reached.
;
; The intermediate values will be looked up in an advance table map
; and will correspond to engine speed from 1500 RPM to 16000 RPM.
;
; As the engine RPM increases above 1500, the retard value becomes
; progressively lower until 5000RPM is reached, then increase until
; 16000 RPM is reached, whereby the retard value will be 0.
; Under 1500 RPM the retard value is fixed at 12ms
;
;
; Map holds retard values in 100uS loops for every loop change
; in rpm rate.
;
;
;
;==========================================================================
;
; PIC 16F84 wiring
;
;==========================================================================
;
; RA2 1+--O--+18 RA1
; pickup36°-----------> RA3 2| |17 RA0
; test jumper---------> RA4 3| |16 Osc ------ 4MHz
; +5V--+----R------ -> MCLR 4| |15 Osc ------ Quartz
; Ground--------- -- -- -- Vss 5| |14 Vcc ------ +5Vdc
; Thyristor <---- - -- RB0 6| |13 RB7 ------>PickupLED
; LEDrpmLimit <----- RB1 7| |12 RB6
; ReverseOutput<-- -- RB2 8| |11 RB5
; Strobe<------------- RB3 9+-----+10 RB4
;==========================================================================
;
; Versions
;
;==========================================================================
;==========================================================================
;
; Directives
;
;==========================================================================
list p=16f84a ; processor type
;
__config B'11111111110010'
; No code protect, PWRT on, no watchdog, Quartz 4to20Mhz
;
; Page 0: 0-FF page1: 100-1FF page2: 200-2FF page3: 300-3FF
;==========================================================================
;
; Register Definitions
;
;==========================================================================
W EQU H'0000'
F EQU H'0001'
;----- Register Files------------------------------------------------------
;==========================================================================
;
; Define
;
;==========================================================================
#DEFINE rotor PORTA,3 ; [pin2]= sensor input
#DEFINE coil PORTB,0 ; [pin6]= output to coil
#DEFINE revcoil PORTB,2 ; [pin8]= reverse output to coil
#DEFINE rpmmax PORTB,1 ; [pin7]= Min and Max RPM led
#DEFINE led PORTB,7 ; [pin13]= pickup led
#DEFINE strobe PORTB,3 ; [pin9] = strobe light output
#DEFINE test PORTA,4 ; [pin3] = test jumper input
;==========================================================================
;
; RAM Definition
;
;==========================================================================
;==========================================================================
;
; Main Program
;
;==========================================================================
movwf TMR0
;
;
btfss test ; if the test jumper is set (low)
goto testdelay ; goes to testdelay routine
mnloop movf TMR0,W
btfss STATUS,Z ; is TMR0=0 ?
goto mnloop ; no, main delay loop
;
movlw .231 ; yes, re-preset TMR0 (240max)
movwf TMR0
;
btfss rotor ; checks hall device. slow test if low, fast test if high
goto slowtest
goto fasttest
slowtest
bsf led
; Delay = 0.005 seconds
; Clock frequency = 4 MHz
;4998 cycles
movlw 0xE7
movwf d1
movlw 0x04
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
goto $+1
goto trigger ; triggers the thyristor
goto testdelay
fasttest
bsf led
; Delay = 0.3 seconds
; Clock frequency = 4 MHz
;299998 cycles
movlw 0x5F
movwf d1
movlw 0xEB
movwf d2
Delay_1
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_1
goto $+1
goto trigger ; triggers the thyristor
goto testdelay
trigger
bsf coil ; set output
bcf revcoil ; set reverse output
; Delay = 0.002 seconds
; Clock frequency = 4 MHz
movlw 0x8F
movwf d1
movlw 0x02
movwf d2
Delay_3
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_3
;2 cycles
goto $+1
bcf coil
bsf revcoil
goto testdelay
;
;=============================End JMJ=============================
end