Pulse Width Modulation and Motor Control Mark Barnhill
Pulse Width Modulation and Motor Control Mark Barnhill Roy Dong Andrew Kleeves Micajah Worden Dave Seaton Facilitator: Professor Strangas
Agenda • • • Pulse Width Modulation Brushed DC Motor How to Code PWM DACs and PWM Amplification Back EMF Ramp Control PID Controller Motor Characterization PID Simulation
Pulse Width Modulation • • Speed Control Duty Cycle Advantages Disadvantages
Brushed DC Motor • • Field Magnets Stator DC Power Supply Armature or Rotor Axle Commutator Brushes
How to Code PWM • Example here will cover MSP 430 – Concepts can be easily extended
Reading the Datasheet • One pin has multiple functions – Set Px. SEL accordingly – P 2 DIR |= BIT 2; – P 2 SEL |= BIT 2; – Why |= operator? // set P 2. 2 as output // use pin as TA 1. 1
Setting Timer Values • Counter counts up each clock cycle • What do the different modes mean? – CCR 0 = 1000 -1; – Why minus 1?
Looking into ‘MSP 430 G 2231. h‘ • We are using Timer A • We must set TACTL – TACTL = TASSEL_2 + MC_1; // SMCLK, up to CCR 0 – Which clock do you want to use?
PWM Output Modes • We are using Timer A 1. 1 • CCTL 1 = OUTMOD_7; • ; // reset at CCR 1 // set at CCR 0 • OUTMOD_1 sets at CCRx • OUTMOD_2 toggles at CCRx, resets at CCR 0
Setting the Duty Cycle • We are using Timer A 1. 1 – Recall: – – TACTL = TASSEL_2 + MC_1; // SMCLK, up to CCR 0 = 1000 -1; CCTL 1 = OUTMOD_7; // reset at CCR 1 ; // set at CCR 0 – Now: – CCR 1 = 200 -1; // 20% duty cycle – What will this do?
DACs and PWM Amplification • DACs are used to convert a digital signal to analog – Why does a PWM signal become a steady DC value? • Microprocessors can’t provide enough current to drive a motor
Back Electromotive Force (EMF) • A motor converts electrical energy to mechanical energy • This conversion can go both ways • If a motor is spinning it will generate electrical energy – Called back emf
Example of Back EMF
Example of BEMF with a Load
Functional Block Diagram of PWM DC Motor Control
Ramp Control • Is an integrator • Adjusts the set point up to the desired value.
PID Control • e(t)= Setpoint - measured • Kp, Ki and Kd must be tuned according to desired output characteristics
DC Motor Model •
Motor Characterization • Voltage (Volts) Current (Amps) Resistance (Ohms) 0. 30 V 0. 23 A 1. 304 Ω 0. 50 V 0. 39 A 1. 282 Ω 0. 70 V 0. 56 A 1. 250 Ω 1. 00 V 0. 79 A 1. 266 Ω 1. 20 V 0. 88 A 1. 364 Ω Rwdg = 1. 2932 Ω
Motor Characterization Cont. • K = 0. 007348 V/rad
Open Loop Simulation J=0. 002; b=0. 00924; K=0. 007348; R=1. 2932; L=0. 05; step(K, [(J*L) ((J*R)+(L*b)) ((b*R)+K^2)]); Rise. Time: Settling. Time: Steady. State: Overshoot: 0. 4871 0. 8853 0. 6120 1. 1044
PID/Closed Loop Simulation J=0. 002; b=0. 00924; K=0. 007348; R=1. 2932; L=0. 05; Kp=20; Ki=30; Kd=29; num_PID=[Kd, Kp, Ki]; den_LOOP=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2 )]; num_B=conv(K, num_PID); den_B=conv(den_LOOP, [1 0]); [num_SYS, den_SYS]=cloop(num_B, den_B); step(num_SYS, den_SYS) Kp: 20 Ki: 30 Kd: 29 Rise. Time: Settling. Time: Steady. State: Overshoot: 0. 1788 0. 2168 1. 0000 0
- Slides: 22