Jerky commutation with EM3215 gimbal motor, TMC6300, and RPI Pico

Hey all, it seems Im in need of some more experienced assistance. I’ve got a TMC6300 driver and an EM3215 gimbal motor, both from SparkFun. I’m trying to get the motor spinning in an open loop config with a raspberry pi pico. I’ve installed mbed os and I’m using viscode and platformio to write the code for simplefoc. No matter what I do, the motor seems to jerk from phase to phase. In my current configuration, it does spin, but the motor occasionally starts jumping back and forth between two of the phases. I’ve tried using different pwm pins, changing pwm frequency, swapping power supplies, and increasing and decreasing target velocity.

In this recording, you can see the motor jerking around and only actually rotating when there’s a tiny bit of friction applied.

My wiring is as follows:

| TMC6300 |     RPI Pico    |
|   VIO   |     3v3 Out     |
|   UL    | GP11 (PWM5,CHB) |
|   UH    | GP10 (PWM5,CHA) |
|   VL    | GP7  (PWM3,CHB) |
|   VH    | GP6  (PWM3,CHA) |
|   WL    | GP3  (PWM1,CHB) |
|   WH    | GP2  (PWM1,CHA) |

TMC6300 VIN,GND -> 2s 18650 for 7.4v nominal

If I’m understanding everything correctly, this means the motor has 7.4v, which I read on a different post that this is the optimal operating voltage for the EM3215. The TMC6300 is operating at 3.3v logic, and all half-bridge pairs are operating at the same clock speed since I’m using PWM channel pairs. I have tried wiring the half-bridges up to PWM1-CHA, PWM2-CHA, PWM3-CHA, PWM4-CHA, PWM5-CHA, and PWM6-CHA, but had the same result.

I wanna note, that I’m primarily a software guy, and haven’t touched C++ in far too long as I almost exclusively code in Python and MicroPython, but I’ve been learning a lot about the hardware, so please correct me on anything I said that may be wrong.

For the software portion, I followed along with sparkfun’s setup guide. While debugging, I started getting rid of the things I didn’t immediately need, like the commander (and the unnecessary comments).

#include <Arduino.h>
#include <SimpleFOC.h>

// EM3215 pole pairs (according to sparkfun)
BLDCMotor motor = BLDCMotor(7);
// TMC6300 -> RPI Pico
//  UH,   UL,   VH,  VL,  WH,  WL
// GP10, GP11, GP6, GP7, GP2, GP3
BLDCDriver6PWM driver = BLDCDriver6PWM(10,11, 6,7, 2,3);
float target_velocity = 6;

void setup() {
    // 2x 18650 in series for 7.4v nominal
    driver.voltage_power_supply = 7.4;
    driver.voltage_limit = 5;
    driver.pwm_frequency = 32000;

    motor.voltage_limit = 3;
    motor.controller = MotionControlType::velocity_openloop;

void loop() {
    // open loop velocity movement
    // using motor.voltage_limit and motor.velocity_limit

At this point I think I’ve exhausted all my troubleshooting options and I don’t know where to go from here. If anyone could help me figure out what’s wrong here or at least point me in the right direction, I would be greatly appreciative.

Thanks in advance!

Why using mbed? Can you use the raspberrypi platform instead? I don’t believe mbed is fully supported or tested.

Do you know whether the correct hardware specific driver is being selected:

It is possible because you’ve picked mbed as the platform it is using the generic hardware implementation. i.e. if you do what @VIPQualityPost suggests you might get code that knows your hardware doing the PWM config (which is much better).

I’d reduce the pwm frequency, there is typically a trade off between frequency and pwm resolution and 32K is quite high.

Your video looks a bit like your voltage limit is too low (but your value seems reasonable) or one of the phases is disconnected (although it doesn’t typically rotate, it usually just twitches). To establish if one of the phases isn’t working properly you can remove one of the motor cables (try removing one at a time). If any of the three ‘doesn’t make things worse’ then the removed phase is broken upstream somewhere.

I was unaware that there was a platform specifically for the pico. While doing my research (albeit short research) it seemed like mbed is needed. Can you point me to the proper documentation?

I’ll start with researching the proper platform, then move on to your other suggestions if I find no improvement. The only reason I chose mbed as the platform is because that’s what I found in a guide post (I don’t remember which one)

For most boards supported on PlatformIO, the valid “platforms” that are supported for a board (pico in this case) are documented on their boards registry. However for Pico, it seems documentation is missing… Raspberry Pi Pico — PlatformIO latest documentation

There are three options: mbed, earl-hillpower, and the “official” sdk (raspberrypi), for any RP2040 basd projects. You can set it by doing:
platform = raspberrypi in your platformio.ini file.

I reset my pico with a flash nuke uf2, and made a new project in platformio just to be safe. Here’s my ini file

; PlatformIO Project Configuration File
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
; Please visit documentation for the other options and examples

platform = raspberrypi
board = pico
framework = arduino
lib_deps = askuric/Simple FOC@^2.3.2
lib_archive = false
monitor_speed = 115200

How would I ensure I’m using the correct drivers?

I copied my main.cpp over and gave it a go, but I’m having the same problem. I’m gonna check the phase connections, but if that doesn’t do the trick, what else may be wrong?

Hey @IRWeidman did you solve your problem in the end?

With the platformio.ini as you have it, the correct drivers should be used. If you have a logic analyser or oscilloscope you can check it by verifying the PWM signals are being generated correctly, and with high frequency (the 32kHz you set).