Controlling BLDC Motor with Arduino Nano ESP32 and L6234 Driver

Hello everyone,

I’m working on a project where I’m trying to control a BLDC motor using an Arduino Nano ESP32 and the L6234 motor driver. For motor control, I’ve written code in MicroPython to generate a sine wave and set the PWM duty cycle for each motor phase. However, I’m encountering an issue where the motor is not running as expected.

Here is the code I’m using:

from machine import Pin, PWM
import math
import time

frequency_pwm = 50_000 # 50 kHz (Maximum operating frequency of L6234)
resolution_bit = 12
resolution_int = (2 ** resolution_bit) - 1 

ena_pins = [Pin(17, Pin.OUT), Pin(18, Pin.OUT), Pin(21, Pin.OUT)]

for ena in ena_pins:
  ena.value(1)

pwm_pins = [Pin(8), Pin(9), Pin(10)]
pwms = [PWM(pin) for pin in pwm_pins]

for pwm in pwms:
    pwm.freq(frequency_pwm)


table_size = 360
sine_table = [(math.sin(math.radians(z)) + 1) / 2 * resolution_int for z in range(table_size + 1)]

def update_pwm(angle):

    # 1. Get three-phase indices
    index_a = angle % table_size
    index_b = (angle + 120) % table_size
    index_c = (angle + 240) % table_size

    # 2. Get PWM value from sine table
    duty_a = int(sine_table[index_a])
    duty_b = int(sine_table[index_b])
    duty_c = int(sine_table[index_c])
  
    # 3. Set pwm duty cycle
    pwms[0].duty_u16(duty_a)
    pwms[1].duty_u16(duty_b)
    pwms[2].duty_u16(duty_c)

def main():
    angle = 0
    steps = 1
    while True:
        update_pwm(angle)
        angle += steps
        time.sleep(0.005)
main()

Motor and Power Supply Details:

  • Motor Model: HT2205
  • Motor Type: BLDC
  • Rated Voltage: 12V
  • Rated Current: 0.66A
  • Pole Pairs: 7
  • Max. Speed: 1200 RPM
  • Power Supply: 12V, 0.66A (bench power supply)

Problem:

Despite the code being set up and the hardware connections verified, the motor is not spinning as expected. I'm using 12 V and 0.66 A to power the L6234 motor driver, but there is either no or jittery movement from the motor.

What I’ve Checked:

  • I've verified the update_pwm function generates the sine-waves correctly and with the right offsets for phase a, b and c:

  • The PWM frequency is set to 50kHz, which is the maximum operating range for the L6234 driver.
  • I've changed the frequency values to determine if higher and/or lower frequencies would work.
  • I've verified the enable pins are set to HIGH to activate the driver.
  • I've verified the motor wiring and power supply connections.

Questions:

  1. Is there anything obvious in my code that could be causing the motor not to run?
  2. Are there any adjustments needed in terms of PWM frequency or other settings for this setup?
  3. Does anyone have experience with controlling a BLDC motor with this combination of Arduino Nano ESP32 and L6234 driver?

I’d greatly appreciate any insights or suggestions on how to troubleshoot or correct this issue!

Raise tthe current limit of the power supply to get some margin.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.