Can HC08's Timer Module achieve accurate 20KHz PWM?

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

Can HC08's Timer Module achieve accurate 20KHz PWM?

2,104 Views
admin
Specialist II
I want to use HC908AZ32's timer module to achieve 20KHz PWM, and I believe I have config the register correctly, but I find that the frequency of the output PWM is 19.77KHz, is it the limit of the MCU's performace?
Labels (1)
0 Kudos
4 Replies

323 Views
peg
Senior Contributor IV
Hi Simon,
 
The exact frequency that you can produce depends on your main clock and then the limited divisors available in these parts and then the granularity of the counter.
You may not be able to achieve an exact frequency but usually the most important thing with PWM is the duty rather than the frequency. The duty will only be affected by the modulos you choose for the counter.
How about you tell us what clock, divisor and modulus you are using.
 
Regards
David
 
0 Kudos

323 Views
admin
Specialist II
Hi David,
 
Thanks for your help.
 
I use the 8MHz crystal, so I think the internal bus clock is 2MHz, and TIMA counter prescale PS[2:0] = 0x00, so the TIMA clock source is equal to 2MHz. The TIMA counter modulo register is set to 0x0064. Is there any issue?
 
Regards,
simon
0 Kudos

323 Views
bigmac
Specialist III
Hello Simon,
 
To achieve an exact 20 kHz PWM frequency, I think you will need to set the counter modulo register to 0x63.  With your current value of 0x64, timer overflow will actually occur every 101 bus cycles, and this would account for the frequency error.
 
With the adjusted modulo value, the normal range of PWM values would be 1 through to 99, with special control arrangements required to achieve 0 percent and 100 percent duty cycle.
 
Regards,
Mac
 
0 Kudos

323 Views
admin
Specialist II
Hi David and Mac,
 
I got it. Thanks for your help.
 
Regards,
Simon
0 Kudos