Arduino Forum

Using Arduino => Microcontrollers => Topic started by: MichaelBagieta on Oct 10, 2018, 03:15 pm

Title: PWM phase correct 10 bit with 2 timers (timer0 and timer 2).
Post by: MichaelBagieta on Oct 10, 2018, 03:15 pm
Hi, i need to use pwm control for 4 devices. I've used phase correct pwm mode from timer/counter1 to get low frequency (~8Hz). But unfortunately it is possible only for timer/counter 1, which has 2 outputs. I need to get this frequency for another 2 devices. Is there any possibility to make 10 bit PWM phase correct control by using 2 x 8 bits timers (timer 0 and timer 1)?
Title: Re: PWM phase correct 10 bit with 2 timers (timer0 and timer 2).
Post by: GolamMostafa on Oct 10, 2018, 05:13 pm
The following diagram says that every TC of ATmega328P has two programmable PWM channels.
(https://forum.arduino.cc/index.php?action=dlattach;topic=572810.0;attach=277378)
Title: Re: PWM phase correct 10 bit with 2 timers (timer0 and timer 2).
Post by: DrAzzy on Oct 10, 2018, 07:17 pm
No, you cant get 10-bit hardware pwm with an atmega328 on more than 2 channels. You cant turn two 8 bit timers into a 10-bit timer, not if you want hardware pwm. Howver you can:

Use a different chip with 2 16-bit timers (attiny841 (use my core), atmega328pb (use minicore), atmega 1284p (use mightycore), atmega2560 (arduino mega), or atmega2561(use megacore)

The smaller flash versions of above will also work.

At only 8hz, you might be able to do it in software

Or you could use a non-AVR chip
Title: Re: PWM phase correct 10 bit with 2 timers (timer0 and timer 2).
Post by: ron_sutherland on Oct 10, 2018, 08:09 pm
ATmega328pb does some odd things with the pwm from Timer3, and Timer4. I have started to look more at ATmega324pb, which has three 16bit timers (Timer1, Timer3, Timer4) with A and B output compare registers.

if ATmega324pb then https://github.com/MCUdude/MightyCore/ (https://github.com/MCUdude/MightyCore/)

if ATmega328pb then https://github.com/MCUdude/MiniCore/ (https://github.com/MCUdude/MiniCore/)
Title: Re: PWM phase correct 10 bit with 2 timers (timer0 and timer 2).
Post by: DrAzzy on Oct 11, 2018, 07:02 am
It puts oc3b and oc4b on the same pin, so there is one fewer pwm pins available - but thats the only "weird" thing it does with the pwm. Unless you enable the oc modulation mode, of course. But iirc the atmega2560 has the same thing
Title: Re: PWM phase correct 10 bit with 2 timers (timer0 and timer 2).
Post by: sterretje on Oct 11, 2018, 01:14 pm
Use a different chip with 2 16-bit timers (attiny841 (use my core), atmega328pb (use minicore), atmega 1284p (use mightycore), atmega2560 (arduino mega), or atmega2561(use megacore)
Or a 32U4 based board.