# Sine wave using arduino uno

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;
}
}
``````

//

• 1. How did you configure your timer ? 2. The `sin()` function takes something like 100 µs per call. Jun 12, 2020 at 10:59
• You could use `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. Jun 12, 2020 at 11:20
• A better method would be to generate a simple square wave then filter it into a sine wave. No need to mess with complex calculations or even lookup tables.
– Majenko
Jun 12, 2020 at 11:29