Code:lb00 ldhx #TabSinlb01 clr TPMC1VH mov x+,TPMC1VL mov #$28,TPMSC brclr TOF,TPMSC,* cphx #EndTabSin blo lb01 bra lb00TabSin dc.b $A0,$A0,$da,$da,$A0,$A0,$da,$da dc.b $A0,$A0,$da,$da,$A0,$A0,$da,$daEndTabSin
Ake wrote:Note that the program assumes that the conversion table starts at address $xx00.So put anorg $xx00before the TabSin label.
mov x+,TPMC1VL (the + is for auto-increment after the move) The TabSin table value isn't loaded to X, it's copied ('moved') from memory to memory using HX as pointer
Read the code carefully. First instruction initializes HX to the beginning of the table.
mingyee wrote:does that mean once this routine is called, I do not require to have any external pre-calculated pointer for #TabSin?
PWM uses an Output Compare. Normally, varying the pulse-width changes the volume, while varying the frequency changes the tone. (How you do it depends on your actual hardware design.)To generate tone, it's preferable to init my pin to PWM or Output Compare?Any difference between these 2 as PWM will also either set/clr output on compare?
tonyp wrote:PWM uses an Output Compare. Normally, varying the pulse-width changes the volume, while varying the frequency changes the tone. (How you do it depends on your actual hardware design.)
tone ldhx #tonetab tone1 clr TPM2C0VH mov X+,TPM2C0VL mov #$28,TPM2SC brclr TPM2SC_TOF,TPM2SC,* cphx #tonetabend blo tone1 rts
tonetab fcb $00,$7F,$94,$A7,$B9,$C8,$D5,$DE,$E4,$E6 fcb $E4,$DE,$D5,$C8,$B9,$A7,$94,$7F,$6C,$59 fcb $47,$38,$2B,$22,$1C,$22,$2B,$28,$47,$59,$6C tonetabend
mingyee wrote:Hi Bigmac,I've tried using the sine table you gave me & the TPM2MOD value.The waveform doesnt seems quite right.Another thing is that after executing mov X+,TPM2C0VL
I still can't see the respective Tonetab value on the memory table in the debug window.Doesnt this mean the value is not written into the register?
I can see some other problems and issues -
The code is intended for edge aligned PWM, not centre aligned as you appear to be operating. The instruction "mov #$28,TPM2SC" seems inappropriate for the AW60 device, as this enables centre aligned mode. Using BUSCLK as the TPM clock source, and no overflow interrupt, the value $08 appears more suitable.
To what value do you initialise the TPM2C0SC register? I suspect this should be a value of $28.
How many times does the "tone" sub-routine repeat to produce your plotted output (it appears to provide an output over about a 250 ms period)? Each call of the sub-routine will output a single sine wave cycle. For the anticipated output frequency, 250 ms would correspond to about 60 cycles. However, you will really need to use continuous output so that the filtered waveform can settle properly.
Regards,
Mac
mov #$28,TPMSC ; TPM: No int, ext source, prescale 1 clr PNTR ; Initialise pointer value clrh LOOP1: ldx PNTR ldx TabSin,x ; Get byte value from table sthx TPMC1V ; Set PWM value inc PNTR ; Increment for next table entry brclr TOF,TPMSC,* ; Wait for timer overflow mov #$28,TPMSC ; Clear overflow flag bra LOOP1 ; Loop always
mingyee wrote:
Hi, i also tried the method proposed by Peg (http://forums.freescale.com/freescale/board/message?board.id=8BITCOMM&thread.id=6656&view=by_date_as...) message 10 of 11.The code goes;Code:mov #$28,TPMSC ; TPM: No int, ext source, prescale 1 clr PNTR ; Initialise pointer value clrhLOOP1: ldx PNTR ldx TabSin,x ; Get byte value from table sthx TPMC1V ; Set PWM value inc PNTR ; Increment for next table entry brclr TOF,TPMSC,* ; Wait for timer overflow mov #$28,TPMSC ; Clear overflow flag bra LOOP1 ; Loop always
I'm still unable to write my lookup table value into the TPM2C0VL.Is there anything wrong?I've attached the debug window & waveform captured below.Btw, I'm using MC9S08AW60CFG.
The code will need to be modified to suit the smaller table size, possibly with the "inc PNTR" instruction replaced by the following code -
lda PNTR
inca
and #$1F
sta PNTR
This will restrict the value of PNTR to the range 0 - 31.
Regards,
Mac
bigmac wrote:The code will need to be modified to suit the smaller table size, possibly with the "inc PNTR" instruction replaced by the following code -lda PNTR
inca
and #$1F
sta PNTRThis will restrict the value of PNTR to the range 0 - 31.
Regards,
Mac
bigmac wrote:How many times does the "tone" sub-routine repeat to produce your plotted output (it appears to provide an output over about a 250 ms period)? Each call of the sub-routine will output a single sine wave cycle. For the anticipated output frequency, 250 ms would correspond to about 60 cycles. However, you will really need to use continuous output so that the filtered waveform can settle properly.
Regards,
Mac