easy way to drive brushless motors with arduino

Hello,

I have posted a video with a Brushless motor being controlled with an Arduino using only the L6234 driver.

The example shows position control with Torque control, I dont measure current, but I do have a closed loop using an absolute encoder for the position (AS5048A).

Hope you enjoy the video

Pablo

Impressive Pablo!
I played a bit with a similar project but never got it off the ground.

Juanpablocanguro:
Hello,

I have posted a video with a Brushless motor being controlled with an Arduino using only the L6234 driver.

The example shows position control with Torque control, I dont measure current, but I do have a closed loop using an absolute encoder for the position (AS5048A).

Hope you enjoy the video

https://youtu.be/uUrcpAUttt8

Pablo

Would you happen to be able to help me with the programming. I have been trying to figure this one out to be able to control the position of a brushless motor.

A New video is up, this one demonstrates variable torque capabilities when controlling a BLDC motor :slight_smile:

Also displays haptic capabilities and dynamic emulation of mechanic feedback, if that is even a concept hahaha

INTP:
You don't control torque of motors.

That shows you know nothing about motor control! Its usually the inner loop in servomotor
controllers, upon which other control loops are built.

Have you seen this one?
https://www.dfrobot.com/wiki/index.php/FIT0441_Brushless_DC_Motor_with_Encoder_12V_159RPM?gclid=Cj0KCQiA6JjgBRDbARIsANfu58G12yhesZ5uhs9l4-1I2I8dJv5nwtBF5xrGaC7wmpoDbaGOfmJ2w7oaAmEYEALw_wcB

MarkT:
That shows you know nothing about motor control! Its usually the inner loop in servomotor
controllers, upon which other control loops are built.

I think the "you" should have been emphasized. "You" as an Arduino beginner should leave the torque control up to the ESC or servo module.

I still haven't seen a specific requirement from the OP to give any specific advice. Maybe the OP wants a gimbal (I can help with that) or maybe something else.

@Juanpablocanguro

TOPIC SPLIT
DO NOT HIJACK / NECRO POST !

Your other random code post was also deleted.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Here is the code for driving a brushless motor in open loop mode and slowly, watch the video on youtube: Brushless Motor Control with Arduino (slow rotation) Open loop - YouTube

//Program to run a brushless motor in open loop mode
const int potPin = A1;  // INPUT pot control for speed or position
//use ports 9, 10, 11 
const int motorPin1 =9;
const int motorPin2 =10;
const int motorPin3 =11;

// Variables
int pwmSin[] = {127,110,94,78,64,50,37,26,17,10,4,1,0,1,4,10,17,26,37,50,64,78,94,110,127,144,160,176,191,204,217,228,237,244,250,253,255,253,250,244,237,228,217,204,191,176,160,144,127}; // array of PWM duty values for 8-bit timer - sine function
int currentStepA=0; //initial pointer at 0   degrees for coil A
int currentStepB=16;//initial pointer at 120 degrees for coil B
int currentStepC=32;//initial pointer at 240 degrees for coil C
int pos;

//SETUP
void setup() {
  Serial.begin(9600);
//next commands will change the PWM frequency, so the annoying sound generated can be moved above human ear capability.
  TCCR0B = TCCR0B & 0b11111000 | 0x03 ;// changing this will also affect millis() and delay(), better to leave it default (0x03).
  TCCR1B = TCCR1B & 0b11111000 | 0x01; // set PWM frequency @ 31250 Hz for Pins 9 and 10, (0x03 is default value, gives 490 Hz).
  TCCR2B = TCCR2B & 0b11111000 | 0x01; // set PWM frequency @ 31250 Hz for Pins 11 and 3, (0x03 is default value, gives 490 Hz).
  
  ICR1 = 255 ; // 8 bit resolution for PWM
 
  pinMode(potPin, INPUT);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
}
 
void loop() {
  move();
}
  
void move()
{
  currentStepA = currentStepA + 1;  //Add 1 to make the motor move step by step.
  currentStepB = currentStepA + 16; //add 120 deg of phase to whatever position StepA is. 
  currentStepC = currentStepA + 32; //add 240 deg of phase to whatever position StepA is.
  
  currentStepA = currentStepA%48; //I used remainder operation or modulo to "wrap" the values between 0 and 47
  currentStepB = currentStepB%48;
  currentStepC = currentStepC%48;

  analogWrite(motorPin1, pwmSin[currentStepA]*0.5); //multipliying by 0.5 to reduce output torque to half as its being supplied with 12V and can get pretty warm. make this 1 if supply is 5V or if you know what you are doing ;)
  analogWrite(motorPin2, pwmSin[currentStepC]*0.5);
  analogWrite(motorPin3, pwmSin[currentStepB]*0.5);

  //Following send data to PLX-DAQ macro for Excel
  /*Serial.print("DATA,");
  Serial.print(pwmSin[currentStepA]);
  Serial.print(","); 
  Serial.print(pwmSin[currentStepB]);
  Serial.print(","); 
  Serial.println(pwmSin[currentStepC]);
  */

  //Read pot value
  int sensorValue = analogRead(potPin); 

// Select ONLY ONE of the following lines for constant speed, speed control or position control:

  //This will give you constant speed, remember if you changed TCCR0B to 0x01, then delay(64000) = ~1 second
  delay(5); 

  //This will give you open loop speed control with the potentiometer
  //delay(sensorValue/10);

  //This will give you open loop position control with the potentiometer
  //currentStepA = sensorValue/5; //divide by a number to affect the ratio of pot position : motor position

 ////////////

}

Pablo, where did you source your L6234D breakout board?

vinceherman:
Pablo, where did you source your L6234D breakout board?

See for his new board which has an integrated atmega 358 and it is newer version !

Hi Pablo,
I like your approach of keeping everything under control.
My current development board from Infineon is hard to convince that 90 degree of FOC angle is not the best for all applications. But no way to change this.
I wonder if I should order your new board, even if I dont need two motor ports.
I'm working currently on a commercial motor project and have some questions related to the specification of your board.

  1. Is it possible to use halls instead of an encoder?
  2. The motor is not an usual BLDC but a Lorentz-force motor (similar to PMSM). That type has terrible low
    inductance (0.4µH).
    Hence I would need the highest PWM-frequency possible. What do you think can your board reach? Also
    the mentiond FOC angle is tight to zero.
  3. With the hall sensors your correction trick wouldn't work for misaligned or wrong placed sensors. Do you
    think there is a workaround for this.
  4. The goal is not a servo-application but a continous drive up to 4000rpm. Is this in range of the board?

looking forward to your answers.