5 Experiment 5 Motor Speed Control

Similar documents
Pulse Width Modulation

CHAPTER 11: Flip Flops

Pulse Width Modulation (PWM) LED Dimmer Circuit. Using a 555 Timer Chip

AVR Timer/Counter. Prof Prabhat Ranjan DA-IICT, Gandhinagar

PWM IN AVR. Developed by: Krishna Nand Gupta Prashant Agrawal Mayur Agarwal

DC Motor with Shaft Encoder

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module

LAB 7 MOSFET CHARACTERISTICS AND APPLICATIONS

Constructing a precision SWR meter and antenna analyzer. Mike Brink HNF, Design Technologist.

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

PROJECT PRESENTATION ON CELLPHONE OPERATED ROBOTIC ASSISTANT

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

Accurate Measurement of the Mains Electricity Frequency

EET272 Worksheet Week 9

Pulse Width Modulation Applications

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

Timer A (0 and 1) and PWM EE3376

Lab 3 - DC Circuits and Ohm s Law

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

1/22/16. You Tube Video. Definitions. Duty Cycle: on-time per period (specified in per cent)

[F/T] [5] [KHz] [AMP] [3] [V] 4 ) To set DC offset to -2.5V press the following keys [OFS] [+/-] [2] [.] [5] [V]

AVR127: Understanding ADC Parameters. Introduction. Features. Atmel 8-bit and 32-bit Microcontrollers APPLICATION NOTE

Experiment 8 : Pulse Width Modulation

Servo Info and Centering

AMZ-FX Guitar effects. (2007) Mosfet Body Diodes. Accessed 22/12/09.

Selecting and Implementing H-Bridges in DC Motor Control. Daniel Phan A

Tamura Closed Loop Hall Effect Current Sensors

AVR Butterfly Training. Atmel Norway, AVR Applications Group

DC Motor control Reversing

WHY DIFFERENTIAL? instruments connected to the circuit under test and results in V COMMON.

Table of Contents Getting Started... 3 The Motors... 4 The Control Board... 5 Setting up the Computer with Mach Starting up the Equipment...

If an occupancy of room is zero, i.e. room is empty then light source will be switched off automatically

Simple Analysis for Brushless DC Motors Case Study: Razor Scooter Wheel Motor

Light Bulbs in Parallel Circuits

DIRECT CURRENT GENERATORS

PCM Encoding and Decoding:

Measuring Insulation Resistance of Capacitors

- 35mA Standby, mA Speaking pre-defined phrases with up to 1925 total characters.

A Digital Timer Implementation using 7 Segment Displays

Pulse Width Modulated (PWM) Drives. AC Drives Using PWM Techniques

PID Control. Proportional Integral Derivative (PID) Control. Matrix Multimedia 2011 MX009 - PID Control. by Ben Rowland, April 2011

GAUGEMASTER PRODIGY EXPRESS

Electronics 5: Arduino, PWM, Mosfetts and Motors

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

Tutorial. replace them with cell-phone operated module. The advantages of a cell-phone operated bot are:-

VOICE RECOGNITION KIT USING HM2007. Speech Recognition System. Features. Specification. Applications

Measuring Resistance Using Digital I/O

3-Digit Counter and Display

A 5 Degree Feedback Control Robotic Arm (Haptic Arm)

Rotating Machinery Diagnostics & Instrumentation Solutions for Maintenance That Matters

NUCLEAR MAGNETIC RESONANCE. Advanced Laboratory, Physics 407, University of Wisconsin Madison, Wisconsin 53706

DIGITAL-TO-ANALOGUE AND ANALOGUE-TO-DIGITAL CONVERSION

The $25 Son of a cheap timer This is not suitable for a beginner. You must have soldering skills in order to build this kit.

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Drive circuit basics + V. τ e. Industrial Circuits Application Note. Winding resistance and inductance

Pulse Width Modulated (PWM)

Talon and Talon SR User Manual

Resistance, Ohm s Law, and the Temperature of a Light Bulb Filament

Micro-Step Driving for Stepper Motors: A Case Study

Table 1 Comparison of DC, Uni-Polar and Bi-polar Stepper Motors

Microtronics technologies Mobile:

Equipment: Power Supply, DAI, Wound rotor induction motor (8231), Electrodynamometer (8960), timing belt.

Current Loop Tuning Procedure. Servo Drive Current Loop Tuning Procedure (intended for Analog input PWM output servo drives) General Procedure AN-015

INTRODUCTION TO SERIAL ARM

Work with Arduino Hardware

ECEN 1400, Introduction to Analog and Digital Electronics

Digital to Analog and Analog to Digital Conversion

Chapter 19 Operational Amplifiers

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

Wiki Lab Book. This week is practice for wiki usage during the project.

Advanced LED Controller (LED Chaser)

Speed Control Methods of Various Types of Speed Control Motors. Kazuya SHIRAHATA

Transistor Characteristics and Single Transistor Amplifier Sept. 8, 1997

Solutions to Bulb questions

OPTICAL COMMUNICATION BASED STEPPER MOTOR CONTROL USING PULSE WIDTH MODULATION

Interfacing To Alphanumeric Displays

VEHICLE SPEED CONTROL SYSTEM

Reading: HH Sections , (pgs , )

APPLICATION NOTES: Dimming InGaN LED

Equipment: Power Supply, DAI, Synchronous motor (8241), Electrodynamometer (8960), Tachometer, Timing belt.

Signal Processing in So.ware and Electric Field Sensing

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

Tutorials Drawing a 555 timer circuit

APEX Robot Rabbit. Tel:

Lab E1: Introduction to Circuits

Series and Parallel Circuits

Digital vs. Analogue Control Systems

Energy, Work, and Power

Bipolar Transistor Amplifiers

Fundamentals of Signature Analysis

RGB for ZX Spectrum 128, +2, +2A, +3

Controlling a Dot Matrix LED Display with a Microcontroller

Adding Heart to Your Technology

OPERATIONAL AMPLIFIERS

Hand Crank Generator (9 May 05) Converting a Portable Cordless Drill to a Hand Crank DC Generator

How to Read a Datasheet

Microcontroller to Sensor Interfacing Techniques

Transcription:

5 Experiment 5 Motor Speed Control 5.1 Aim This experiment aims to: Learn how to use emitter-detector to measure the speed of the motor. Learn how to do speed control for a DC motor by using Pulse Width Modulation (PWM). 5.2 Preparation It is important that you prepare for each laboratory experiment, so that you can use your time (and your partner s time) most effectively. For this particular, experiment, you should do the following before coming in to the Laboratory: Read through this experiment in detail, trying to understand what you will be doing. Skim-read the section on Programming Style in Experiment 1 and 2. It is highly recommeded that you: Type up or modify the necessary files in this experiment, to save time in class, and Run through the experiment at home using AVR Studio and AVR Microcontroller Board. 5.3 Save Your Work The computer in the lab are also used by other students in this course. So when you finish your lab, please save all your work to your floppy disk and DELETE all files associated with your lab if you do not want other students to use your files. 5.4 Part 1: Speed Detection Shaft encoders use infra red emitters and detectors that are placed fairly close to each other (about half an inch or less). When there is a direct line of sight between them the detector is on and produces a voltage (normally around 1 to 3 volts). When the line of sight is blocked the detector doesn t pick up any infra red light so is off, producing 0 volts. For a perfect example of how shaft encoders work take a look inside your mouse. You will see a disk with holes around the edges. On either side of the disk are an infra red emitter and infra red detector. When you move the mouse, the mouse ball s rotation causes the perforated disk to rotate. As the disk rotates the path between the IR emitter and detector is made and broken, causing the detector to create a string of electrical pulses. By monitoring the frequency of the pulses you can deduce how far the wheel has turned and the time it took. Carefully exam the motor and shaft encoder on the AVR Microcontroller Board. Can you identify the emitter and the detector? The emitter isactive high and the detector is active low (It will go low when it can see the signal). Now power up the AVR Microcontroller Board as from last lab, wire up the POT to the MOT using the patch cables provided. As you turn the POT, the motor spins at different speeds. 75

As you have already noticed, there are 4 holes on the motor, the combination of the motor and shaft encoder enables you to measure the frequency of the motor by counting the number of the holes the shaft encoder detects and divide by 4. Hints for Motor Speed Testing There are two ways to measure speed, counting holes in a given period of time or measuring time for a complete revolution of the wheel (or several revolutions to average things out). Whichever method you choose is up to you. The Detector can be read by an interrupt. The detector usually will output a 1 when there isn t a hole, so you can use the falling edge of the detector to trigger an interrupt to count a hole. 1. Method 1: Timing can be done with Timer 0 or any of the other timers in the chip. Count Overflow interrupts to measure a period of one second while counting the number of holes that pass by using an external interrupt. Every second you can update your speed on the LCD. 2. Method 2: Set up the timer to time over an appropriate period. Wait for the first external interrupt to indicate the first hole and record the timer value. After four more external interrupts you know that 1 revolution has occurred. Find the difference between the start and end times (you may also need to count the number of timer overflows) and you can calculate the period of rotation for the wheel. From this value you can work out how many revolutions could occur in a second and display it. The first method is fairly simple but will only update every second. The second method is a little more tricky, but gives you much higher accuracy and a MUCH faster refresh rate (in fact you will probably have to limit this rate if you want to read the number off the LCD in time). Write an AVR assembly language program that measures the speed of the motor by counting the number of holes that has been detected using the shaft encoder, and display the speed of the motor on the LCD. You might need to go back to the previous experiment for how to initialize, and write to LCD properly. Assemble your program using AVR Studio, download the program to the AVR Microcontroller Board and show your working program to the Laboratory assessor. Remember to save and delete your work before you leave the laboratory. Checkpoint 1: Signature: 5.5 Part 2: Pulse Width Modulation Analog circuits An analog signal has a continuously varying value, with infinite resolution in both time and magnitude. A nine-volt battery is an example of an analog device, in that its output voltage is not 76

precisely 9V, changes over time, and can take any real-numbered value. Similarly, the amount of current drawn from a battery is not limited to a finite set of possible values. Analog signals are distinguishable from digital signals because the latter always take values only from a finite set of predetermined possibilities, such as the set 0V, 5V. Analog voltages and currents can be used to control things directly, like the motor. In a simple DC motor, a POT is connected to a variable resistor. As you turn the POT, the resistance goes up or down. As that happens, the current flowing through the resistor increases or decreases. This changes the amount of current driving the motor, thus increasing or decreasing the speed. An analog circuit is one, like the motor, whose output is linearly proportional to its input. As intuitive and simple as analog control may seem, it is not always economically attractive or otherwise practical. For one thing, analog circuits tend to drift over time and can, therefore, be very difficult to tune. Precision analog circuits, which solve that problem, can be very large, heavy (just think of older home stereo equipment), and expensive. Analog circuits can also get very hot; the power dissipated is proportional to the voltage across the active elements multiplied by the current through them. Analog circuitry can also be sensitive to noise. Because of its infinite resolution, any perturbation or noise on an analog signal necessarily changes the current value. Digital control By controlling analog circuits digitally, system costs and power consumption can be drastically reduced. What s more, many microcontrollers and already include on-chip PWM controllers, making implementation easy. PWM is a way of digitally encoding analog signal levels. Through the use of high-resolution counters, the duty cycle of a square wave is modulated to encode a specific analog signal level. The PWM signal is still digital because, at any given instant of time, the full DC supply is either fully on or fully off. The voltage or current source is supplied to the analog load by means of a repeating series of on and off pulses. The on-time is the time during which the DC power is supplied and the off-time is the period during which that the power is not supplied. Given a sufficient bandwidth, any analog value can be encoded with PWM. Figure 1 shows three different PWM signals. Figure 1a shows a PWM output at a 10% duty cycle. That is, the signal is on for 10% of the period and off the other 90%. Figures 1b and 1c show PWM outputs at 50% and 90% duty cycles, respectively. These three PWM outputs encode three different analog signal values, at 10%, 50%, and 90% of the full strength. If, for example, the supply is 5V and the duty cycle is 10%, a 0.5V analog signal results. 77

Figure 1: Pulse Width Modulation PWM is a common technique for speed control. A good analogy is bicycle riding. You peddle (exert energy) and then coast (relax) using your momentum to carry you forward. As you slow down (due to wind resistance, friction, road shape) you peddle to speed up and then coast again. The duty cycle is the ratio of peddling time to the total time (peddle+coast time). A 100% duty cycle means you are peddling all the time, and 50% only half the time. PWM for motor speed control works in a very similar way. Instead of peddling, your motor is given a fixed voltage value (say +5 V) and starts spinning. The voltage is then removed and the motor coasts. By continuing this voltage on-off duty cycle, motor speed is controlled. To control the speed of a DC motor, we need a variable voltage DC power source. However, if you take a 5V motor and switch on the power, the motor will start to speed up, motors do not respond immediately so it will take a small time to reach full speed. If we switch the power off, sometimes before the motor reaches full speed, then the motor will start to slow down. If we switch the power on the off quickly enough, the motor will run at some speed part way between zero and full speed. This is exactly what a PWM controller does; it switches the motor on in series of pulses. To control the motor speed it varies the width of the pulses hence Pulse Width Modulation. PWM can be controlled on the Atmega64 through the use of Timer 0 and its Phase Correct PWM mode. This is explained in the datasheet in the Timer 0 chapter (pp99-100). You should read this section before continuing. Basically, you control the timer to vary the duty cycle of the signal on the output pin which varies the average voltage on the pin which controls the motor speed. PWM allows 256 different duty cycles to be output to the device. Not all of these are high enough to overcome the friction of the motor shaft, but most will allow you to control the motor speed with fairly good accuracy. Timer 0 allows control of the PWM on pin B4 of the microcontroller. Therefore you should be connecting PORT B4 to the motor to control it this way. Once the timer is set up to perform PWM, you can control the duty cycle and therefore control the speed of the motor by using the OCR0 port. This can be set up so that increasing the value of this port will increase the duty cycle of the output pin. The ports used to control the PWM are described below. All references to tables and figures 78

are those in the Atmega64 datasheet. Timer Counter Control Register (TCCR0): This port controls the timer. The bit values you need to control are described. Bit 7 - FOC0: This bit is not used for PWM it should be 0. Bits 6,3 - WGM01:0: These bits determine what mode the timer is in. Table 52 shows that WGM01(bit 6) should be 0 and WGM00(bit 3) should be 1 to enable PWM mode. Bit 5:4 - COM01:0: These bits further control the output type of the PWM signal. Table 54 shows the values for this pin. To enable the type of PWM we want, set COM01 to 1 and COM00 to 0. Bit 2:0 - CS02:0: These pins select the clock speed used. It doesn t really matter what speed you set the clock to for PWM, so you can just use the value 001 for these three bits Timer/Counter Register (TCNT0): This port contains the current value of the timer. You can read this value if you want to find the current time but it s not required. Output Compare Register (OCR0): The value on this port determines the duty cycle. The larger the value, the higher the duty cycle and the faster the motor will go. Timer/Counter Interrupt Mask Register (TIMSK): This allows you to create an interrupt if you wish, but you probably won t need these. The interrupt types are: Timer Overflow (TOIE0): Interrupts every time the timer overflows (i.e. at the frequency of the clock. Output Compare(OCIE0): This interrupt occurs whenever the output is going to change. You can get a better understanding of these interrupts from Figure 40. Write an assembly program for DC motor speed control. You program should work as follows: 1. When it is started, the motor spins at the speed of 20 rps (rounds per second) clockwise. 2. Every time when the key 1 on the keypad is pressed, the motor speed is increased by 10 rps. The maximum speed is 100 rps. 3. Every time when the key 2 on the keypad is pressed, the motor speed is decreased by 10 rps. The minimum speed is 20 rps. 4. When the key 3 is pressed, the motor stops. 5. When the key 4 is pressed, the motor starts spinning at the speed of 20 rps. Assemble your program using AVR Studio, download the program to the AVR Microcontroller Board and show your working program to the Laboratory assessor. Remember to save and delete your work before you leave the laboratory. 79

Checkpoint 2: Signature: 80