H-Bridge Controller Using Raspberry Pi Pico

Author Message
Solar Mike

Joined: 08/02/2015
Location: New Zealand
Posts: 963
Posted: 09:31am 24 Jun 2021      

  Planned Obsolescence said  Nice work!

I've been looking into SPWM for a raspi too, I want to build a variable frequency drive for an induction motor to maximize startup torque and correct the power factor at low rpm in the hope of wringing a bit more efficiency out it.

I've seen SPWM done on Arduino many times but when you add variable frequency into the mix the coding becomes a bit more complex than a python solution would be (I imagine anyway)

Is your code open source or is it proprietary?

Here is a sample of the code that generates a spwm lookup table of sine values; each row is in format of a tuple containing 60 values for 180 degrees of a sine wave at a fixed modulation depth using 10 bit modulation.
The rows start at 70% mod depth and end at 100%. The data is passed into 2 of the high speed PIO state machines to output the SPWM on gp pins 0 1nd 1. All this occurs on CPU0.

CPU1 is used to update the index into the table running on a separate thread, currently it just loops through the mod depths and outputs a number that causes the sine output loop to switch to a different table index; this would be part of a feedback loop. Note code on CPU1 must not use more memory, ie use globals as there is no proper thread OS to manage things. I hade to make use of the garbage collector to free up memory generating the table data, as the PICO was running out.

Variable frequency is easily done by altering the sleep_us(value) in the main sine output loop, the current value of 150 = 50 Hz, lowering it speeds up proportionately.

Note: this is my first attempt at writing ANY python code, so it may not be the most efficient way to accomplish things, any python experts out there feel free to let me know how to speed it up.