I'm doing a project for which I need two measurements from two different ADCs and two different PWM signals related to them. The values measured are stored in the variables freq
and duty
. As the names state, I want one PWM signal's frequency to vary depending on the value of freq
, while the other one must change its duty cycle depending on duty
. The problem is that the first signal works alright but the second doesn't.
I'm using an ATmega328p. I've tried using a constant value instead of the variable duty
but the same happened. Instead of the PWM signal, the output pin (OC0B
) is constantly set high, i.e. 5 V DC. The function is really simple:
//Timer0 configuration
TCCR0A = 0b00100011;
TCCR0B = 0b00001001; //Fast PWM, no prescaler, non-inverted, out OC0B
OCR0B = duty;
I've triple-checked the values of the TCCR0
registers but everything seems to be correct. What could be causing this behaviour?
OCR0A
. – Edgar BonetOCR0A
if I want to use the B output? – Tendero