filtering data – smoothing out the rough...

24
Community College of Allegheny County Unit 4 Page #1 Timers and PWM Motor Control Timers and Timers and PWM Motor PWM Motor Control Control

Upload: dodiep

Post on 18-May-2018

219 views

Category:

Documents


2 download

TRANSCRIPT

Community College of Allegheny County Unit 4 Page #1

Timers and PWM Motor Control

Revised: Dan Wolf, 3/1/2018

Timers and PWMTimers and PWM Motor ControlMotor Control

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, Tables #1 and #22. Practice Problems

On-Line Reading Material:Required:

a) http://www.engin.swarthmore.edu/~ejaoudi1/datasheets/555 b) http://www.ocfreaks.com/pulse-width-modulation-pwm-tutorial/

Optional:a) How to Build a 555 Timer Mono-stable Circuit:

http://www.learningaboutelectronics.com/Articles/555-timer-monostable-circuit.php

b) How to Build a 555 Timer Bi-stable Circuit:c) http://www.learningaboutelectronics.com/Articles/555-timer-

bistable-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:

f= 10.693∗C∗(R1+2R2)

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:

high=0.693∗C∗(R1+R2)

And the Low time from each pulse is given by:

low=0.693∗C∗R2

Community College of Allegheny County Unit 4 Page #3

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:

t=1.1∗RC

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:

DutyCycle=Time High per pulse cycleTime per pulse cycle

Proportional (Average )Output Voltage=Duty Cycle∗5Volts

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

Community College of Allegheny County Unit 4 Page #4

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 resisterb. R1 = 2000Ω (you may substitute a 10K pot)c. R2 = 2000Ω (you may substitute a 10K pot)d. C = 1uFe. 10nF capacitorf. +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

R1 R2 C F Period Thigh Tlow Duty Cycle

Calculated 2K 2K 1uF

Measured 2K 2K 1uF

Calculated

Measured

Calculated

Measured

Experiment #2 - Monostable Timer:

Community College of Allegheny County Unit 4 Page #6

1. Figure #3 shows a typical 555 Monostable circuit.EQUIPMENT REQUIRED:

a. Misc. wireb. LED and 330Ω load resisterc. R = 10000Ω (ok to substitute a 10K potentiometer)d. C = 100uFe. 10nF capacitorf. +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.

Table #2R C Pulse Period

Calculated 10K 100uF

Measured 10K 100uF

Calculated

Measured

Calculated

Measured

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 a PWM duty cycle that will control the brightness of an LED or the speed of a small motor. Figure #5 shows the PWM waveforms that you would expect to see for different power levels. You will need the following parts:

a) 555 timer ICb) R1 = 10K variable resistorc) C1 = 10nF capacitord) C2 = 1uF capacitore) LED and 330Ω load resister

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

Duty Cycle

Calculated PWM Voltage

Measured PWM Voltage

(Volt Meter)

Slow Calculated n/a

Slow Measured

Fast Calculated n/a

Fast Measured

Calculated n/a

Measured

Experiment #4 – Arduino Pulse Width Modulation:

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. You will need the following parts:

a. Arduino Uno microcontroller, power supply, cable, and USB Hub.

b. AdaFruit Motor Shield v2.3c. Small 12Volt Dc motor

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.inob) 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

Monitord) Upload the load cell software to the Arduino using the

menu bar: Sketch |Uploade) 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 andhttps://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM

Figure 1 – The 555 Timer

Community College of Allegheny County Unit 4 Page #9

Figure 2 – 555 Astable (Free-running) Timer

Community College of Allegheny County Unit 4 Page #10

Figure 3 – 555 Monostable Timer

Figure 4 – 555 Timer PWM LED Brightness

+5V

LED

555

C1

C2

10K

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

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 – DCMotorTest_CCAC.ino - Arduino PWM Software

#include <Mouse.h>

/*This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2It 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_Library-masterBE CAREFUL OF THE MOTOR CURRENT!! 3.0A MAX BUT 2.0A REQUIRES A HEATSINK ON THE ARDUINOMAX 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 addressAdafruit_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, M1Adafruit_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 modeint 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)

Community College of Allegheny County Unit 4 Page #14

case 1: 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");

Community College of Allegheny County Unit 4 Page #15

delay(250); 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 Page #16

Graph#1 – Astable and Monostable Waveforms

Community College of Allegheny County Unit 4 Page #17

Graph#2 – PWM Waveforms

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.