BLDC Controller phase 5: control

In the last post in this series I had just moved the Pico-BLDC code to C but it still wasn’t a fully-fledged motor controller. It would just run the motors at full speed forwards or backwards, keeping the phase of the magnets in lockstep with the rotor.

To make the driver useful, the next step was to add a control loop. To control a BLDC motor’s speed efficiently, the control loop needs to do a few things:

  • Keep the phase of the magnetic field 90 degrees ahead of or behind the position of the motor.
  • Vary the strength of the magnetic field to vary the force (and hence the torque).
  • Decide how much torque is needed. The simplest option would be to just control power like a throttle but I wanted the Pico to govern the speed of the motor.

I already had code to control the phase, so how do I control the throttle? All that’s needed is to apply a scale factor to the PWM values. Scale them all down and the effective voltage going to the motor goes down along with it’s torque.

How do we decide what throttle to set? I started with the absolute simplest approach just to prove to my self that it’d work:

  • Measure motor speed by comparing current sensor reading to last and dividing by time taken.
  • If going too slowly, add 1 to PWM scale factor.
  • If going too fast, subtract 1.

This worked (poorly as expected) but it proved that I had all the parts needed.

The next step was to implement PID control, I started with proportional control and iterated until I found something I was happy with. Really felt like I was getting somewhere at this point!

One thought on “BLDC Controller phase 5: control”

Leave a Reply

Your email address will not be published. Required fields are marked *