Hello everyone. I am working with Pololu baby orangutan Atmega328p, I wonder if there is a way to work with 2 independent PWM with the Timer1 in both pin PB1[OC1A] and pin PB2[OC1B]. I know that setting TCCR1A, TCCR1B and DDRB make it works, but it doesn’t.
Here is my code for working with PWM on pin PB1 OC1A
void setup()
{
pinMode(A5,INPUT);
pinMode(13,INPUT_PULLUP);
pinMode(12,INPUT_PULLUP);
pinMode(10,INPUT_PULLUP);
//PWMs
// pinMode(9 , OUTPUT);//9, OC1A, PB1
// pinMode(8 , OUTPUT);//8, OC1B, PB2
DDRB = ((1 << PB3) | (1 << PB1) | (1 << PB2));
DDRD = ((1 << PD3) | (1 << PD5) | (1 << PD6));
TCCR1A = ((1 << COM1A1) | (0 << COM1A0) | (0 << COM1B1) | (0 << COM1B0) | (1 << WGM11) | (0 << WGM10));
TCCR1B = ((1 << WGM13) | (1 << WGM12) | (0 << CS12) | (1 << CS11) | (1 << CS10));
ICR1 = (uint16_t)2499;
OCR1A = (uint16_t)0;
Serial.begin(115200);
}
void loop()
{
OCR1A = (uint16_t)outputValue;
if(outputValue<=2499)
outputValue++;
else
outputValue=0;
Serial.println(outputValue);
_delay_ms(5);
}
But when I prove it with only pin PB2 [OC1B] it does not work. Here is my code
void setup()
{
pinMode(A5,INPUT);
pinMode(13,INPUT_PULLUP);
pinMode(12,INPUT_PULLUP);
pinMode(10,INPUT_PULLUP);
//PWMs
// pinMode(9 , OUTPUT);//9, OC1A, PB1
// pinMode(8 , OUTPUT);//8, OC1B, PB2
DDRB = ((1 << PB3) | (1 << PB1) | (1 << PB2));
DDRD = ((1 << PD3) | (1 << PD5) | (1 << PD6));
TCCR1A = ((0 << COM1A1) | (0 << COM1A0) | (1 << COM1B1) | (0 << COM1B0) | (1 << WGM11) | (0 << WGM10));
TCCR1B = ((1 << WGM13) | (1 << WGM12) | (0 << CS12) | (1 << CS11) | (1 << CS10));
ICR1 = (uint16_t)2499;
OCR1A = (uint16_t)0;
OCR1B = (uint16_t)0;
Serial.begin(115200);
}
void loop()
{
OCR1B = (uint16_t)outputValue;
if(outputValue<=2499)
outputValue++;
else
outputValue=0;
Serial.println(outputValue);
_delay_ms(5);
}
I would thank any suggestion