shakki87:
I'm using a digital pin to create a 1khz wave. The problem is that its a square wave and it has harmonics. I can hear the harmonic on my radio even in fm band > 90mhz. I'm trying to use a passive rc low pass filter but it seems it doesn't have any affect. Is there a way to create a wave that doesn't have harmonics? Either using some filter or by software?
With a digital pin you have to filter in hardware afterwards. With high-speed PWM then
a LPF you can get a much better approximation to a sine wave with less critical filtering
requirements. So a 60kHz PWM through a 2kHz-cutoff LPF will fare much better than
putting a square wave through a single RC filter.
Alternatively you can use a much more performant filter (say 6+ poles) using cascaded
active filter sections, so that it has a steep cutoff just above 1kHz. However such a
filter is both expensive in components and fixed at a single frequency.
In practice if you want to generate a quality sinusoid you use a DAC and generate
enough samples to greatly reduce the error, then LPF the residual noise away.
[one last possibility: LC resonant filter - however not easy for low frequencies and have the
risk of exceeding the supply voltage at resonance]