H-Bridge Controller Using Raspberry Pi Pico

Author Message
Planned Obsolescence

Joined: 23/06/2021
Location: Australia
Posts: 2
Posted: 10:56am 24 Jun 2021      

  Solar Mike said  
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.




I've only been looking into SPWM on a Pi for a few days and there's not much information applicable to the pi mcu, there's quite a bit of info on Arduino so I kept finding a lot of red herrings until I stumbled across your recent post.

I salvaged a 240v squirrel cage motor from a washing machine, it doesn't have a start cap just a dual run cap (one for each speed I assume) so it has negligible startup torque. I hoping I can reduce the slip by managing the start frequency until it gets up to about 75% of its working rpm and make it generate a bit of torque at low rpm without needing a massive inrush of current like a motor with a start cap.

Thanks for posting your code Mike.