Help with Arduino control of an Out Runner Brushless motor - Electronics Forums

Author Topic: Help with Arduino control of an Out Runner Brushless motor  (Read 30932 times)

Georg

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
  • I have a soldering iron and I'm not afraid to use it!
    • View Profile
Re: Help with Arduino control of an Out Runner Brushless motor
« Reply #15 on: March 09, 2013, 05:03:21 PM »
Your code runs perfectly with the L293 and my motor (max aprx. 600 rpm).
You have my full respekt for the code! I have no idea how it works ... like a miracle!

Electronics Forums

Re: Help with Arduino control of an Out Runner Brushless motor
« Reply #15 on: March 09, 2013, 05:03:21 PM »

ElectroNick

  • The forum moderator
  • Administrator
  • Full Member
  • *****
  • Posts: 154
  • Karma: +3/-0
  • The soldering iron is ON!
    • View Profile
    • Electronics Blog
Re: Help with Arduino control of an Out Runner Brushless motor
« Reply #16 on: March 09, 2013, 07:14:58 PM »
Your code runs perfectly with the L293 and my motor (max aprx. 600 rpm).
You have my full respekt for the code! I have no idea how it works ... like a miracle!
Thank you for stopping by, Georg! Well, not really a miracle,  :) just need to follow a certain sequence of voltage levels on the three ends of the windings and voila, round goes the rotor  ;)

If you wanted to see a little animation that shows how this works, check out this page about BLDC theory : http://elabz.com/brushless-dc-motor-with-arduino/  where you can pretty much stop and analyze (if you have time and desire to do so) each of the 36 steps that the motor goes through in one 360° revolution.

Both the software code and the schematics are slated for an update soon, so stay tuned.

Cheers!

Georg

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
  • I have a soldering iron and I'm not afraid to use it!
    • View Profile
Re: Help with Arduino control of an Out Runner Brushless motor
« Reply #17 on: March 10, 2013, 04:39:44 AM »
the theory is ok - but in your code is no digitialWrite or something like that!
The old code for the stroboscope is working, but probably I have a mechanical friction so the picture after the stroboscope is not standing still, but slowly moving away. The motor with the new code is much more stable and stronger. So I tried to integrate the stroboscope flash code from the old code into the new code, but was not successful (the strobo does not match). So I am waiting for your new code!!
Thanks for your ideas!

ElectroNick

  • The forum moderator
  • Administrator
  • Full Member
  • *****
  • Posts: 154
  • Karma: +3/-0
  • The soldering iron is ON!
    • View Profile
    • Electronics Blog
Re: Help with Arduino control of an Out Runner Brushless motor
« Reply #18 on: March 10, 2013, 07:56:39 PM »
the theory is ok - but in your code is no digitialWrite or something like that!
The old code for the stroboscope is working, but probably I have a mechanical friction so the picture after the stroboscope is not standing still, but slowly moving away. The motor with the new code is much more stable and stronger. So I tried to integrate the stroboscope flash code from the old code into the new code, but was not successful (the strobo does not match). So I am waiting for your new code!!
Thanks for your ideas!

Ah, I did not realize you are making the stroboscope, not just any BLDC related project.  The new code does not use digitalWrite  because it changes the state of the entire port (as well as the Input / Output definitions of each I/O line in the port) directly with DDRB and PORTB commands. My guess is that the old code can be adapted to use this approach, too, I'll just need some time to take a look.

The new code I was talking about was for an ESC (Electronic Speed Control) without the need to sync the steps with the LED flashes, but it's not all that difficult to add. I'll try to do that in the next couple of days.

BTW, let me see the integration of the stroboscope part into the new code - perhaps you've already done most of the work, I just have a feeling you need to adjust this line:
Code: [Select]
byte outModes[] ={0B00001010,0B00000110,0B00001100,0B00001010,0B00000110,0B00001100};
If you use bit 5 for LED flash (i.e. connect it to digital Pin 13), you'd need to have its bit changed to always being a "1" ( meaning it will always be an output ), like so:


byte outModes[] ={0B00011010,0B00010110,0B00011100,0B00011010,0B00010110,0B00011100};
Perhaps something else, just need to count the number of steps properly: in this type of the BLDC one 360° means 36 electrical steps (36 times windings are commutated differently), so to flash 12 times per one 360° revolution LED has to fire only on every third step.

Georg

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-0
  • I have a soldering iron and I'm not afraid to use it!
    • View Profile
Re: Help with Arduino control of an Out Runner Brushless motor
« Reply #19 on: March 11, 2013, 01:15:16 PM »
I have changed it according to your tips (btw now I understood it! :)). the LED flash is working and the CD is turning. But ... I could not find the right value for the flash frequency (parameter flashlimit)! I have 12 sections on the CD. But picture the sections do not stand still?! I was already counting it up by the programm starting with 1 - but none did work. What value is correct??
-----------------------
byte steps[] ={0B00000010,0B00000010,0B00001000,0B00001000,0B00000100,0B000000100};
byte outModes[] ={0B00011010,0B00010110,0B00011100,0B00011010,0B00010110,0B00011100};

unsigned int stepDelay = 50; // microseconds, multiplied by the value read from the pot on A0

byte potPin = 0;
byte bemfPin = 1;
byte bemfCompPin = 1;

long potPinValue;
int bEMF;
int bEMFTimeSet;
unsigned int actualStepDelay;
unsigned  long periodNow; // microseconds since last step
unsigned long serialPeriodNow;
unsigned long rpm;
int serialDelay = 5000;
int i=0; // counter for the steps

int currentFlash;
int flashlimit=3;

void setup() {
  Serial.begin(9600);
  pinMode(potPin, INPUT);
  pinMode(bemfPin, INPUT);
  pinMode(bemfCompPin, INPUT);

}

void loop() {

potPinValue = analogRead(potPin); 
actualStepDelay = potPinValue * stepDelay;

if ((micros() - periodNow) > actualStepDelay) {
    // time to switch windings to another state
    DDRB = outModes; // input or output? If input, it becomes high-Z, we can use those to measure back-EMF
    currentFlash = currentFlash + 1;

    if(currentFlash>flashlimit)
      {currentFlash=0;
      PORTB = steps | 0B00010010; //with flash
      }
    else
      {PORTB = steps;} // commutation
     
    periodNow=micros();
    if(i==2) { /*winding C is open, can read backEMF from it for speed calculations, compare to winding B which is zero in this step*/
    bEMF = analogRead(bemfPin);

    }
    i++;
    if(i>5) { i=0;}
   
}

if((millis() - serialPeriodNow) > serialDelay)
{
//flashlimit=flashlimit+1;
  rpm = 1666666.7/actualStepDelay; //actualStepDelay*36 = duration of 1 rotation in microseconds. 60,000,000/36 = 1666666.666667
  Serial.print("Actual Step delay: ");
 Serial.print(actualStepDelay);
 Serial.print(" | RPM: ");
 Serial.println(rpm);
 Serial.print("Last BackEMF comarative read: ");
 Serial.println(bEMF);
 Serial.println(flashlimit);
 serialPeriodNow=millis();
}

}

ElectroNick

  • The forum moderator
  • Administrator
  • Full Member
  • *****
  • Posts: 154
  • Karma: +3/-0
  • The soldering iron is ON!
    • View Profile
    • Electronics Blog
Re: Help with Arduino control of an Out Runner Brushless motor
« Reply #20 on: March 11, 2013, 07:38:02 PM »
Hi Georg, I have to admit - I'm not sure how the code you posted works at all - seems like both the LED flashes as well as the winding commutations are not in order at all. But anyway, I'll do  quick change in my new test circuit to see if I can add the strobe function really quick. Let me do that first and I'll post what comes out.

Cheers 

ElectroNick

  • The forum moderator
  • Administrator
  • Full Member
  • *****
  • Posts: 154
  • Karma: +3/-0
  • The soldering iron is ON!
    • View Profile
    • Electronics Blog
Re: Help with Arduino control of an Out Runner Brushless motor
« Reply #21 on: March 11, 2013, 11:40:19 PM »
I have changed it according to your tips (btw now I understood it! :)). the LED flash is working and the CD is turning. But ... I could not find the right value for the flash frequency (parameter flashlimit)! I have 12 sections on the CD.

Georg, I started a new post on the changes I made for the stroboscope. I have it running fine on discrete transistors but you should also be able to run in on L293 without an issue. Note that I moved the flash LED to Arduino's digital Pin 3 so we don't accidentally change its ON/OFF status while setting the motor windings by changing the entire Port B (digital 3 belongs to a different Port D)

Here is the updated schematics and the new software for the BLDC stroboscope project

sa898

  • Trusted Member
  • *
  • Posts: 3
  • Karma: +0/-0
  • I have a soldering iron and I'm not afraid to use it!
    • View Profile
Re: Help with Arduino control of an Out Runner Brushless motor
« Reply #22 on: June 06, 2013, 11:39:44 PM »
what changing in the program required to drive a bldc motor with 10 rpm and 12cog ?

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
13410 Views
Last post February 11, 2013, 12:15:21 PM
by ElectroNick
14 Replies
18730 Views
Last post June 07, 2013, 11:49:31 AM
by mamette
6 Replies
7128 Views
Last post June 14, 2013, 12:56:18 PM
by antmabee
9 Replies
20201 Views
Last post December 16, 2015, 12:03:18 PM
by PaulBailey
0 Replies
10496 Views
Last post April 05, 2015, 07:30:53 PM
by earslan

anything