Go Down

Topic: PWM phase correct 10 bit with 2 timers (timer0 and timer 2). (Read 329 times) previous topic - next topic

MichaelBagieta

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)?

GolamMostafa

The following diagram says that every TC of ATmega328P has two programmable PWM channels.

DrAzzy

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
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

ron_sutherland

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/

if ATmega328pb then https://github.com/MCUdude/MiniCore/
I use an R-Pi Zero on an RPUpi shield to have a tool-chain at the network edge.

DrAzzy

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
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

sterretje

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.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up