* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Timers and PWM Motor Control Timers and PWM Motor Control
Brushless DC electric motor wikipedia , lookup
Power engineering wikipedia , lookup
Electric motor wikipedia , lookup
Three-phase electric power wikipedia , lookup
Stray voltage wikipedia , lookup
Electrical substation wikipedia , lookup
Resistive opto-isolator wikipedia , lookup
Time-to-digital converter wikipedia , lookup
Amtrak's 25 Hz traction power system wikipedia , lookup
Alternating current wikipedia , lookup
Power inverter wikipedia , lookup
Two-port network wikipedia , lookup
Induction motor wikipedia , lookup
Mains electricity wikipedia , lookup
Voltage optimisation wikipedia , lookup
Oscilloscope history wikipedia , lookup
Brushed DC electric motor wikipedia , lookup
Immunity-aware programming wikipedia , lookup
Stepper motor wikipedia , lookup
Switched-mode power supply wikipedia , lookup
Opto-isolator wikipedia , lookup
Buck converter wikipedia , lookup
Community College of Allegheny County Unit 4 Timers and PWM Motor Control Revised: Dan Wolf, 3/23/2017 Page #1 Community College of Allegheny County Unit 4 Page #2 OBJECTIVES: ο· Timers: Astable and Mono-Stable ο· 555 Timers ο· Pulse Width Modulation for Motor Control DELIVERABLES THAT YOU MUST SUBMIT 1. Graphs #1 and #2 2. Tables #1 and #2 On-Line Reading Material: Required: a) http://www.engin.swarthmore.edu/~ejaoudi1/datasheets/555 b) http://www.ocfreaks.com/pulse-width-modulation-pwmtutorial/ Optional: a) How to Build a 555 Timer Mono-stable Circuit: http://www.learningaboutelectronics.com/Articles/555-timermonostable-circuit.php b) How to Build a 555 Timer Bi-stable Circuit: c) http://www.learningaboutelectronics.com/Articles/555-timerbistable-circuit.php INTRODUCTION TO THE 555 TIMER: The IC 555 has three operating modes: a) Astable (free-running) mode: As per Figure #1, in this mode, the 555 operates as an electronic oscillator where the square wave output frequency is given by the equation: π= 1 0.693 β πΆ β (π 1 + 2π 2) Where R1 and R2 are in ohms and C is the value of the capacitor in farads. The High time from each pulse is given by: βππβ = 0.693 β πΆ β (π 1 + π 2) Community College of Allegheny County Unit 4 Page #3 And the Low time from each pulse is given by: πππ€ = 0.693 β πΆ β π 2 b) Monostable mode: As per Figure #2, in this mode, the 555 functions as a "one-shot" pulse generator. Once the input on Pin 2 is triggered, the output on Pin 2 will go high for a period of time determined by R and C according to the equation: π‘ = 1.1 β π πΆ Where R1 and R2 are in ohms and C is the value of the capacitor in farads. c) Bistable mode or Schmitt trigger: As per Figure #3, the 555 can operate as a flip-flop. Uses include bounce-free latched switches. INTRODUCTION TO PULSE-WIDTH MODULATION (PWM): Pulse-width modulation (PWM) uses digital pulses to generate an analog voltage. A digital output pin may be either high (+5 V) or low (0 V). But what if you switched the pin rapidly between high and low so that it was high half the time and low half the time? As per Figure #5, the average voltage over time would be halfway between 0 and 5 V (2.5 V). PWM emits a burst of ones and zeros whose ratio is proportional to the duty value you specify. The proportion of ones to zeros in PWM is called the duty cycle. The duty cycle controls the analog voltage in a very direct way; the higher the duty cycle the higher the voltage. Duty Cycle is the proportion of ones to zeros output by the PWM command. To determine the proportional PWM output voltage, use this formula: π·π’π‘π¦ πΆπ¦πππ = ππππ π»ππβ πππ ππ’ππ π ππ¦πππ ππππ πππ ππ’ππ π ππ¦πππ Community College of Allegheny County Unit 4 Page #4 πππππππ‘πππππ (π΄π£πππππ) ππ’π‘ππ’π‘ ππππ‘πππ = π·π’π‘π¦ πΆπ¦πππ β 5ππππ‘π For example, if the duty cycle is 50%, 0.50 x 5V = 2.5V; the PWM will output a train of pulses whose average voltage is 2.5V. Although we could slow down a motor by wiring it in series to a variable resister using a constant power supply, this approach wastes the power being dropped across the resister. PWM has the advantage in that no power is being wasted across such a resister. Community College of Allegheny County Unit 4 Page #5 Experiment #1 - Astable (free-running) Timer: 1. Figure #2 shows a typical 555 Astable circuit. EQUIPMENT REQUIRED: CCAC 555 Timer Lab box or the following: a. LED and 330β¦ load resister b. R1 = 2000β¦ (you may substitute a 10K pot) c. R2 = 2000β¦ (you may substitute a 10K pot) d. C = 1uF e. 10nF capacitor f. +5 Volt power supply 2. Connect the circuit shown in Figure #2 and add the LED and 330β¦ resister to the output on Pin 3. Calculate the expected frequency, period, time high and time low then update Table #1. Ask the instructor to check the circuit before you apply power! 3. Use the oscilloscope to monitor the output on Pin 3. Assuming that the oscilloscope confirms the expected frequency value, does the LED light? Explain? 4. Use Graph #1 to sketch this waveform and include the voltage level, period and frequency. Update Table #1 5. Calculate new values for R1, R2, and C which will allow you to see the LED blink (i.e. about once per second). Test with the new components and then update Table #1. Table #1 C F R1 R2 Calculated 2K 2K 1uF Measured 2K 2K 1uF Calculated Measured Calculated Measured Experiment #2 - Monostable Timer: Period Thigh Tlow Duty Cycle Community College of Allegheny County Unit 4 Page #6 1. Figure #3 shows a typical 555 Monostable circuit. EQUIPMENT REQUIRED: a. Misc. wire b. LED and 330β¦ load resister c. R = 10000β¦ (ok to substitute a 10K potentiometer) d. C = 100uF e. 10nF capacitor f. +5 Volt power supply 2. Connect the circuit shown in Figure #3. Add the LED and 330β¦ resister to the output on Pin 3 and a switch to the trigger input on Pin 2. Calculate the expected pulse time and update Table #2. Ask the instructor to check the circuit before you apply power! 3. Use the oscilloscope to monitor the output on Pin 3 and update Table #2. 4. Use Graph #1 to sketch this waveform showing the voltage level and pulse period and then pdate Table #2. 5. Calculate new values for R and C for a different time period. Test with the new components and then update Table #2. R Table #2 C Calculated 10K 100uF Measured 10K 100uF Calculated Measured Calculated Measured Pulse Period Community College of Allegheny County Unit 4 Page #7 Experiment #3 β 555 Pulse Width Modulation: 1. Figure #4 shows a 555 circuit that will generate cycle that will control the brightness of an LED speed of a small motor. Figure #5 shows the PWM that you would expect to see for different power You will need the following parts: a) 555 timer IC b) R1 = 10K variable resistor c) C1 = 10nF capacitor d) C2 = 1uF capacitor e) LED and 330β¦ load resister a PWM duty or the waveforms levels. 2. Connect the circuit shown in Figure #4 and add an LED and 330β¦ resister to the output on Pins 7 and 8. Ask the instructor to check the circuit before you apply power! 6. Test the circuit while changing the variable resister: use both an oscilloscope and a volt meter to monitor the PWM output to the LED. 7. Use Graph #2 to sketch at least two duty cycles (slow and fast) and include the peak voltage level, proportional PWM output voltage and duty cycle. 8. Figure #6 shows a modified 555 circuit which will drive a bigger motor. This is being shown for information only and you are not asked to build it. Table #3 Peak Voltage Slow Calculated Slow Measured Fast Calculated Fast Measured Calculated Duty Cycle Calculated PWM Voltage n/a n/a n/a Measured Experiment #4 β Arduino Pulse Width Modulation: Measured PWM Voltage (Volt Meter) Community College of Allegheny County Unit 4 Page #8 1. The 555 timer works fine but it requires the assembly of discrete components on a printed circuit board. Using todayβs technology, engineers would more likely use a microcontroller to perform PWM. In this experiment, you will see how easy it is to use the Arduino to generate a PWM motor signal. 2. Connect the circuit shown in Figure #7 and #8. Ask the instructor to check the circuit before you apply power! 3. Start the Arduino software: a) Start the Arduino interface by clicking on the file named: DCMotorTest_CCAC.ino b) Specify the correct Arduino serial port from the menu bar: Tools | Port | βCOMx (Arduino/Genuine Unoβ c) Start the serial monitor from the menu bar: Tools |Serial Monitor d) Upload the load cell software to the Arduino using the menu bar: Sketch |Upload e) Observe that the Serial Monitor window is displaying the startup message. 4. In Mode 1, the motor will ramp up and down in forward then again in reverse. You may change the mode by reassigning the value of intSelect_Mode which is located near the top of the software file (and then uploading). The other options are shown in the code. 5. Test the circuit while using an oscilloscope and volt meter to monitor the PWM output to the motor. 6. In this experiment, you have seen that PMW can be implemented rather quickly in software with a microcontroller which is also likely to be doing other tasks as well. If you are interested in software and want to explore in more detail, the Arduino supports the use of the AnalogWrite() function to do PWM and is explained here: https://www.arduino.cc/en/Reference/AnalogWrite and https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM Community College of Allegheny County Unit 4 Page #9 Figure 1 β The 555 Timer Figure 2 β 555 Astable (Free-running) Timer Community College of Allegheny County Unit 4 Page #10 Figure 3 β 555 Monostable Timer +5V 1K ohm Figure 4 β 555 Timer PWM LED Brightness +5V 555 LED Community College of Allegheny County Unit 4 Page #11 Figure 5 β PWM Waveforms Figure 6 β 555 Timer PWM Motor Control Community College of Allegheny County Unit 4 Page #12 Figure 7 β Arduino PWM Motor Control M1 Adafruit Motor Shield v2.3 M M1 Computer USB Arduino Uno External Power Supply Connect a DC motor to motor port 1 - it does not matter which wire goes into which terminal block as motors are bi-directional. Connect to the top two terminal ports, do not connect to the middle pin (GND) See the next photo for the red and blue wire example. Figure 8 β Arduino Motor Shield Connections M1 Motor wires Monitor here for excessive heat. Community College of Allegheny County Unit 4 Page #13 Figure #9 β Arduino PWM Software #include <Mouse.h> /* This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2 It won't work with v1.x motor shields! Only for the v2's with built in PWM control For use with the Adafruit Motor Shield v2 ----> http://www.adafruit.com/products/1438 Requires the Adafruit Motor Library to be installed: Adafruit_Motor_Shield_V2_Librarymaster BE CAREFUL OF THE MOTOR CURRENT!! 3.0A MAX BUT 2.0A REQUIRES A HEATSINK ON THE ARDUINO MAX MOTOR CURRENT SHOULD BE 1.2A PER MOTOR OR LESS!! SMALL MOTORS CAN PULL QUITE HIGH CURRENT LEVELS, ESPECIALLY AT STALL.*/ */ #include <Wire.h> #include <Adafruit_MotorShield.h> #include "utility/Adafruit_MS_PWMServoDriver.h" // Create the motor shield object with the default I2C address Adafruit_MotorShield AFMS = Adafruit_MotorShield(); // Or, create it with a different I2C address (say for stacking) // Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); // Select which 'port' M1, M2, M3 or M4. In this case, M1 Adafruit_DCMotor *myMotor = AFMS.getMotor(1); // You can also make another motor on port M2 //Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2); // Pick one of these to set the mode int iSelect_Mode = 1; // Varying forward and reverse // int iSelect_Mode = 2; // forward slow // int iSelect_Mode = 3; // forward fast // int iSelect_Mode = 4; // reverse slow // int iSelect_Mode = 5; // reverse fast void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("\nAdafruit Motorshield v2 - DC Motor Test - vJan_12_2017"); Serial.println("High motor current will burn out the Arduino, "); Serial.println("even for small motors or at stall conditions! \n"); AFMS.begin(); // create with the default frequency 1.6KHz //AFMS.begin(1000); // OR with a different frequency, say 1KHz // Set the speed to start, from 0 (off) to 255 (max speed) myMotor->setSpeed(150); myMotor->run(FORWARD); // turn on motor myMotor->run(RELEASE); } void loop() { uint8_t i; delay(2000); switch (iSelect_Mode) { case 1: Community College of Allegheny County { Serial.print("Forward "); delay(250); myMotor->run(FORWARD); for (i = 0; i < 255; i++) { myMotor->setSpeed(i); delay(10); } for (i = 255; i != 0; i--) { myMotor->setSpeed(i); delay(10); } Serial.print("Backward "); delay(250); myMotor->run(BACKWARD); for (i = 0; i < 255; i++) { myMotor->setSpeed(i); delay(10); } for (i = 255; i != 0; i--) { myMotor->setSpeed(i); delay(10); } Serial.print("Release "); delay(250); myMotor->run(RELEASE); delay(1000); } break; case 2: { Serial.print("Run Forward Slow \n"); delay(250); myMotor->run(FORWARD); myMotor->setSpeed(50); delay(10000); Serial.print("Release \n"); delay(250); myMotor->run(RELEASE); delay(5000); } break; case 3: { Serial.print("Run Forward Fast \n"); delay(250); myMotor->run(FORWARD); myMotor->setSpeed(100); delay(10000); Serial.print("Release \n"); delay(250); Unit 4 Page #14 Community College of Allegheny County Unit 4 Page #15 myMotor->run(RELEASE); delay(5000); } break; case 4: { Serial.print("Run Reverse Slow \n"); delay(250); myMotor->run(BACKWARD); myMotor->setSpeed(100); delay(10000); Serial.print("Release \n"); delay(250); myMotor->run(RELEASE); delay(5000); } break; case 5: { Serial.print("Run Reverse Fast \n"); delay(250); myMotor->run(BACKWARD); myMotor->setSpeed(100); delay(10000); Serial.print("Release \n"); delay(250); myMotor->run(RELEASE); delay(5000); } break; default: { Serial.print("Invalid Mode Selected - Defaulting to Mode 1 \n\n"); iSelect_Mode = 1; } break; } } Community College of Allegheny County Unit 4 Graph#1 β Astable and Monostable Waveforms Page #16 Community College of Allegheny County Graph#2 β PWM Waveforms Unit 4 Page #17 Community College of Allegheny County Unit 4 Page #18 PRACTICE PROBLEMS: 1. Design a 555 mono-stable circuit which provides a 750mS pulse when the input is triggered by a SPST switch. 2. Design a 555 Astable circuit which provides an output signal of 500Hz. 3. Design a 555 Astable circuit which will provide a PWM output voltage of 3.0volts. The entire circuit should be powered by +5volt. Specify the time high, time low, and duty cycle for the output. 4. Research the internet for equations to calculate the Thigh and Tlow for an Astable timer. Apply the equations to Table #1 and compare the results to the measured values. 5. Modify Figure #3 to use the trigger switch configuration shown below. Explain why it will not work. +5V 1K ohm