QG8 Timer problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

QG8 Timer problem

1,400 Views
Kaare
Contributor III
Greetings all

Task:
Use the timer module to create a series of pulses with predefined length.

My solution:
Setup the timer module as edge-aligned PWM and set teh proper frequency and duty cycle. Then activate output compare interrupt and count the number of output compares until the desired pulses has been met. Then set the duty cycle to zero to stop the pulses.

;*******************************************************************************
Code implementation #1:
This code almost works. If i set PulseCount = 10, then the first two output compares happens right after each other, so theres no pulse to be measured on the output. The final 8 pulses gets transmitted just fine.

I've tried resetting the main counter in the PushUpBtn and PushDwnBtn with no change in behaviour.

;**************************************
; Initialization code

ldhx #28000
sthx TPMMOD

ldhx #0
sthx TPMC1V
sthx TPMC0V

mov #$0F,TPMSC ; Store settings - No TOF interrupt needed.
mov #$28,TPMC1SC ; Enable output compare interrupt, edge-PWM
mov #$28,TPMC0SC

;**************************************
; PushUpBtn

PushUpBtn:
pshhx
ldhx #PULSE_LEN
sthx TPMC0V ; Set the pulse length
pulhx
rts

PushDwnBtn:
pshhx
ldhx #PULSE_LEN
sthx TPMC1V ; Set the pulse length
pulhx
rts


;***************************************
; isrTPMCH1
; Timer output compare interrupt
;
; This interrupt is used to count the number
; of pulses sent to AP110. It decrements the
; PulseCount and stops the PWM when it reaches
; 0x00 in PulseCount

isrTPMCH1:
lda TPMC1SC
and #$7F ; Clear the output compare flag
sta TPMC1SC
dbnz PulseCount,isrTPMCH1End
ldhx #0
sthx TPMC1V

isrTPMCH1End:
rti


;***************************************
; isrTPMCH0
; See description of isrTPMCH1

isrTPMCH0:
lda TPMC0SC
and #$7F ; Clear the output compare flag
sta TPMC0SC
dbnz PulseCount,isrTPMCH0End
ldhx #0
sthx TPMC0V

isrTPMCH0End:
rti

;*******************************************************************************

;*******************************************************************************
Code implementation #2:
This code won't work at all. The output compare interrupt triggers fine, but the output stage on the pins never change. I can't figure out why this happens?

;**************************************
; Initialization code

ldhx #28000
sthx TPMMOD

ldhx #0
sthx TPMC1V
sthx TPMC0V

mov #$0F,TPMSC ; Store settings - No TOF interrupt needed.
mov #$28,TPMC1SC ; Enable output compare interrupt, edge-PWM
mov #$28,TPMC0SC

;**************************************
; PushUpBtn

PushUpBtn:
pshhx
bclr TPMC0SC_CH0IE,TPMC0SC ; Disable interrupt
sthx TPMCNT ; Reset the main counter
ldhx #PULSE_LEN
sthx TPMC0V ; Set the pulse length
lda TPMC0SC
and #$7F ; Clear the output compare flag
ora #$40 ; Enable interrupt @output compare
sta TPMC0SC
pulhx
rts

PushDwnBtn:
pshhx
bclr TPMC1SC_CH1IE,TPMC1SC ; Disable interrupt
sthx TPMCNT ; Reset the main counter
ldhx #PULSE_LEN
sthx TPMC1V ; Set the pulse length
lda TPMC1SC
and #$7F ; Clear the output compare flag
ora #$40 ; Enable interrupt @output compare
sta TPMC1SC
pulhx
rts


;***************************************
; isrTPMCH1
; Timer output compare interrupt
;
; This interrupt is used to count the number
; of pulses sent to AP110. It decrements the
; PulseCount and stops the PWM when it reaches
; 0x00 in PulseCount

isrTPMCH1:
lda TPMC1SC
and #$7F ; Clear the output compare flag
sta TPMC1SC
dbnz PulseCount,isrTPMCH1End
ldhx #0
sthx TPMC1V
bclr TPMC1SC_CH1IE,TPMC1SC ; Disable interrupt

isrTPMCH1End:
rti


;***************************************
; isrTPMCH0
; See description of isrTPMCH1

isrTPMCH0:
lda TPMC0SC
and #$7F ; Clear the output compare flag
sta TPMC0SC
dbnz PulseCount,isrTPMCH0End
ldhx #0
sthx TPMC0V
bclr TPMC0SC_CH0IE,TPMC0SC ; Disable interrupt

isrTPMCH0End:
rti


;*******************************************************************************

In both code implementations the vector table looks like this:

ORG $FFF2
dc.w isrTPMCH1
dc.w isrTPMCH0


Anyone got some ideas how to get the timer module to send out 10 well-defined pulses if i set PulseCount = 10?
Labels (1)
0 Kudos
Reply
1 Reply

335 Views
thisobj
Contributor III
Perhaps I missed it, but I can't find anywhere in your code examples where the TPM interrupts are enabled. The code lines,

====> mov #$28,TPMC1SC ; Enable output compare interrupt, edge-PWM
====> mov #$28,TPMC0SC

will not enable interrupts. Bit #6 is the interrupt enable bit.

The following lines will enable interrupts:

====> mov #$68,TPMC1SC ; CH0 - This sets the interrupt enable bit
====> mov #$68,TPMC0SC ; CH1 - This sets the interrupt enable bit
0 Kudos
Reply