2022-03-12

Use Raspberry Pi CM4 for Motor Control

Recently, a customer asked me to design a testing machine used in his factory. The machine needs three motors and some peripherals. There should be a LCD display for operator to give commands and watch the progress.

Finally, I decide to use three BLDC motors and Raspberry Pi CM4 as the main processor. A dedicated 7" LCD display can be attached to the DSI port of CM4IO. That is very convenient. In order to control BLDC, I design a HAT board to be attached on CM4IO. The below picture shows 3D model view in KiCAD. This board is capable of controlling three BLDCs with total power up to 500W.


All three motors are controlled by sensorless FOC algorithms. Two dedicated sensorless FOC controllers are used for two 70W motors and a dedicated DSP is used to control the major 400W BLDC.

All the three motors (provided by customer) have built-in hall sensors. I don't need them for torque and speed control loops. But, I think they could be used for position control without adding additional encoders. So, I route the hall sensor outputs to GPIO pins of CM4. These hall sensors will generate interrupts to Pi CPU. The frequency could be up to 40KHz. In order to deal with this high interrupt rate, I design a Linux kernel module to handle it. The position control loop is also implemented in kernel module instead of user space program.

In summary, it is possible to implement time-critical motor control by CM4. You just have to do it in kernel module.