Interfacing a DC Motor



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

Servo Info and Centering

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

Construction and Application of a Computer Based Interface Card

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

STEPPER MOTOR SPEED AND POSITION CONTROL

DC Motor Driver 24V 20A [RKI-1340]

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

Arduino Motor Shield (L298) Manual

Pulse Width Modulation

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence :

Interfacing Analog to Digital Data Converters

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

CHAPTER 11: Flip Flops

HT46R14A Single Phase AC Induction Motor Frequency Converter Application

An Introduction to MPLAB Integrated Development Environment

Special Lecture. Basic Stamp 2 Programming. (Presented on popular demand)

GT Sensors Precision Gear Tooth and Encoder Sensors

Arduino Lesson 13. DC Motors. Created by Simon Monk

Basic Pulse Width Modulation

EasyC. Programming Tips

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

Ocean Controls RC Servo Motor Controller

Programming Real-Time Motion Control Robot Prototype

SYSTEM 4C. C R H Electronics Design

Car Racing Game. Figure 1 The Car Racing Game

PROJECT PRESENTATION ON CELLPHONE OPERATED ROBOTIC ASSISTANT

BrightSign Expander Hardware Guide

Accurate Measurement of the Mains Electricity Frequency

Micro-Step Driving for Stepper Motors: A Case Study

Six-servo Robot Arm. DAGU Hi-Tech Electronic Co., LTD Six-servo Robot Arm

Analog Servo Drive 25A8

A+ Guide to Managing and Maintaining Your PC, 7e. Chapter 1 Introducing Hardware

DMX-K-DRV. Integrated Step Motor Driver + (Basic Controller) Manual

SYSTEM 45. C R H Electronics Design

Talon and Talon SR User Manual

Ordering Part Numbers: Universal Signal Converter: USC-CVB Universal Signal Converter with a 4-20mA input and +/- 10V output: USC-CVB225-B10V

Pulse Width Modulation Applications

Optical Sensor Interface for AFX Digital LED Timer/Counter by George Warner, Jan

Brushless DC Motor Controller Product Specification Assembly 025F0129

Whale 3. User Manual and Installation Guide. DC Servo drive. Contents. 1. Safety, policy and warranty Safety notes Policy Warranty.

Analog to Digital Conversion of Sound with the MSP430F2013

Using the Motor Controller

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

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

ServoPAL (#28824): Servo Pulser and Timer

Pololu DRV8835 Dual Motor Driver Shield for Arduino

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

A Digital Timer Implementation using 7 Segment Displays

PLL frequency synthesizer

Transformerless UPS systems and the 9900 By: John Steele, EIT Engineering Manager

Contents Installing the ucal Software on your PC/Laptop ucal Programmer Version Connecting the ucal Programmer to your PC/Laptop

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

Lab Experiment 1: The LPC 2148 Education Board

cs281: Introduction to Computer Systems Lab08 Interrupt Handling and Stepper Motor Controller

UIM2901-5A MACH3 breakout board

DUAL FULL-BRIDGE PWM MOTOR DRIVER

TRILOGI 5.3 PLC Ladder Diagram Programmer and Simulator. A tutorial prepared for IE 575 by Dr. T.C. Chang. Use On-Line Help

Electronic Brick of Current Sensor

AN2680 Application note

Datasheet of the Easy Servo Drive ES-D VDC, 8.2A Peak, Close-loop, No Tuning. Version

M68EVB908QL4 Development Board for Motorola MC68HC908QL4

ezsystem elab16m Project 1F: Alarm System (Full Project description)

IQAN MDM Operation Manual

8 coil stator 11 coil stator

Cornerstone Electronics Technology and Robotics I Week 15 Voltage Comparators Tutorial

How to design and implement firmware for embedded systems

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

Work with Arduino Hardware

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

What Is Regeneration?

ECEN 1400, Introduction to Analog and Digital Electronics

Pmod peripheral modules are powered by the host via the interface s power and ground pins.

Four/Five Axis TB6560 CNC Driver Users Manual

Stop Alert Flasher with G-Force sensor

OPERATIONAL AMPLIFIER

Discontinued Product For Reference Only

ARRL Morse Code Oscillator, How It Works By: Mark Spencer, WA8SME

Adafruit's Raspberry Pi Lesson 9. Controlling a DC Motor

GLOLAB Two Wire Stepper Motor Positioner

Three Axis TB6560 CNC Driver Users Manual

User and installation manual

LEN s.r.l. Via S. Andrea di Rovereto 33 c.s CHIAVARI (GE) Tel Fax mailto: len@len.it url: http//

Digital to Analog Converter. Raghu Tumati

Crazy Alarm Clock L A K S H M I M E Y Y A P P A N J A M E S K A Y E W I L L I A M D I E H L C O N G C H E N

Pulse Width Modulated (PWM)

Hands On ECG. Sean Hubber and Crystal Lu

ABB Drives. User s Manual HTL Encoder Interface FEN-31

Wireless Security Camera

Basic DC Motor Circuits. Living with the Lab Gerald Recktenwald Portland State University

The Design of DSP controller based DC Servo Motor Control System

Basic DC Motor Circuits

MDC Series

Debouncing Switches. Mechanical switches are one of the most common interfaces to a uc.

PRODUCTIVITY THROUGH INNOVATION 600 CONTROL DIRECT DRIVE TECHNICAL/OPERATION MANUAL

ECE 495 Project 3: Shocker Actuator Subsystem and Website Design. Group 1: One Awesome Engineering

Arduino Lesson 14. Servo Motors

XS-3525/8S-3. Preliminary DataSheet Version 2.02

Transcription:

Interfacing a DC Motor This chapter will describe how you can interface a DC motor to your Boondog 8255 PC Interface Card. The QBasic and Turbo C code will demonstrate how you can implement pulse-width-modulation (PWM) in software and control the motor's speed. Introduction and Motivation: Many PC hobbyists are interested in interfacing a DC motor to their PCs to build a robot or do mechanical work by computer control.. Such motor control typically means having the PC turn the motor on, off, adjusting speed and reversing direction. There are many dedicated chips designed for this purpose. Allegro makes one called the UDN2993B which has a dual H- bridge driver that can handle continuous loads up to 30 V and 0.5 A. This chip requires no additional Figure 1: The circular black disk is attached to the hardware and can be quickly DC motor's spindle. The motor is mounted in a plasticinterfaced to your 8255 PC Interface frame on a wooden base. The DC motor controller Card. uses a single integrated chip (bottom left). The UDN2993B is interfaced to the motor (see Figure 1). It only requires an ENABLE and PHASE signals. ENABLE must be a pulse-width-modulated (PWM) signal. PWM is a very common, highly efficient method for controlling motor speed. To understand PWM think how you ride your bicycle. There are times when you pedal (on-time), and times when you coast (off-time). When coasting you are using your momentum and are not physically exerting energy. When you feel (modulation) you are going too slow you pedal (pulse) again for some time(width) and then coast again. This pedal-coast-pedal cycle is called PWM. The amount of time you pedal is called the on-time. The amount of time you coast is called the off-time. The total time is the sum of on-time and off-time. PWM signals are described by a duty cycle (D.C.) percentage. The duty cycle is the ratio of the on-time and total time. For example, a 100% D.C. means that the motor is receiving energy (you are pedaling) all the time. A 50% D.C. means that the motor receives energy (pedaling) only half the time (coasting half the time). 8255 PC Interface Card Applications Manual 39

Typically motor speed controllers are designed in hardware with timer circuitry 12. However, you can program a PWM signal in software. This is much more economical and efficient. You do not need any external circuitry, and can quickly reprogram a new duty cycle. The Program Listings will show how to do this later. Parts List, Numbers and Sources: Part Description Supplier and Number QTY Cost($) UDN2993B (1-pin DIP) Allegro (see Appendix) 1 3.00 DC Motor e.g. Radio Shack 273-223 1 0.99 Table 7: Parts List for DC Motor Interface Schematic Wiring Diagram: Motor Voltage Supply Vcc = +5 V ENABLE A (A.0) 1 2 PHASE A (A.1) 3 4 5 7 8 PORT A 0 1 2 3 4 5 7 1 2 3 4 5 7 8 U1 1 2 3 4 5 7 8 LOAD SUPPLY ENABLE A PHASE A GND GND OUT 1A OUT 2A VEA LOGIC SUPPLY ENABLE B PHASE B GND GND OUT 1B OUT 2B VEB 1 15 14 13 12 11 10 9 UDN2993B DC MOTOR Figure 17: Schematic wiring diagram for interfacing a DC motor to the 8255 PC Interface Card. The numbers 0-7 in the box labeled Port A refer to lines A0-A7 on the Terminal Expansion Board 12 For example, the 555 timer chip. 40 8255 PC Interface Card Applications Manual

Construction The schematic shows that the UDN2993B requires only two digital lines to control a single motor. You can add another motor using pins 9-15 and another two digital lines. The toy motor in Figure 1 requires a voltage supply of +5 V. This supply voltage is connected to pin 1. No external heat sinks are required. The UDN2993B can handle much stronger motors with supply voltages up to 30 V and 0.5 A. If you require even higher voltages and currents, Allegro makes the UDN2998 which can handle 50 V and 3 A. QBasic Program Listing for DC Motor Interface: ' FILE: PWM.C ' DESC: Control speed and direction of a DC motor using PWM CLS:LOCATE 2, 1: PRINT "ENTER BASE ADDRESS IN DECIMAL (E.G. 08) =>" LOCATE 2, 45: INPUT BASEADDR PORTA = BASEADDR PORTB = BASEADDR + 1 PORTC = BASEADDR + 2 CNTRL = BASEADDR + 3 OUT CNTRL, 128: ' Configure all ports for output OUT PORTA, 0: ' motor should be off LOCATE 3, 1: PRINT "Speed Options" LOCATE 4, 1: PRINT "(f)aster" LOCATE 5, 1: PRINT "(s)lower" LOCATE, 1: PRINT "(r)everse direction" LOCATE 7, 1: PRINT "(q)uit" LOCATE 9, 1: PRINT "Selection => " LOCATE 9, 14 DutyCycle = 0: ' start off at zero velocity Phase = 0 DO DO GOSUB pwm SpeedOption$ = INKEY$ LOOP UNTIL SpeedOption$ <> "" SELECT CASE SpeedOption$ CASE "f" ' increase speed by 5% DC DutyCycle = DutyCycle + 5 IF DutyCycle > 100 THEN DutyCycle = 100 LOCATE 20, 1: PRINT "Can't go faster" FOR d = 1 TO 1000: NEXT d LOCATE 20, 1: PRINT (" "); END IF LOCATE 13, 1: PRINT "Going faster..." 8255 PC Interface Card Applications Manual 41

GOSUB pwm CASE "s" ' decrease speed by 5% DC DutyCycle = DutyCycle - 5 IF DutyCycle < 0 THEN DutyCycle = 0 LOCATE 20, 1: PRINT "Can't go slower" FOR d = 1 TO 1000: NEXT d LOCATE 20, 1: PRINT " " END IF LOCATE 13, 1: PRINT "Going slower..." GOSUB pwm CASE "r" ' reverse direction at present DC IF Phase = 0 THEN Phase = 2 ELSEIF Phase = 2 THEN Phase = 0 END IF GOSUB pwm LOCATE 13, 1: PRINT "Reversing..." CASE "q" LOCATE 22, 1: PRINT "Quitting" OUT PORTA, 0 OUT PORTB, 0 OUT PORTC, 0 END END SELECT LOCATE 9, 14 LOOP WHILE (1): ' end of do pwm: TotalTime =.1: '100 msec = 0.1 sec OnTime = TotalTime * DutyCycle / 100 OffTime = TotalTime - OnTime OUT PORTA, Enable + Phase GOSUB DELAYOnTime Enable = 0 OUT PORTA, Enable + Phase GOSUB DELAYOffTime LOCATE 10, 1: PRINT "Duty Cycle is "; : PRINT DutyCycle RETURN DELAYOnTime: TIMERA = TIMER DO LOOP WHILE (TIMER - TIMERA) < OnTime RETURN DELAYOffTime: TIMERA = TIMER DO LOOP WHILE (TIMER - TIMERA) < OffTime RETURN 42 8255 PC Interface Card Applications Manual

Program Description: The program begins by asking the user to input the base address of the card. Then Ports A, B, C and the control word addresses are assigned. The three ports are configured with outputs roles. DutyCycle sets the initial duty cycle to be 0, so that the motor is initially at rest. Phase is set to 0 and Enable is set to 1, so that the motor is ready to run. A nested DO...LOOP awaits for the user to hit a key on the PC keyboard and loops though the pwm subroutine. The key menu describes how to control the speed of the motor. Once a key press has been detected (using the INKEY$ ) the program enters the SELECT...CASE code. If an f key (faster) is hit the duty cycle is increased by 5%. If an s key (slower) is hit the duty cycle is decreased by 5%. Since the maximum duty cycle is 100%, an IF...THEN is used as a threshold A similar threshold is used for the minimum duty cycle of 0%. If an r key (reverse) is hit the PHASE bit is complimented from its present state. The motor will reverse direction at the present duty cycle. The major subroutine is pwm and calculates the OnTime and OffTime values. A divide by 100 is used because duty cycle is in percentages. The TotalTime value of the pulse is set for 0.1 seconds. Port A's A0 (ENABLE) line uses these values to enable the motor for OnTime seconds using the DelayOnTime function. This function uses the QBasic TIMER statement which accesses the PC's real-time internal clock. pwm then disables the motor for OffTime seconds using the DelayOffTime function. If the q key (quit) is hit the motor stops and the program exits. This circuit and program is an example of open-loop control, and does not use any feedback. In our bicycle analogy, if the bicycle has no speedometer, there is no way of knowing your exact speed. Furthermore, the speed depends on a person's pedal rate (on time and off time) and torque. The rate and torque depend on which gear you are in (i.e. the motor's load voltage supply and hence supplied current), the road's slope (load on the motor) and how properly the tires are inflated and how lubricated the gears are (e.g. friction of the motor bearings). It is only by trial and error that you can match your pedal speed and torque with bicycle speed. This trial and error process is called tuning. Similarly, every DC motor needs to be tuned. In the above program listing, a TotalTime of 0.1 seconds was used. For your motor, you may have to tune your motor by changing the TotalTime to reflect your motor's properties. The Turbo C listing follows, and its operation mimics that of the QBasic listing. Turbo C Program Listing for DC Motor Interfacing: /* 8255 PC Interface Card Applications Manual 43

*/ FILE: PWM.C DESC: Control speed and direction of a DC motor using PWM #include<stdio.h> #include<stdlib.h> #include<dos.h> /* outportb, inportb defined here */ #include<conio.h> /* formatted text functions defined here */ void pwm(int, int, int, int); void main(void) { int BASEADDR; int PORTA, PORTB, PORTC; int CNTRL; int DutyCycle; int SpeedOption; int Enable, Phase; /* Enable on A.0, Phase on A.1 */ clrscr(); /* clear screen */ window(5,5,75,30); /* set up text window */ gotoxy(1,1); cprintf("enter Base Address (decimal) e.g. 08 =>\n"); gotoxy(42,1); scanf("%d", &BASEADDR); PORTA = BASEADDR; PORTB = BASEADDR + 1; PORTC = BASEADDR + 2; CNTRL = BASEADDR+3; outportb(cntrl, 128); /* configure all ports for output */ outportb(porta, 0); /* motor should be off */ gotoxy(1,3); cprintf("speed Options"); gotoxy(1,4); cprintf("(f)aster"); gotoxy(1,5); cprintf("(s)lower"); gotoxy(1,); cprintf("(r)everse direction"); gotoxy(1,7); cprintf("(q)uit"); gotoxy(1,9); cprintf("selection => "); gotoxy(14,9); DutyCycle = 0; /* start off at zero velocity */ ; Phase = 0; do { while (!kbhit()) { pwm(porta, DutyCycle, Enable, Phase); }; /* end of while */ SpeedOption = getch(); switch(speedoption) { case 102 : /* 102 ASCII is f */ /* increase speed by 5% DC */ DutyCycle = DutyCycle + 5; if(dutycycle > 100) { DutyCycle = 100; gotoxy(1,20); cprintf("can't go faster"); delay(200); gotoxy(1,20); cprintf(" "); 44 8255 PC Interface Card Applications Manual

}; gotoxy(1,13); cprintf("going faster...\n"); Enabl e = 1; pwm(porta, DutyCycle, Enable, Phase); break; case 115 : /* 115 ASCII is s */ /* decrease speed by 5% DC */ DutyCycle = DutyCycle - 5; if(dutycycle < 0) { DutyCycle = 0; gotoxy(1,20); cprintf("can't go slower"); delay(200); gotoxy(1,20); cprintf(" "); }; gotoxy(1,13); cprintf("going slower...\n"); ; pwm(porta, DutyCycle, Enable, Phase); break; case 114 : /* 114 ASCII is r * / /* reverse direction at present DC */ ; if(phase == 0) { Phase = 2; } else if(phase ==2) { Phase = 0; }; pwm(porta, DutyCycle, Enable, Phase); gotoxy(1,13); cprintf("reversing...\n"); break; case 113 : /* 113 ASCII is q */ gotoxy(1,22); cprintf("quitting"); outportb(porta, 0); outportb(portb, 0); outportb(portc, 0); exit(0); break; }; /* end of switch */ gotoxy(14,9); } while(1); /* end of do */ }; /* end of main */ void pwm(int PORTA, int DutyCycle, int Enable, int Phase) { int OnTime, OffTime, TotalTime; TotalTime = 100; /* 100 msec */ OnTime = (int)(totaltime * DutyCycle / 100); OffTime = (int)(totaltime - OnTime); outportb(porta, Enable+Phase); delay(ontime); Enable = 0; outportb(porta, Enable+Phase); delay(offtime); gotoxy(1,10); cprintf("duty Cycle is %3d", DutyCycle); return; 8255 PC Interface Card Applications Manual 45

}; /* end of pwm */ This chapter showed how to interface a DC motor to your Boondog 8255 PC Interface Card. The hardware circuitry requires only one chip. The QBasic and Turbo C code implemented a pulse-width-modulated signal. This demonstrated how software can replace many hardware components. Many companies sell dedicated DC motor controller cards that plug into your PC. These cards often cost over $100. This chapter shows how you can build one for less than $5. These expensive boards give you control routines and additional hardware 13 to have very precise motor control. This may be overkill for your application and the circuit in this chapter may be all you need. The source code provides a starting point for you to implement your own control algorithms. 13 Typical control routines are trapezoidal motion profiles. Typical circuitry consist of chopper drivers and filters. 4 8255 PC Interface Card Applications Manual