-
Notifications
You must be signed in to change notification settings - Fork 85
DO NOT MERGE WIP. Add support for external SPI ADC on rp2040 and rp2350 #65
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
base: rp2350_current_sense
Are you sure you want to change the base?
DO NOT MERGE WIP. Add support for external SPI ADC on rp2040 and rp2350 #65
Conversation
…itting 64bits per samples, in a ring buffer from witch the CPU can take the last samples.
…dc values from buffer)
|
I changed it into draft mode - that way it can’t be merged by accident… |
|
Memory usage change @ 4aa83b6
Click for full report table
Click for full report CSV |
…n, validated on RP2350 with 3 ADCs
… the loop, only do abc, only 12bits
…sing the same PIO with different state machine, ans also be compatible with other library that uses other PIOs (encoder for example)
|
Memory usage change @ ff1108c
Click for full report table
Click for full report CSV |
|
I was just about to ask you for the #if conditional compilation :-) thanks so much! Thanks for all your amazing effort on this! |
|
Memory usage change @ 488eff6
Click for full report table
Click for full report CSV |
|
I have a board in development that will hopefully allow me to test this out :-) the way I see it there is still the todo to make the trigger from the timer to the PIO.
|
|
Looking at this a bit more, I am not sure there is any TODO for the ArduinoFOC code... In the RP2350PIOCurrentSense we can do the following: #include "drivers/hardware_api.h"
// get the driver params
RP2040DriverParams* params = (RP2040DriverParams*)driver->params;
// create a 1PWM timer on the trigger pin using the same frequency
RP2040DriverParams* paramsTrigger = (RP2040DriverParams*)_configure1PWM(params->pwm_frequency, pinTRIG);
// set the correct duty cycle for the desired trigger point, we could provide a convenience function for that
_writeDutyCycle1PWM(0.29f, paramsTrigger);and for IRQ based triggering with WAIT IRQ in the PIO: #include "hardware/pwm.h"
RP2040DriverParams* params = (RP2040DriverParams*)driver->params;
pwm_set_irq_enabled(params->slice[0], true); // using PWM_IRQ_WRAP_0
// TODO check the IRQ isn't being used on the interrupt controller, because then it can't be used for PIO
irq_set_enabled(PWM_IRQ_WRAP_0, true);
// for the PIO code we will probably have to make an alternate version that uses WAIT IRQ PWM_IRQ_WRAP_0 1
// instead of the two WAIT GPIO instructions? |
Current Sense for RP2350
warning Work in progress
Implementation of current sensing on RP2350 using the PIO to read SPI based ADCs.
Wiring:
Temporarly, for this to work, we need to add a PWM chanell in Arduino-FOC rp2040 hardware specific files. The duty cyctle needs to be computed to trigger the ADC at the right-time.
TODO: