AtMega32
Junior Member level 3
I was following this tutorial
I am confused with couple things,
thought of pm'ing him but he haven't replied to my previous pm so may be he is busy, so can someone here helps me understand few things
Written by tahmid,
I am confused with couple things,
- Why TOP value is chosen as 999 and not something else (like 1200 or 499) is this just to set the PWM frequency to 16 Khz or is there some other reason ??
- Why sine peak value is taken as 990 and not 1000 or 256 or anything else ???
Most confused part is SET_Frequency - Lets say i want to take 128 samples of sine wave for the half cycle instead of 32 (tahmid taken that much)
Frequency of PWM is 16 Khz (62.5 us) as it is calculated earlier with this formula
Output frequency which want is 50 Hz (20 ms) for half cycle 10 ms
for my case with 128 samples, to calculate set frequency
Set Frequency = 2^16 / [(no. of sine values) * (no. of times each value is called)]
no. of times each value is called can be calculated using this as tahmid has done that in that blog
2*128*(62.5 us) * no. of times = 20 ms
no. of times each value is called = 1.25 - it is not an integer so do i take it as 2,
Set frequency = 2^16 / (128 * 2) = 256
- is this the correct way to calculate set frequency ?
- table pointer new is to be right shifted 9 times as to get a number between 0-128, and calling each value 2 times to complete the half cycle.
- but all the calculations go wrong as the output frequency desired is 50 Hz but with no. of times each value is called as 2 and set frequency = 256 , i would get
2* 62.5 us * 128 * 2 = 32 ms = 31.25 Hz and not 50 Hz
thought of pm'ing him but he haven't replied to my previous pm so may be he is busy, so can someone here helps me understand few things