Hi all,
I'm using an HC908GP32 as an engine controller and have been stumped by what I thought should be an easy thing. I want to generate a single pulse width for fuel injector control using Tim1 CH0 for injector 1, and CH1 for injector 2. Below is the code I'm using to initialize Port D, the Tim1 timer, the calling code for inj1 and the CH0 interrupt service routine. For some reason I'm not getting an interrupt for either channel. Any help would be greatly appreciated. Here' my code:
; MC68HC908GP32 40 Pin
; PORT D INIT
;***********************************************************************************************
; Port D
mov #$30,PORTD ; Move %00110000 to Port D Data Direction Register (preinit output
; pins 5,4 Hi)(Turn off injectors (inverted output)
mov #$FF,DDRD ; Move %11111111 to Port D Data Direction Register
; (PTD7,6 not available, outputs on PTD5,4,3,2,1,0
; = N/A,N/A,Inj1,Inj2,N/C,N/C,N/C,N/C
;***********************************************************************************************
; TIM1 INIT
;***********************************************************************************************
; Set up TIM1 as a free running ~1us counter. Set channels 0 and 1 for output
; compare, pulsewidth control of injectors. INJ1 on T1SC0 and INJ2 on T1SC1
;***********************************************************************************************
mov #%00110011,T1SC ; Move %00110011 into Timer1 Status and Control Register
; Bit7 TOF, (no effect)
; Bit6 TOIE, (Overflow interrupts disabled)
; Bit5 TSTOP, (counter stopped)
; Bit4 TRST, (Prescale and counter cleared)
; Bit3 Unimplemented
; Bits 2,3,0 (Prescale for bus frequency /
mov #$FF,T1MODH ; Move decimal 255 into T1 modulo reg Hi (Free running timer)
mov #$FF,T1MODL ; Move decimal 255 into T1 modulo reg Lo
mov #%01000000,T1SC0 ; Channel 1 Output compare, interrupt enabled
; Bit7 CHxF, CH0 output compare
; Bit6 CHxIE, CH0 interrupts enabled
; Bit5 MSxB, CH0 Buffered OC/PWM disabled
; Bit4 MSxA, CH0 Initial output level Hi (Inj1 off)
; Bit3 ELSxB, CH0 Pin under port control
; Bit2 ELSxA, CH0 Pin under port control
; Bit1 TOVx, CH0 No toggle on overflow
; Bit0 CHxMAX, CH0 No max duty cycle
mov #$00,T1CH0H ; Move decimal 0 to T1CH0 register Hi
mov #$00,T1CH0L ; Move decimal 0 to T1CH0 register Lo
bclr CHxF,T1SC0 ; Clear CH0 output compare flag
bclr CHxIE,T1SC0 ; Disable CH0 interrupt until we are ready
mov #%01000000,T1SC1 ; Channel 1 Output compare, interrupt enabled
; Bit7 CHxF, CH1 output compare
; Bit6 CHxIE, CH1 interrupts enabled
; Bit5 MSxB, CH1 Buffered OC/PWM disabled
; Bit4 MSxA, CH1 Initial output level Hi (Inj2 off)
; Bit3 ELSxB, Pin under port control
; Bit2 ELSxA, Pin under port control
; Bit1 TOVx, CH1 No toggle on overflow
; Bit0 CHxMAX, CH0 No max duty cycle
mov #$00,T1CH1H ; Move decimal 0 to T1CH0 register Hi
mov #$00,T1CH1L ; Move decimal 0 to T1CH0 register Lo
bclr CHxF,T1SC1 ; Clear CH1 output compare flag
bclr CHxIE,T1SC1 ; Disable CH1 interrupt until we are ready
mov #%01010011,T1SC ; Start timer, no overflow int, div / 8
; Bit7 TOF, (no effect)
; Bit6 TOIE, (overflow interrupts enabled)
; Bit5 TSTOP, (counter active)
; Bit4 TRST, (Prescale and counter cleared)
; Bit3 Unimplemented
; Bits 2,3,0 (Prescale for bus frequency /
;****************************************************************************
; CALL FOR INJECTOR PULSE 1 IN PROGRAM
;****************************************************************************
lda T1CNTL ; Unlatch any previous reads
lda pwcalc1L ; uS pulse width Lo byte
add T1CNTL ; A<-(A)+(M) Current counter value Lo byte
tax ; (A)->(X) Result to X
lda pwcalc1H ; uS pulse width Hi byte
adc T1CNTH ; A<-(A)+(M)+(C) Current counter value Hi byte
sta T1CH0H ; Write high byte timer output compare first
stx T1CH0L ; Then low byte
bclr inject1,portd ; Turn on Injector #1 (inverted drive)
bclr CHxF,T1SC0 ; Clear CH0 output compare flag
bset CHxIE,T1SC0 ; Enable CH0 interrupt
;****************************************************************************
; TIM1 CHANNEL 0 INTERRUPT SERVICE ROUTINE
;***************************************************************************
; - TIM1_CH0_ISR (Inj1 control)
;**************************************************************************
TIM1_CH0_ISR:
pshh
lda T1SC0 ; Read interrupt
bclr CHxF,T1SC0 ; Reset interrupt flag
bclr CHxIE,T1SC0 ; Disable interrupt
bset inject1,portd ; Turn Off Injector #1 (inverted drive)
pulh
rti
;***************************************************************************