Hi,
I needed to setup Timer1 in the "Phase and Frequency Correct PWM Mode"
After reading the data sheet a dozen times I felt I had all ther correct register settings but still no output (PB5 and PB6). After more register searching I added the "DDR" setup for the data direction, where I had been using the pinmode method. Voila! we had PWM.
So my question is:
Why did the DDR method work and the pinmode not?
// below 3 lines did not result in an output on the PB5 and PB6 port pins.
pinMode(LED_BUILTIN, OUTPUT);
pinMode(13, OUTPUT);
pinMode(14, OUTPUT);
//replaced by these lines and the PWM functioned:
pinMode(LED_BUILTIN, OUTPUT);
PORTB = 0;
DDRB = (1<<DDB2)|(1<<DDB1);
Blinking LED worked in either method, only the PWM output required the DDR form.
Strange, but when i was using pinmode to make pin 9 output, the PWM (mode 14) on this pin was working.
If i was set it with DDRB |= (1 << DDB1); the PWM was not working.
On the setup, after DDR settings, I was using digitalwrite command to make the outputs low.
Next i set the Timer1.
When i deleted the digital write commands and replaced them with PORT settings the issue disappeared and everything is working properly.