I am an adruino hobbyist, i want to make sine wave using arduino uno, for that i using timer0 as interrupt, OCR0A set to 17 for 3.6khz interrupt(16000000/(100hz*36 interval)/256-1), If i am using only one pwm pin i am getting correct frequency but when i enable two pwm pin i am getting only half if the frequency, kindly advise what is wrong and how to correct it. ................................. This code i am getting correct frequency at PWM pin 9.
//
ISR(TIMER0_COMPA_vect)
{
OCR1A=(256+((((sin(num*3.14/180))*256))))/2;
//OCR1B=(256+((((sin(num*3.14/180))*256))))/2;
num=num+10;
if(num >= 360)
{
num = 0;
}
}
// ............................ This code i am getting only half of the previous frequency at PWM pin 9,10
//
ISR(TIMER0_COMPA_vect)
{
OCR1A=(256+((((sin(num*3.14/180))*256))))/2;
OCR1B=(256+((((sin(num*3.14/180))*256))))/2;
num=num+10;
if(num >= 360)
{
num = 0;
}
}
//
sin()
function takes something like 100 µs per call.OCR1B=OCR1A
since both are the same. But, assuming the problem is as StarCat said due to the ISR taking to long, I'd look into creating a table of SIN values.