Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some strangeness in the PWM interface #584

Open
sakian opened this issue Mar 21, 2022 · 2 comments
Open

Some strangeness in the PWM interface #584

sakian opened this issue Mar 21, 2022 · 2 comments

Comments

@sakian
Copy link
Contributor

sakian commented Mar 21, 2022

I've been using the PWM interface for a bit now and there's some strangeness in it. I just want to make sure I'm not missing anything before I potentially look to create a PR. Currently, I'm using the ATSAMD51J18A chip and trying to drive two PWM outputs on PA04 and PA05 using TC0. I think this should be possible, but running into a number of issues that made me look closer at the HAL implementation. Weird things I think I'm seeing are:

  • Difference between thumbv6m and thumbv7em: thumbv7em allows you to give it a pin, where thumbv6m doesn't. Seems like thumbv6m should be updated to take a pinout as well (talked about in Add basic support for PWM using TCC on D51/E54 #245).
  • thumbv7em TCx implements PwmPin and not Pwm: The TCx can control two pins, so I think these should implement Pwm?
  • Can only give it a single pin: Multiple pins can be driven from a single PWM (is this true for all chips?) so it makes sense that we should be able to give it multiple pins. Right now, I create pinouts for each pin to initialize them, but can only pass one to the PWM.
  • Not all supported PWM pins are defined in the HAL: So, for what I'm working on now, there is a TC0Pinout defined for PA05, but none for PA04 even though it's supported by the chip.
@bradleyharden
Copy link
Contributor

@sakian, yes, there are a few APIs in the HAL that could probably use an overhaul. I've notice the inconsistencies in the PWM modules myself.

If you want to tackle this, I would suggest making a mini-RFC first, outlining what you plan to do. I think that would reduce any wasted effort and also make it easier for reviewers to understand the approach without dealing with all the complications of the actual implementation.

@sakian
Copy link
Contributor Author

sakian commented Mar 22, 2022

Thanks, I will look into doing that!

More digging has made me realize why only the single channel PwmPin is being used for TCx. It's using the match PWM mode, where it resets when the counter matches CC0, and uses CC1 to drive the PWM output. I think I'll want to use normal PWM mode, where the counter is reset when it hits the max counter value (if using 16-bit counter) and control period using the peripheral clock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants