Arduino-FOC icon indicating copy to clipboard operation
Arduino-FOC copied to clipboard

[FEATURE] Support 6-channel PWM with only TC4 on ATmega32u4

Open cinderblock opened this issue 2 years ago • 4 comments

I'd like to use some existing ATmega32u4 based driver boards. Theses are wired up to the 6-channel PWM output that is unique to the ATmega32u4's 10-bit High Speed Timer/Counter4.

AVR Pin Output Compare Arduino Pin
PC7 OC4A D13
PC6 OC4A~ D5
PB6 OC4B D10
PB5 OC4B~ D9
PD7 OC4D D6
PD6 OC4D~ D12

Looking at the sources in atmega32u4_mcu.cpp, it's clear that the code is only set up for a couple dedicated pins that don't fully overlap with the Timer 4 hardware outputs.

I realize this is an older IC but is there any interest in supporting this mode?

My very old implementation: https://github.com/cinderblock/3-Phase-Controller/blob/master/src/ThreePhase/Driver.cpp


PS, great to meet you at OpenSauce!

cinderblock avatar Jul 19 '23 02:07 cinderblock

Hey, this could be a nice addition, would you be interested to do a PR for this?

askuric avatar Jul 19 '23 09:07 askuric

Yes, I'm interested. But I won't have time to look much at this for the next 2, maybe 6+ weeks! (Moving offices, Burning Man, traveling to a wedding) So if anyone else wants to get started, be my guest!


To be sure, would this (new) code live in this repo or in the drivers repo?

cinderblock avatar Jul 19 '23 18:07 cinderblock

From my point of view it would be one of the PWM drivers in the main repository, or a modification to one of the existing AVR drivers…

runger1101001 avatar Jul 20 '23 15:07 runger1101001

Yep, I agree. This would go the the main library inside the file atmega32u4_mcu.cpp. I am going to try to provide you with a starting point @cinderblock, maybe even implement it completely, if I manage to get the time. Otherwise, don't hesitate to contact us when you start implementing it if you need some assistance.

askuric avatar Jul 20 '23 15:07 askuric