TPM2CH1 - HC9S08AW32 PWM Register problem

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

TPM2CH1 - HC9S08AW32 PWM Register problem

1,383 Views
Sany
Contributor III
My problem very easy, can PWM be turned off? how?
Below my assembly code:
 
ON_PWM          LDA       #%00001000 
                       STA       TPM2SC
                        LDA       #%00101000
                         STA       TPM2C1SC
                        LDHX     #$4000
                        STHX     TPM2MOD
                         LDHX     #$2000 
                          STHX     TPM2C1V
                         RTS

OFF_PWM       LDA        #%00001000 
                        STA       TPM2SC
                        LDA       #%00100000
                        STA       TPM2C1SC
                       LDHX     #$4000
                        STHX     TPM2MOD
                        LDHX     #$4000
                         STHX     TPM2C1V
                        RTS
 
When I put the OFF_PWM first (piezo buzzer no sound), then ON_PWM, my Piezo Buzzer will sound.
But if i put the other way, ON_PWM first (piezo buzzer sound), then OFF_PWM, my piezo buzzer still continue to sound. :-/
 
Anything I missing? Anyone can help? Any flag need to be cleared b4 turn off PWM? I can't find any answer from datasheet. Ty in advance.
Labels (1)
0 Kudos
2 Replies

345 Views
Sany
Contributor III
I made it stopped by setting bit CLKSB:CLKSA to 0:0 inside TPM2SC.
 
So, when I need to stop a timer, all the channels within the timer will be stopped as well?
Bits ELS1B:ELS1A inside TPM2C1SC can't be used to temporary stop the respective channel PWM output?
0 Kudos

345 Views
Wings
Contributor I
In your OFF_PWM code, where you do:
LDA #%00100000
STA TPM2C1SC
it certainly should have stopped it, since that sets ELSB:ELSA to 0:0, which places the output pin under general purpose control (i.e., no longer controlled by the timer).

Are you sure you don't have something else going on here?
0 Kudos