2

I am trying to get a nice sounding varying PWM to DAC, and intend to use a Sallen Key as part of an active low pass filter.

I set the Fast PWM at a max of 255 (WGM1[0-3] = 5) and set/clear OC1A upon comparing with OCR1A (1<< COM1A1)

I also update the value of OCR1A in 64 distinct steps, changing those steps around 15'000 times a second to create a specific sinusoidal shape.

As the chip works at 16 Mega Hertz, does this mean that one cycle of PWM is 16'000'000/256= 62.5 Kilo Hertz? If not, what is its resolution

Thank you!

B7th
  • 167
  • 8

1 Answers1

1

With the help of the comments, I decided to use variable PWM max values to match absolutely with the frequency. This resulted in a crispier sound that actually doesn't need the Sallen Key anymore.

For example, a low C natural, or 261.6Hz, updated 32 times for 8 full cycles of PWM give us, for a 16MHz chip, an period and amplitude of 238.

This means that having a prescaler of 8 (CS01), a period (OCR0A) AND a max potential duty cycle (ICR1) of 238, and going through 32 iterations of the sound sought for, I got the sound that I wanted and none of the wave groove that comes with a pulse duty cycle cut short.

Sure, it means less granularity when it comes to a Bb with a max duty cycle of 133, however it worked for me.

B7th
  • 167
  • 8