About 5Hz-20KHz audio generator of mr. rb

Status
Not open for further replies.

kristo

New Member
Hello everyone

I was trying to code PIC pwm to generate audio sines, as did Mr. RB. But my maths cant find his results. He didnt publish code. After reading the article, I got: Taudio(min) = samples * Tpwm(min). From the article, he says for 20Khz he used 20 samples to form the sine, so the Tpwm(min) =1/20KHz * 1/20 = 1/400,000 s.=2.5us. So far, so good. The problem is how to get the duty cycle, which he said spans 5-95%, requiring a Tpwm always greater than Tdcycle, obviously. So, using the pwm formulas of the PIC, we have: Tpwm = (Ptper-1)/Fosc/4, so: Tpwm = (95-1)/40MHz/4= 9,4us required to allow that duty cycle spam. This is much greater than the 2.5us required to 20KHz out, so for me it seems impossible to assembly a 20khz audio with 20 samples with that amplitude spam. For that I would have to use a much faster clock. Any ideas where is my error or the trick he used?

article: romanblack.com/onesec/SineDDS.htm
 
1/20KHz * 1/20 = 1/400,000 s.=2.5us
So the clock into the PWM would be 400khz. Which requires Fosc=1.6mhz
If you have 20 clocks in a cycle then it looks like you should be able to get 5 to 95%. Each clock time = 5%.
I don't see the problem but I don't have that much knowledge.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…