# controlling 3x BLDC motors

I'd like to control 3x L6234 IC's (3x BLDC motors) with the cheapest microcontroller/board/lauchpad but I'm a bit confused about the requirements needed for the microcontroller. As I understood each motor needs 3 PWM control signals so I'd need 9 PWM's, but I'd also need 9 timers in the microcontroller right? Or can I use just 3 combined with prescalers?

I was thinking about using Arduino boards but they are still more expensive than texas launchkits (MSP430 launchpad and stellaris could do the work?).

• Projects engaged in for learning are a great thing. But if your goal is primarily to spin a number of motors, keep in mind that RC-hobby-market brushless ESC's start at around $10 USD for 12v/25A - including the FETs, MCU, and firmware (which you can probably replace with an open-source alternative if you prefer different features - or potentially even use as a platform to develop your own software). When comparing to the price of an Arduino, consider if you need the whole board, or just the microcontroller? – Chris Stratton Oct 17 '14 at 15:15 • well my goal is to use a cheap board and connect 3x L6234 to 9 PWMs to control the motor's spin independently. it would help if it was arduino based because it is easier to write the code – Electronics_Guy Oct 17 '14 at 15:59 • In reality, you will have a lot easier time using one$3 processor per motor. And it will be cheaper to make three copies of a small board, than one large board. But cheapest still will be buying the MCU and FETs already on a PCB, with working firmware already loaded, for about \$10/motor. – Chris Stratton Oct 17 '14 at 16:19

One L6234 driving one BLDC motor needs 3 PWM signals.
Three L6234 driving three BLDC motors need 9 PWM signals. This assumes each motor requires independent speed control.

Several manufacturers, for example Texas Instruments BLDC Cntrol have extensive documentation and videos on driving BLDC motors.

Their advice is to use a type of PWM called 'centred', 'symmetric' or 'up-down counting'.

Wikipedia PWM types shows the three types. One type counts up, another counts down, and the third is centred.

Up-counting PWM counts upwards, triggers the output pin 'on' when it matches the threshold value, reaches a maximum count, then resets the count to zero, switches the PWM 'off' and repeats. Down counting PWM is the opposite, with 'on' happening at the stat of the cycle, and 'off' being controlled by the timer threshold. (Some PWM timers can also reverse the sense of the PWM signal.)

The point is, either the start of the PWM signal becomes 'on' at a consistent timer, and the 'off' is controlled, or the 'off' is consistent and the 'on' controlled by the threshold value.

'Centred' PWM counts up, 'triggers-on', continues to count to the maximum, then counts backwards towards zero, 'un-triggers-off', continues down to 0, then repeats. So both the start and the end are controlled symmetrically. According to TI, this is the best way to drive BLDC control.

For BLDC control, typically, one timer can drive three PWM outputs, and control one BLDC motor. For one BLDC motor, the three PWM signals are synchronised, so they can be driven by a single, common timer. It is okay to use more timers to drive the PWM signals, it takes a couple of extra lines of code to keep the timers in synch.

An Arduino UNO has three timers, but each timer generates only 6 PWM, so it could drive two BLDC motors. The Arduino software use one of the timers to generate a 'millis clock', so that one couldn't necessarily be used for BLDC speed control. So it is awkward to use for more than one BLDC, using that L6234.

You are looking for a MCU which has three independent timers, each timer has at least three PWM outputs. There are a lot of MCUs which can do that. It appears that the L6234 could be driven by a 3.3V MCU.

AFAIK the Arduino Due has plenty of timers and PWM channels.

Lots of STM32F, which are available in very low-cost ST NUCLEO boards. These are under 10GBP including Tax. Those boards look like 'flash memory' so loading programs does not require any extra hardware programmer. The board includes hardware (SWD) debugging, too.

Nucleo's can be used with mbed software, so you don't need to install an IDE to get started.

Or can i use just 3 combined with prescalers?

If all three motors need to be controlled individually then you'll need 9 PWM signals, 3 for each L6234 driver. If the three motors didn't need individual control then 3 PWM outputs are probably all that is needed.

• Not driving the motors individually means no rotor position sensing, so they will probably have to be manually started rotating. – Chris Stratton Oct 17 '14 at 11:47
• i need individual control so i need 9 timers right? – Electronics_Guy Oct 17 '14 at 12:22
• 9 timers - I'm thinking that one timer per motor may be feasible because the phase relationship between one winding and the other two is defined - they are 120 degrees apart and this could be mathematically derived for the other two windings based on the speed of the motor. Maybe only three timers are required for all three motors. – Andy aka Oct 17 '14 at 12:28
• well i saw a code for gimbal motor control (by martinez i guess): //Hardware Abstraction for Motor connectors //DO NOT CHANGE UNLES YOU KNOW WHAT YOU ARE DOING #define PWM_A_MOTOR1 OCR2A #define PWM_B_MOTOR1 OCR1B #define PWM_C_MOTOR1 OCR1A #define PWM_A_MOTOR0 OCR0A #define PWM_B_MOTOR0 OCR0B #define PWM_C_MOTOR0 OCR2B and they use these Output Compare Registers A and B from Timer0, Timer1 and Timer2 for each PWM.I couldn't understand i can i change this to 3 motors (instead of 2) source: code.google.com/p/brushless-gimbal/source/browse/trunk/_BruGi/… – Electronics_Guy Oct 17 '14 at 14:30
• Actually, I expect (if the CPU can keep up) that you can share one timer with 9 distinct output compares (or any combination giving 9 total outputs). This is because while the commutation frequency needs to vary with the individual motor speed (and it's phase with detected position), the PWM frequency can be uniform (probably somewhere between from 20-40KHz). The commutation will be sampled at the PWM rate anyway, so you can use a DDS algorithm to produce the proper sampled PWM counts from the currently appropriate commutation phase/frequency for each motor. – Chris Stratton Oct 17 '14 at 15:11

how about multiplexing one PWM line for the three motor coils. Do you need to have individual control on each coil of one motor? Maybe I am misunderstanding this problem but I think it should be possible to have the same duty rate on each coil of a motor for one revolution and change the PWM duty for the next rev if needed. All three coils would have symmetrical current feeding/driving. Do you think this idea can work for you?

have fun, Alex

• Well thanks Alex. I don't really know if that is feasible or not. It's my first time controlling this king of motors (have just controlled servos and DC motors via PWM). As a help i used the BGC (brushless gimbal control) that i found online and it works for 2 motors (using 6 PWM signals and 3 timers). I'd like to change it but i couldn't understand the number of timers vs. the number of pwm signals. – Electronics_Guy Oct 17 '14 at 14:35
• @Haanz - it's a three phase motor and to rotate it properly, the voltages on all three phase are never all the same. – Andy aka Oct 17 '14 at 15:28