connecting pwm output to low pass filter

For general Flowcode discussion that does not belong in the other sections.
Post Reply
siliconchip
Posts: 18
http://meble-kuchenne.info.pl
Joined: Wed Dec 16, 2020 10:38 am
Has thanked: 6 times

connecting pwm output to low pass filter

Post by siliconchip »

hi all
im generating a pwm output using a pic 12f1840 there are 3 pwm values with which i want to create 3 different tones when connecting to a common collector amp but im using a low pass filter between the 2 to convert the pwm to an anolgue voltage, im under the impression that the pwm needs to be 10 - 100 times greater frequency than that of the low pass cut off frequency that's fine but i want to select 3 frequencys within that band 1.2kHz, 1.6KHz AND 2KHz which means my pwm out put needs to be at least 20KHz constantly ? to avoid possible distortion ?, so my question is how can i produce a 20khz pwm signal but pick out the 3 desired frequency's, ive added a program where i select the frequency's i want in succession but max is 2000Hz, not sure if this all make sense or if ive got this all completely wrong but any advice would be appreciated
cheers bob
Attachments
buzzer test 2.fcfx
(15.74 KiB) Downloaded 86 times

BenR
Matrix Staff
Posts: 2133
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 573 times
Been thanked: 757 times

Re: connecting pwm output to low pass filter

Post by BenR »

Hello,

For a single tone output at a time the easiest way to do this is to change the PWM frequency by altering the prescalers, rollover period and duty. There is I beleive a ChangeFrequency function that should make this fairly easy. The PWM frequency itself would be changed to 1, 1.5, 2KHz. This is a square wave so you will likely be able to hear the harmonics in the audio output.

For multiple tones at once or for a higher fidelity signal you can keep the PWM frequency high say 20KHz and output frequencies by varying the duty at a corresponding rate. The easy way to do this would be to use the DSP components with one or more frequency generators connected through to a PWM output. You would use a timer interrupt to drive the timing of the DSP processing and keep in sync with the PWM.

For a really good output, audio quality I would recommend a DAC or an I2S driver. I've made relatively good audio using a 10-bit R2R DAC, much better than 10-bit PWM.

Post Reply