Hi all,
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(num3.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
Please post your entire code (in code tags according to the forum guidelines, please!). There are obviously variables and code that you haven't shown, that can impact how that ISR operates. We can't help with what we can't see.
Some issues I can see:
Timer0 is used by the core for timing.
You recalculate the same floating point expression twice.
You needlessly convert radians to degrees, when the whole thing would work perfectly well in radians.
First, you approach is confusing compared to what you have done with Timer0. You are better to clear all the ide presets with TCCR1A = 0 and TCCR1B = 0 and then set the bits you want. The clearing of individual bits is then not necessary.
I see two errors. Do you have a data sheet and the register map in front of you?
Please post the complete code which demonstrates the problem. I strongly encourage the approach which starts with registers set to 0 and then set bits. The ide generates presets for the default pwm modes with analogWrite().
COM1B1 set to 1 that is correct....
I made a mistake in my first posting and I intended to say that you hadn't cleared COM1B0. It is a bit that is likely set by the ide.