An alternative way of dealing with PWM pins #593
MCUdude
started this conversation in
Future development discussion
Replies: 1 comment
-
|
I've updated the extended API documentation where the new PWM related functions have been added: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is something that has bugged me for quite a while with MegaCoreX. PWM pin routing is somewhat flexible on these modern AVRs, but I've been forced to place them in fixed positions that overlap the least with other peripherals. I think it's a shame that the possibility of re-routing the PWM output is thrown out the window. It is possible to reconfigure the PORTMUX and the various timers yourself, but it takes a lot of time and effort to dive into the datasheet to figure everything out when you just want a simple PWM signal on a different pin.
My idea is to supplement the Arduino framework with a few additional functions that will make routing and minor reconfiguring much easier. I'm not talking about full-blown TCA and TCB reconfiguring, just the possibility to re-route, change the resolution, and clock prescaler.
I've come up with the following functions and enums to pass along:
The development branch for this is located here. Again, the goal is not to expose every timer function imaginable; it's just a set of functions to make it easier to reconfigure the 8-bit PWM outputs. The reason why I'm using enums is to force the user to actually use this and hopefully throw an error if a non-compatible constant is used.
Let's say you want PWM output on pin PB2 using timer TCA0 and a custom prescaler. Easy!
@SpenceKonde I'd like to hear your thoughts on this. Have you been in a situation where you'd like to re-map PWM pins?
Beta Was this translation helpful? Give feedback.
All reactions