Hi,
I'm tryng to have Arduino Due generate a PWM with fixed frequency but sine modulated duty cycle.
I would like to attach the PWM duty cycle change to PWM generation timer interrupt.
So far I add a look at many forums but I couldn't find any way to do that.
Can you give any advice?
Thanks in advance!
Garvano
MarkT
2
You mean doing DDS (direct digital synthesis) in a timer overflow interrupt something like this:
#define MASK 0xFF
#define SHIFT 8
float sinetable [0x100] ;
volatile int phase ;
volatile int freq ;
ISR (TIMER1_OVF_vect)
{
phase += freq ;
OCR1A = 128 + 127 * sinetable [(phase>>SHIFT) & mask] ; // DDS
}
(In practice an integer table, not float, would be used for speed)