Download presentation
Presentation is loading. Please wait.
Published byHugo Walsh Modified over 9 years ago
1
www.ee.ntou.edu.tw Department of Electrical Engineering, National Taiwan Ocean University Motor Control 5/2/2013 Richard Kuo Assistant Professor
2
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Outline ► Motor Introduction –9.NuMicro_MOTOR_CONTROL.ppt ► Stepper Motor Primer & Driving Method ► Exercise : use GPIO to control Stepper Motor Driver (Smpl_GPIO_StepMotor) ► DC Servo Motor Primer & Driving Method ► Exercise : use PWM to control DC Servo motor (Smpl_PWM_SG5010) ► DC Motor Primer & Driving Method ► Exercise : use GPIO to control DC motor driver (Smpl_GPIO_DCMotor)
3
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Electric Motors DC Motor Servo Motor Other Motors Brushless DC motor AC Motor Permanent-magnet DC motor AC Induction Motor AC Synchronous Motor Ultrasonic Voice Coil Motor AC Linear Motor Stepper Motor AC Servo Motor DC Servo Motor Microstepping Motor
4
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw DC Servo Motor
5
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Stepping Motor
6
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Stepping Motor
7
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Stepping Motor ► Stepping motors come in two varieties, permanent magnet and variable reluctance (there are also hybrid motors, which are indistinguishable from permanent magnet motors from the controller's point of view). ► Stepping motors come in a wide range of angular resolution. The coarsest motors typically turn 90 degrees per step, while high resolution permanent magnet motors are commonly able to handle 1.8 or even 0.72 degrees per step. With an appropriate controller, most permanent magnet and hybrid motors can be run in half-steps, and some controllers can handle smaller fractional steps or microsteps. ► For both permanent magnet and variable reluctance stepping motors, if just one winding of the motor is energised, the rotor (under no load) will snap to a fixed angle and then hold that angle until the torque exceeds the holding torque of the motor, at which point, the rotor will turn, trying to hold at each successive equilibrium point.
8
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Stepping Motor Types ► Variable Reluctance Motors ► Unipolar Motors ► Bipolar Motors ► Bifilar Motors http://homepage.cs.uiowa.edu/~jones/step/types.html
9
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Stepping Motor Types ► Multiphase Motors
10
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Step Motor Driving Methods ► Four phase Step Motor : 4 phases are A, /A, B, /B ► Diving Method as left –Wave Drive: single phase full step –Full Step Drive : two phase full step –Half Stepping : one/two phase half step –Microstepping
11
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Step Motor Driving Method ► Driver IC Interface –Control Pins : INA,INB,INC,IND –Power Pins : Vcc, Gnd
12
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Smpl_GPIO_StepMotor
13
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Smpl_GPIO_StepMotor ► 5V Step Motor ► Driver IC : TI ULN2003A ► Connections –Motor A+ connected to INA of ULN2003A, controlled by GPA3 –Motor A- connected to INB of ULN2003A, controlled by GPA2 –Motor B+ connected to INC of ULN2003A, controlled by GPA1 –Motor B- connected to IND of ULN2003A, controlled by GPA0 ► unsigned char CCW[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09}; //counter-clockwise sequence ► unsigned char CW[8] ={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08}; //clockwise sequence
14
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Smpl_GPIO_StepMotor unsigned char CCW[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09}; // 逆轉相 序表 unsigned char CW[8] ={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08}; // 正轉相序表 void CW_MOTOR(unsigned char deg) { int i=0,j=0; for(j=0;j<(deg);j++) { for(i=0;i<8;i++) { GPIOA->DOUT=CW[i]; DrvSYS_Delay(10000);//delay 10ms } void CCW_MOTOR(unsigned char deg) { int i=0,j=0; for(j=0;j<(deg);j++) { for(i=0;i<8;i++) { GPIOA->DOUT=CCW[i]; DrvSYS_Delay(10000);//delay 10ms } int main (void) { CW_MOTOR(d360); // 順時針轉 360 度 CCW_MOTOR(d180);// 逆時針轉 180 度 }
15
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw DC Servo Motor Driving Method ► DC Servo (SG-5010): remote controlled airplane/car/robot –Interface: pin1 = PWM, pin2 = Vcc, pin3 = Gnd ► Driving Method –PWM pulse duration is 20ms –High width = 0.5 ~ 2.5ms to control motor rotation ► Exercise: Smpl_PWM_DCServo –PWM controller generate 20ms pulse –ADC read from VR to control PWM high pulse width –ADC input variable resistance to control gripper open/close
16
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Smpl_PWM_DCServo
17
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Smpl_PWM_DCServo void InitPWM(void) { /* Step 1. GPIO initial */ SYS->GPAMFP.PWM0_AD13=1; /* Step 2. Enable and Select PWM clock source*/ SYSCLK->APBCLK.PWM01_EN = 1;//Enable PWM clock SYSCLK->CLKSEL1.PWM01_S = 0;//Select 22.1184Mhz for PWM clock source PWMA->PPR.CP01=5; //Prescaler 0~255, Setting 0 to stop output clock PWMA->CSR.CSR0=4; // PWM clock = clock source/(Prescaler + 1)/divider /* Step 3. Select PWM Operation mode */ //PWM0 PWMA->PCR.CH0MOD=1; //0:One-shot mode, 1:Auto-load mode //CNR and CMR will be auto-cleared after setting CH0MOD form 0 to 1. PWMA->CNR0=40000-1; PWMA->CMR0=2000; PWMA->PCR.CH0INV=0;//Inverter->0:off, 1:on PWMA->PCR.CH0EN=1;//PWM function->0:Disable, 1:Enable PWMA->POE.PWM0=1;//Output to pin->0:Diasble, 1:Enable }
18
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Smpl_PWM_DCServo int32_t main (void) { uint32_t u32Temp; char TEXT[15]=" "; UNLOCKREG(); SYSCLK->CLKSEL0.HCLK_S = 0;//select HCLK = 12MHz SYSCLK->PWRCON.XTL12M_EN=1;//Enable 12Mhz LOCKREG(); InitPWM();// initialize PWM InitADC();// initialize ADC Initial_panel(); // initialize LCD panel clr_all_panel(); // clear LCD panel /* Synch field transmission & Request Identifier Field transmission*/ print_lcd(0, "Servo Motor"); print_lcd(1, "PWM period:20mS"); print_lcd(2, "High Level:"); while(1) { while(ADC->ADSR.ADF==0);// wait till ADC conversion flag is 1 (conversion finished) ADC->ADSR.ADF=1; // write 1 to clear ADC flag u32Temp = 2500 + ADC->ADDR[7].RSLT * (1341) / 4096; // input ADC value PWMA->CMR0=u32Temp;// PWM0 CMR use ADC value to control high width sprintf(TEXT,"%d.%dmS",(u32Temp/2)/1000, (u32Temp/2)%1000); print_lcd(3, TEXT); // print string Delay(20000); ADC->ADCR.ADST=1; // set ADC to start conversion }
19
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw DC Motor Full-Bridge Driver IN1 IN2 IN1 IN2 Direction A : IN1=1 && IN2=0 Direction B : IN1=0 && IN2=1
20
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw DC Motor Control for Robot PWM UART or I2C +12V Ultrasonic Sensor to avoid collision Dual full-bridge DC motor driver MCU
21
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw L298 – Dual Full-Bridge DC Motor Driver
22
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw L298 – Dual Full-Bridge DC Motor Driver GND +5V +12V ctrl3 ctrl0 ctrl1 ctrl2 M0+ ctrl4 ctrl5 M0- M1+ M1-
23
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Smpl_GPIO_DCMotor
24
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Smpl_GPIO_DCMotor // L298N pin connections // pin1 Sense A : to Gnd // pin2 Output1 : to MotorA + // pin3 Output2 : to MotorA - // pin4 Vs : to +12V // pin5 Input1 : to GPA1 // pin6 Enable A: to GPA0 // pin7 Input2 : to GPA2 // pin8 Gnd : to Gnd // pin9 Vss : to +5V // pin10 Input3 : to GPA4 // pin11 EnableB: to GPA3 // pin12 Input4 : to GPA5 // pin13 Output3: to MotorB + // pin14 Output4: to MotorB - // pin15 Sense B: to Gnd // #include #include "NUC1xx.h" #include "Driver\DrvGPIO.h" #include "Driver\DrvSYS.h" #include "NUC1xx-LB_002\LCD_Driver.h" void InitGPIO() { DrvGPIO_Open(E_GPA,0,E_IO_OUTPUT); DrvGPIO_Open(E_GPA,1,E_IO_OUTPUT); DrvGPIO_Open(E_GPA,2,E_IO_OUTPUT); DrvGPIO_Open(E_GPA,3,E_IO_OUTPUT); DrvGPIO_Open(E_GPA,4,E_IO_OUTPUT); DrvGPIO_Open(E_GPA,5,E_IO_OUTPUT); DrvGPIO_ClrBit(E_GPA,0); DrvGPIO_ClrBit(E_GPA,1); DrvGPIO_ClrBit(E_GPA,2); DrvGPIO_ClrBit(E_GPA,3); DrvGPIO_ClrBit(E_GPA,4); DrvGPIO_ClrBit(E_GPA,5); } void MotorEnable() { DrvGPIO_SetBit(E_GPA,0); DrvGPIO_SetBit(E_GPA,3); }
25
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Smpl_GPIO_DCMotor void Forward() { DrvGPIO_SetBit(E_GPA,1); DrvGPIO_ClrBit(E_GPA,2); DrvGPIO_SetBit(E_GPA,4); DrvGPIO_ClrBit(E_GPA,5); } void Backward() { DrvGPIO_ClrBit(E_GPA,1); DrvGPIO_SetBit(E_GPA,2); DrvGPIO_ClrBit(E_GPA,4); DrvGPIO_SetBit(E_GPA,5); } void Right() { DrvGPIO_SetBit(E_GPA,1); DrvGPIO_ClrBit(E_GPA,2); DrvGPIO_ClrBit(E_GPA,4); DrvGPIO_SetBit(E_GPA,5); } void Left() { DrvGPIO_ClrBit(E_GPA,1); DrvGPIO_SetBit(E_GPA,2); DrvGPIO_SetBit(E_GPA,4); DrvGPIO_ClrBit(E_GPA,5); } void Stop() { DrvGPIO_ClrBit(E_GPA,0); DrvGPIO_ClrBit(E_GPA,3); } void Delay(uint8_t i) { for (i=0;i<10;i++) DrvSYS_Delay(1000000); }
26
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw Smpl_GPIO_DCMotor int main (void) { UNLOCKREG(); DrvSYS_Open(48000000); LOCKREG(); Initial_panel(); clr_all_panel(); print_lcd(0,"Smpl_GPIO_DCMoto"); InitGPIO(); MotorEnable(); print_lcd(1,"Move Forward...."); Forward(); Delay(10); print_lcd(1,"Move Backward..."); Backward(); Delay(10); print_lcd(1,"Turn Right......"); Right(); Delay(10); print_lcd(1,"Turn Left......."); Left(); Delay(10); print_lcd(1,"Stop............"); Stop(); }
27
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw General Disclaimer The Lecture is strictly used for educational purpose. MAKES NO GUARANTEE OF VALIDITY ► The lecture cannot guarantee the validity of the information found here. The lecture may recently have been changed, vandalized or altered by someone whose opinion does not correspond with the state of knowledge in the relevant fields. Note that most other encyclopedias and reference works also have similar disclaimers.similar disclaimers No formal peer review ► The lecture is not uniformly peer reviewed; while readers may correct errors or engage in casual peer review, they have no legal duty to do so and thus all information read here is without any implied warranty of fitness for any purpose or use whatsoever. Even articles that have been vetted by informal peer review or featured article processes may later have been edited inappropriately, just before you view them.peer reviewfeatured article No contract; limited license ► Please make sure that you understand that the information provided here is being provided freely, and that no kind of agreement or contract is created between you and the owners or users of this site, the owners of the servers upon which it is housed, the individual Wikipedia contributors, any project administrators, sysops or anyone else who is in any way connected with this project or sister projects subject to your claims against them directly. You are being granted a limited license to copy anything from this site; it does not create or imply any contractual or extracontractual liability on the part of Wikipedia or any of its agents, members, organizers or other users. ► There is no agreement or understanding between you and the content provider regarding your use or modification of this information beyond the Creative Commons Attribution-Sharealike 3.0 Unported License (CC-BY-SA) and the GNU Free Documentation License (GFDL);Creative Commons Attribution-Sharealike 3.0 Unported License GNU Free Documentation License
28
Department of Electrical Engineering, National Taiwan Ocean University www.ee.ntou.edu.tw General Disclaimer Trademarks ► Any of the trademarks, service marks, collective marks, design rights or similar rights that are mentioned, used or cited in the lectures are the property of their respective owners. Their use here does not imply that you may use them for any purpose other than for the same or a similar informational use as contemplated by the original authors under the CC-BY- SA and GFDL licensing schemes. Unless otherwise stated, we are neither endorsed by nor affiliated with any of the holders of any such rights and as such we cannot grant any rights to use any otherwise protected materials. Your use of any such or similar incorporeal property is at your own risk. Personality rights ► The lecture may portray an identifiable person who is alive or deceased recently. The use of images of living or recently deceased individuals is, in some jurisdictions, restricted by laws pertaining to personality rights, independent from their copyright status. Before using these types of content, please ensure that you have the right to use it under the laws which apply in the circumstances of your intended use. You are solely responsible for ensuring that you do not infringe someone else's personality rights.personality rights
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.