Announcements

Webinar: Integrated solutions for smaller, simpler low-voltage motor control design.
Join the webinar to experience!

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
grabnj
Level 1
Level 1
First reply posted First question asked Welcome!

I have the BLDC motor shield with TLE9879QXA40 for Arduino. I already updated the firmware to make setParameter() work. 

The motor works when I do the start motor in the setup void but it doesn't not turn on when the start motor is in a void loop. The LEDs blink correctly in the void loop, but the motor doesn't do anything. 

 

How to I get the motor to work in the void loop?

 
// Include the Shield library to your Arduino project
#include "TLE9879_Group.h"
 
int ButtonPin1 =2;
int ButtonPin2 = 3;
int ButtonPin3 = 5;
int OnTime = 500;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
 
// Declare Shield group object
TLE9879_Group *shields;
 
 
enum EState
{
  // Button 1 not pressed
  NoButton,
 
  // Button 1 is pressed
  FirstButton,
 
};
 
EState _state;
 
void setup()
{
    _state = NoButton;
   
// Initialize the Shield group object with the
// number of Shields in the stack
shields = new TLE9879_Group(1);
 
                     
  //Initialize shield group as object for board 1.
  
  shields->setMode(BEMF);
  //Sets mode to BEMF on board 1.
  
  shields->setMotorSpeed(-900);
  //Sets motor speed on board 1.
  
  shields->setParameter(BEMF_POLE_PAIRS,6,BOARD1);
  //Assigns number of pole pairs.
  shields->setParameter(BEMF_SPEED_TEST_ENABLE,1,BOARD1);
  
  // Enable and set LED to green, start the motor and let it run for 15 seconds,
  // then stop the motor
  shields->setLed(LED_ON, BOARD1);
  shields->setLedColor(COLOR_BLUE, BOARD1);
  shields->setMotorMode(START_MOTOR);
  
  delay(1000);
  shields->setLedColor(COLOR_BLACK ,BOARD1);
  shields->setLed(LED_OFF, BOARD1);
  shields->setMotorMode(STOP_MOTOR); 
}
 
 
void loop()
{
  switch (_state)
  {
  case NoButton:
    if (digitalRead(ButtonPin1) == HIGH)
    {
      _state = FirstButton;
      shields->setLedColor(COLOR_BLACK ,BOARD1);
      shields->setMotorMode(STOP_MOTOR);
      
    }
    else if (digitalRead(ButtonPin2) == HIGH)
    {
      shields->setMotorSpeed(1000);
      shields->setMotorMode(START_MOTOR);
      shields->setLed(LED_ON, BOARD1);
      shields->setLedColor(COLOR_BLUE, BOARD1);
    }
    else
    {
      shields->setLedColor(COLOR_BLACK ,BOARD1);
      shields->setMotorMode(STOP_MOTOR);
    }
    break;
 
  case FirstButton:
    if (digitalRead(ButtonPin1) == LOW)
    {
      _state = NoButton;
      shields->setLedColor(COLOR_BLACK ,BOARD1);
      shields->setMotorMode(STOP_MOTOR);
    }
    else if (digitalRead(ButtonPin3) == HIGH)
    {
      shields->setMotorSpeed(-1000);
      shields->setMotorMode(START_MOTOR);
      shields->setLed(LED_ON, BOARD1);
      shields->setLedColor(COLOR_GREEN, BOARD1);
    }
    else 
    {
      shields->setLedColor(COLOR_BLACK ,BOARD1);
      shields->setMotorMode(STOP_MOTOR);
    }
    break;
 
  default:
   // Other state, illegal.
   shields->setLedColor(COLOR_BLACK ,BOARD1);
   shields->setMotorMode(STOP_MOTOR);
   break;
  }
}
0 Likes
1 Solution
Raj_C
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 replies posted

Hi @grabnj,

Inside void loop if the  shields->setMotorMode(START_MOTOR); keeps on executed continuously it will not run the motor.

You may have to add the condition that if the motor start command has been sent once do not execute the start motor command again till the stop motor command is executed once.

If you have further question please let us know. Please let us know the flow diagram of your system(e.g. button press will be continuous or one instant). 

 

Thank you

Best Regards

Raj Chaudhari

View solution in original post

0 Likes
3 Replies
Raj_C
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 replies posted

Hi @grabnj,

Inside void loop if the  shields->setMotorMode(START_MOTOR); keeps on executed continuously it will not run the motor.

You may have to add the condition that if the motor start command has been sent once do not execute the start motor command again till the stop motor command is executed once.

If you have further question please let us know. Please let us know the flow diagram of your system(e.g. button press will be continuous or one instant). 

 

Thank you

Best Regards

Raj Chaudhari

0 Likes
grabnj
Level 1
Level 1
First reply posted First question asked Welcome!

Hi Raj, 

Thank you for the tip. 

 

I eliminated the loops looking for the button press for now. 

I tried just turning the motor on in the void loop by itself and it seemed to work but when I uncommented the motor start in the setup loop and still had the void loop motor start, the motor only turned on one time when I reset the Arduino. 

 

// Include the Shield library to your Arduino project
#include "TLE9879_Group.h"
 
int ButtonPin1 =2;
int ButtonPin2 = 3;
int ButtonPin3 = 5;
int OnTime = 500;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
 
// Declare Shield group object
TLE9879_Group *shields;
 
 
enum EState
{
  // Button 1 not pressed
  NoButton,
 
  // Button 1 is pressed
  FirstButton,
 
};
 
EState _state;
 
void setup()
{
    _state = NoButton;
   
// Initialize the Shield group object with the
// number of Shields in the stack
shields = new TLE9879_Group(1);
 
                     
  //Initialize shield group as object for board 1.
  
  shields->setMode(BEMF);
  //Sets mode to BEMF on board 1.
  
  shields->setMotorSpeed(-900);
  //Sets motor speed on board 1.
  
  shields->setParameter(BEMF_POLE_PAIRS,6,BOARD1);
  //Assigns number of pole pairs.
  shields->setParameter(BEMF_SPEED_TEST_ENABLE,1,BOARD1);
  
  // Enable and set LED to green, start the motor and let it run for 15 seconds,
  // then stop the motor
  shields->setLed(LED_ON, BOARD1);
  shields->setLedColor(COLOR_BLUE, BOARD1);
  shields->setMotorMode(START_MOTOR);
  
  delay(1000);
  shields->setLedColor(COLOR_BLACK ,BOARD1);
  shields->setLed(LED_OFF, BOARD1);
  shields->setMotorMode(STOP_MOTOR);
  delay(1000); 
}
 
 
void loop()
{
    shields->setLed(LED_ON, BOARD1);
  shields->setLedColor(COLOR_BLUE, BOARD1);
  shields->setMotorSpeed(900);
  shields->setMotorMode(START_MOTOR);
  
  delay(1000);
  shields->setLedColor(COLOR_BLACK ,BOARD1);
  shields->setLed(LED_OFF, BOARD1);
  shields->setMotorMode(STOP_MOTOR); 
   delay(1000);
}
0 Likes
Raj_C
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 replies posted

Hi @grabnj,

There is a possibility that when you stop the motor the system has entered into to the fault state. It is not easy to debug this issue.

I recommend you to try the FOC example which is comparatively stable then BEMF example.

Use same recommendation from above for the FOC example.

 

Thank you

Best Regards

Raj Chaudhari

0 Likes