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

Feature Request: PWM Overfow interrupt #2683

Open
bmentink opened this issue Mar 6, 2022 · 10 comments
Open

Feature Request: PWM Overfow interrupt #2683

bmentink opened this issue Mar 6, 2022 · 10 comments
Labels
enhancement New feature or request

Comments

@bmentink
Copy link

bmentink commented Mar 6, 2022

Hi,

Requesting that support for PWM interrupts be added to the machine_rp2040_pwm.go driver, especially handling for the overflow interrupt.

This is required when you want to update PWM duty synchronous with the PWM cycle ..

From the manual:

A slice generates an interrupt request each time its counter wraps (or, if CSR_PH_CORRECT is enabled, each time the counter
returns to 0). This sets the flag corresponding to this slice in the raw interrupt status register, INTR. If this slice’s interrupt is
enabled in INTE, then this flag will cause the PWM block’s IRQ to be asserted, and the flag will also appear in the masked
interrupt status register INTS
@soypat
Copy link
Contributor

soypat commented Mar 6, 2022

What would the function/method look like for this? Is there a function you'd like replicated from the C SDK or micropython?

@bmentink
Copy link
Author

bmentink commented Mar 6, 2022

I have no idea at this stage, I will try and find out what Arduino C code implements..

@soypat
Copy link
Contributor

soypat commented Mar 6, 2022

Alright, I'll see if I begin dipping my toes into writing code again these days.

@bmentink
Copy link
Author

bmentink commented Mar 6, 2022

Cool, many thanks ...

@soypat
Copy link
Contributor

soypat commented Mar 6, 2022

Please take a look at #2684. Let me know if it works for you and what else would be required for your use case.

@bmentink
Copy link
Author

bmentink commented Mar 6, 2022

Wow that was quick, thanks will try it out ....

Remind me again how to patch that file with git ... or is it applied to the commit you did with the PWM max frequency fix, if so I already have that code pulled on my machine ..

EDIT: I did a git checkout rp2040-pwm-int to switch to that branch, and did a make, but I get this error: /usr/bin/ld: cannot find -llldMachO2 any idea's ?
Also does the above branch include the pwmfreqfix? `

EDIT2: Nevermind, I changed to the rp2040-pwm-int branch, grabbed a copy of the file, switch back to rp-2040-pwmfreqfix and copied the file to that branch, compiled, seemed to work just fine.

Now, how do I setup a callback function? It is not clear from the code ..
Don't we need a: pwm.SetInterrupt(machine.PinRising, handler) somewhere? .. like the way it's done for GPIO
.. or use the interrupt.xxxx mechanism ..

Cheers

@soypat
Copy link
Contributor

soypat commented Mar 7, 2022

Right, so apparently theres more to it than just setting up the IRQ. I've tried to dive into the pico SDK interrupt code but have been unable to port some parts of it since it's beyond my understanding on how the NVIC works for ARM processors. I'm really just a hobbyist who really wanted to use the pico and had no experience with embedded programming. My progress with the full interrupts implementation is over here https://github.com/soypat/tinygo/tree/rp2040-sync

@bmentink
Copy link
Author

bmentink commented Mar 7, 2022

I don't think you are "just" a hobbyist at all, based on all your code efforts. I am an embedded engineer, but have no experience with TinyGo, but happy to test code to improve TinyGo as I think it is great ..

I am using TinyGo to implement a sensorless BLDC motor controller at the moment and am struggling with real-time support, so any help with getting full interrupt support would be great.

I also think the Pico is a great embedded platform and when TinyGo gets full support for the PIO unit, it will be a great combo ..

@soypat
Copy link
Contributor

soypat commented Mar 7, 2022

Hmmmm, I'm gonna throw a little brainstorm your way: what about shorting a pwm signal to a GPIO pin with an interrupt set? Is that too hacky?

I'm also looking forward to PIO support... someday...

@bmentink
Copy link
Author

bmentink commented Mar 7, 2022 via email

@deadprogram deadprogram added the enhancement New feature or request label Apr 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants