|
4 | 4 | *warning* Work in progress |
5 | 5 |
|
6 | 6 | Implementation of current sensing on RP2350 using the PIO to read SPI based ADCs. |
| 7 | +Wiring: |
7 | 8 |
|
| 9 | +* SCK_PIN -> Clock pin shared with 3 ADCs |
| 10 | +* CSB_PIN -> Chip Select pin shared with 3 ADCs |
| 11 | +* D0, D1 D2 -> The 3 data output from the ADCs. Needs to be contigus (D1=D0+1 D2=D1+1) |
8 | 12 |
|
9 | 13 | 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. |
10 | | -The PWM pin is hardcoded to GPIO11 for now. |
11 | 14 |
|
12 | 15 |
|
| 16 | +TODO: |
| 17 | +* Init a the DMA or IRQ to read samples from PIO. |
| 18 | +* Activate the push of adc data in PIO program (disabled for tests) |
| 19 | +* Find a way to setup the trigger PWM from the driver, or change the arduino-foc lib. |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +# Example: |
| 24 | +``` |
| 25 | +// Open loop motor control example With current readings (work in progress) |
| 26 | +#include <SimpleFOC.h> |
| 27 | +#include "pico/stdlib.h" |
| 28 | +#include "hardware/pio.h" |
| 29 | +#include "hardware/clocks.h" |
| 30 | +#include <SimpleFOCDrivers.h> |
| 31 | +#include "current/rp2350/RP2350PIOCurrentSense.h" |
| 32 | +
|
| 33 | +static const uint SCK_PIN = 2; // sideset pin |
| 34 | +static const uint CSB_PIN = 3; // set pin |
| 35 | +static const uint D0_PIN = 4; // D0..D2 must be contiguous (D1=D0+1, D2=D0+2) |
| 36 | +static const uint TRIG_PIN = 8; // This need to be also configure as an extra PWM output with custom fixed duty cycle. For now let's just one of the phase as the trigger. |
| 37 | +
|
| 38 | +BLDCMotor motor = BLDCMotor(11); |
| 39 | +BLDCDriver3PWM driver = BLDCDriver3PWM(7, 8, 9); |
| 40 | +RP2350PIOCurrentSense curr = RP2350PIOCurrentSense(1.0, 4096,SCK_PIN, CSB_PIN, D0_PIN, TRIG_PIN); |
| 41 | +
|
| 42 | +float target_velocity = 0.2; |
| 43 | +
|
| 44 | +void setup() { |
| 45 | + Serial.begin(115200); |
| 46 | + SimpleFOCDebug::enable(&Serial); |
| 47 | + driver.voltage_power_supply = 12; |
| 48 | + driver.voltage_limit = 12; |
| 49 | + driver.init(); |
| 50 | + motor.linkDriver(&driver); |
| 51 | + motor.voltage_limit = 2; // [V] |
| 52 | + motor.controller = MotionControlType::velocity_openloop; |
| 53 | + motor.init(); |
| 54 | + Serial.println("Motor ready!"); |
| 55 | + _delay(100); |
| 56 | + curr.init(); |
| 57 | +} |
| 58 | +
|
| 59 | +void loop() { |
| 60 | + motor.move(target_velocity); |
| 61 | +} |
| 62 | +``` |
| 63 | + |
13 | 64 |
|
14 | 65 | ## Compilling the PIO program |
15 | 66 | To manually compile the PIO files (generating a .pio.h from a pio), you need to instal pioasm. |
|
0 commit comments