cancel
Showing results for 
Search instead for 
Did you mean: 

How to Control AC Servo motor in STM 32 NucleoF746ZG board(PWM & Position)

kalai
Associate II

 

I am New for this domain(embedded systems), Currently i am doing robotics for some Motors(stepper, DC Servo, pumps and DC geared Motor), Now i started to writing the code for Alternate current servo motor. Herewith i have attached the reference of motor and driver,

I am using this type of servo is lifting up and down motion. whenever i run this servo motor at same stepper motor is also not working, but one by one working fine, These codes i have modified from the stepper motor code. The stepper motor is controlled by working in half mode. The servo motor is controlled by working in full mode.

Please find the attached main file, CPP file and main file.

Kindly help me on this issue. I am Using Keil Studio Cloud Software. 

AC_Servo Servo_Motor(PC_8,PC_9); // AC Servo (Pluse+,Pluse-)
DigitalOut Linear_Up_Motion(PE_9); // AC Servo up
DigitalOut Linear_Down_Motion(PG_15); // AC Servo Down
DigitalOut AC_Servo_Enable_Relay(PF_2); // AC Servo Enable(-24vdc)

 

kalai_0-1703048387449.jpeg

 

Servo Drive1200×1600 189 KB

 

kalai_1-1703048387510.jpeg

 

Servo Motor1200×1600 167 KB

 

void AC_Sero(int step,int direction)
{
int steps=0;
//steps =(step10000);
steps =(step
1000);
wait_ms(1);
AC_Servo_Enable_Relay=1;
wait_ms(1);
Linear_Up_Motion=0;
wait_ms(1);
Linear_Down_Motion=0;
wait_ms(1);
printf(“\n\n AC Servo Enable”);
if(direction==1)
{
printf(“\n UP direction”);
Linear_Up_Motion=1;
}
else
{
printf(“\n Down direction”);
Linear_Down_Motion=1;
}
Servo_Motor.stepp(steps);
wait_ms(1);
AC_Servo_Enable_Relay=0;
wait_ms(1);
Linear_Up_Motion=0;
wait_ms(1);
Linear_Down_Motion=0;
wait_ms(1);
}
int main()

{

printf("\n\n AC_Servo");
printf("\n\nEnter steps:");
scanf("%d",&Steps);
printf("\n\nEnter direction:");
scanf("%d",&Dir);
AC_Sero(Steps,Dir);
printf("Steps:%d \t,Direction:%d\t",Steps,Dir);

}

//--------------------------------------------------------------------------------------------------------------------------------------------------------

Servo.cpp
#include “AC_Servo.h”
#include “mbed.h”

AC_Servo::AC_Servo(PinName A0, PinName A1) : _A0(A0), _A1(A1), _A2(A2), _A3(A3) { // Defenition of motor pins
_A0=0;
_A1=0;
_A2=0;
_A3=0;
}

void AC_Servo::AC_Servo_Runn() {
for (int i = 4; i > 0 ; i–) {

switch (i)
{
case 0: {
_A0=1;
_A1=1;
_A2=0;
_A3=0;
}
break;
case 1: {
_A0=0;
_A1=1;
_A2=1;
_A3=0;
}
break;
case 2: {
_A0=0;
_A1=0;
_A2=1;
_A3=1;
}
break;
case 3: {
_A0=1;
_A1=0;
_A2=0;
_A3=1;
}
break;
}
wait_us(0); // wait time defines the speed
}

}

void AC_Servo::stepp(int num_steps) { // Servo function: number of steps
int count=0; // initalize step count
do {
AC_Servo_Runn();
count++;
} while (count<num_steps); // turn number of steps applied
}
//--------------------------------------------------------------------------------------
Servo.hfile

#include “mbed.h”

class AC_Servo {
public:

AC_Servo(PinName A0,PinName A1); //motor constructor
void stepp(int num_steps);
void AC_Servo_Runn();

private:

DigitalOut _A0;
DigitalOut _A1;
DigitalOut _A2;
DigitalOut _A3;

};

2 REPLIES 2
KnarfB
Principal III

Use "insert code sample" for better formatting of your code.

Check the waveforms at the 4 outputs with a (cheap) logic analyzer.

Start with more delay than 0 us.

AC_Servo c'tor does only get A0 and A1?

hth

KnarfB

i am not understating what you said,

i am using Keil Studio Software for my coding.