Hello everybody, I'm new at this forum.
Well, I wanna to do a toggled pwm, so when port A is 1 the port B is 0.... and, of course, with the same duty cycle and frequency.
I tried to do this configuration with the register of TIMER2 of AVR328p, but only port A (I/O 11 of Arduino) works with PWM, another is always on 0
void setup(){
TCCR2B= 5; //OB00000100; fast PWM mode, 64 prescaler
TCCR2A= 227; //Ob11100011; port A inverted and port B not inverted - this configuration does the toggle.
OCR2A= 127; //50%duty cycle
OCR2B= 127;
}
void loop(){
delay(30);
}
PS: I only simulated in proteus 8 because I don't have oscilloscope
I need another configuration to it work??
PS2: I wanna to control a motor with this pwm.
Have you set your pins as outputs?
Your prescaler for 64 is wrong. It should be TCCR2B = 4. TCCR2B =5 is 128.
I can see outputs on both pins (approx 1khz) with this code, which is equivalent to yours with reference to register values from the Atmega 328 data sheet. I can see outputs on both pins, but don't have a scope to see if they are inverted as they should be. Perhaps someone with a scope could verify this code.
I arranged to use a scope on the output of the sketch in my previous reply. It indeed showed the two traces, with opposed polarity as intended. Previously I could count outputs on both pins, but could not determine phasing.
I do not know why you can only see one pin output with Timer2, and what the issue might be with your Arduino or scope, but I'm pretty sure the issue is not the code.