I am working on PWM code (varying duty cycles) in which I used a Sine wave lookup table.
The code I have is based off of this site:
http://interface.khm.de/index.php/lab/experiments/arduino-dds-sinewave-generator/
I use timer two and the OC2B and OC2A registers (pin 3 and 11). Both pins generate the same output except one is an inverted output. How do i make a dead time between these outputs to make sure both are never on at the same time?
My code is as follows
void Setup_timer2() {
sbi (TCCR2B, CS20); //Set bit '1' to CS20
cbi (TCCR2B, CS21); //Set bit '0' to CS20
cbi (TCCR2B, CS22); //Set bit '0' to CS20
//OCR2A resiter(Pin 11) will have a non inverted PWM signal.
cbi (TCCR2A, COM2A0); //Set bit '0' to COM2A0
sbi (TCCR2A, COM2A1); //Set bit '1' to COM2A1
//OC2RB register(Pin3) will have an inverted PWM signal.
sbi (TCCR2A, COM2B0); //Set bit '1' to COM2B0
sbi (TCCR2A, COM2B1); //Set bit '1' to COM2B1
sbi (TCCR2A, WGM20); //Set bit '1' to WGM20
cbi (TCCR2A, WGM21); //Set bit '0' to WGM21
cbi (TCCR2B, WGM22); //Set bit '0' to WGM22
}
//******************************************************************
// Timer2 Interrupt Service at 31.372 KHz = 32uSec interupt
// This is the timebase REFCLOCK for the DDS generator
// FOUT = (M (REFCLK)) / (2 exp 32)
//******************************************************************)
ISR(TIMER2_OVF_vect) {
phaccu=phaccu+tword_m; //Soft DDS, phase accu with 32 bits
icnt_a=phaccu >> 24; //Use upper 8 bits for phase accu as frequency information
OCR2A=pgm_read_byte_near(sine256 + icnt_a); //Read value from sine table and send to PWM DAC (ORCR2A will be non inverted PWM)
OCR2B=pgm_read_byte_near(sine256 + icnt_a); //ORCR2B will be inverted PWM)
strajke:
I am working on PWM code (varying duty cycles) in which I used a Sine wave lookup table.
The code I have is based off of this site:
http://interface.khm.de/index.php/lab/experiments/arduino-dds-sinewave-generator/
I use timer two and the OC2B and OC2A registers (pin 3 and 11). Both pins generate the same output except one is an inverted output.
OCR2A=pgm_read_byte_near(sine256 + icnt_a);
//Read value from sine table and send to PWM DAC
// (ORCR2A will be non inverted PWM)
OCR2B=pgm_read_byte_near(sine256 + icnt_a); //ORCR2B will be inverted PWM
How? You're giving them both the same value. You appear to be missing a "!"
Henry_Best:
strajke:
I am working on PWM code (varying duty cycles) in which I used a Sine wave lookup table.
The code I have is based off of this site:
http://interface.khm.de/index.php/lab/experiments/arduino-dds-sinewave-generator/
I use timer two and the OC2B and OC2A registers (pin 3 and 11). Both pins generate the same output except one is an inverted output.
OCR2A=pgm_read_byte_near(sine256 + icnt_a);
//Read value from sine table and send to PWM DAC
// (ORCR2A will be non inverted PWM)
OCR2B=pgm_read_byte_near(sine256 + icnt_a); //ORCR2B will be inverted PWM
How? You're giving them both the same value. You appear to be missing a "!"
It is done by setting up up and down counting in the TCCR2A register by setting COM2A0,COM2A1 for OCR2A and COM2B0,COM2B1 for OCR2B
I don't claim to understand your code, but this is how I see it.
You want a see-saw, but you can't have a see-saw that starts with both ends on the ground. There's no 'half way' (evenly balanced) with PWM, it's either on or off, up or down.
Henry_Best:
I don't claim to understand your code, but this is how I see it.
You want a see-saw, but you can't have a see-saw that starts with both ends on the ground. There's no 'half way' (evenly balanced) with PWM, it's either on or off, up or down.
Code is based off
http://interface.khm.de/index.php/lab/experiments/arduino-dds-sinewave-generator/
I am doing SPWM to get a PWM with varying duty cycles. This in turn when put through a basic RC filter yeilds a nice sine wave.