FABIO FUMAGALLI

9S08QG8 PWM for SINE GENERATION

Discussion created by FABIO FUMAGALLI on Jul 4, 2007
Latest reply on Apr 30, 2011 by david.miravete
Hi, I have a problem for generate a 8 bit PWM  signal for create a sine wave at 50Hz with PWM work at 15 or 20kHz.
The read for the sine tab work correctly, the generation signal of PWM is ok but when I paste all for the generation of signal the processor not work correctly because not read the value for load the PWM register.
I do with a table of 16 data for test and the code is the follow:
 
 
    lda   #$0f             ; lunghezza tabella sinusoide
    sta   TABMAX          ; lunghezza tabella sinusoide
 
lb00    ldhx  #TabSin           ; LETTURA TAB SINUSOIDE      read sin tab
lb01
        lda   ,x   
        LDHX   ,x
        STHX  TPMC1V                                              
        MOV   #$28,TPMSC           
        aix   #1     
        LDA   TABMAX       
        deca                      
        sta   TABMAX             
        cmp   #$00
        beq   go2      
go1     brCLR 7,TPMSC,go1       
        jmp   lb01
go2            
        lda   #$0f             ; lunghezza tabella sinusoide   lengh sin tab
        sta   TABMAX                                                
go3     brCLR 7,TPMSC,go3        
        jmp   lb00
       
TabSin:   
       dc.b $A0,$A0,$da,$da,$A0,$A0,$da,$da,$A0,$A0,$da,$da,$A0,$A0,$da,$da     ; only for test
EndTabSin
 
Where is my error? 
Thanks for the help.
Regards
 
Fabio

Outcomes