A little update on this, in case someone else is interested. I have found some things that need to be taken into account
Fast PWM mode details:
"1. timer2 is set to PWM mode..."
= timer 2 should be in fast PWM mode 3, where TOP is fixed at 0xFF and OCR2A controls duty cycle. The other mode, the fast PWM mode 7 reserves OCR2A for holding top and duty is controlled by OCR2B. This however means that output will be Arduino pin 10 = incompatible with game shield and Nootropic's Hackvision. Also, controlling PWM frequency is not required in this case.
"2. prescaler is set to clk/256 to get 62,5 kHz, this is just a matter of convenience (0xff = 100% duty)."
Actually, since TOP is at 0xFF to get 62,5 kHz prescaler is 1 => Frequency = clockspeed / 256 / prescaler.
I am close to working example with this project.
I have simulated the waveform synthesis on a PC using SFML library and a 8kHz signal. So far I have implemented:
- 2 oscillators with 7 waveforms + noise
- ADSR envelope
- oscillators can be combined in several modes: mixed, AM modulated, FM modulated and low-pass filter
- software low-pass filter for resultant wave
UPDATE:
Using this method, a simple toggle of OCR2A value in the hbi_hook with resolution 128x96 produces a square wave at 7811 hz