Motion control plays. Microcontroller-based DC Motor Controller. KS Project Manual. a vital role in industrial

Similar documents
Digital temperature controllers

Normally, digital speedometers

S.Sirish Kumar CIRCUIT DIAGRAM

The Speech Based Floor Cleaning Robot

Ocean Controls KT-5198 Dual Bidirectional DC Motor Speed Controller

IZ602 LCD DRIVER Main features: Table 1 Pad description Pad No Pad Name Function

Induction Motor Protection using Micro Controller

HIGH LOW Astable multivibrators HIGH LOW 1:1

BIDIRECTIONAL ROTATION OF AN INDUCTION MOTOR WITH A REMOTE CONTROL DEVICE


A Design of GUI Based Wireless Robotic Car

Topics Introduction to Microprocessors

WIRELESS DC MOTOR SPEED AND DIRECTION CONTROL USING IR (PWM and H-Bridge)

Seminar Report Railway Gate Control 1. INTRODUCTION

DIY KIT 141. Multi-Mode Timer

Hardware Flags. and the RTI system. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Lock Cracker S. Lust, E. Skjel, R. LeBlanc, C. Kim

Adjustable Parametric Equalizer Hardware Description

Hello and welcome to this Renesas Interactive Course that provides an overview of the timers found on RL78 MCUs.

DUAL STEPPER MOTOR DRIVER

NJM3777 DUAL STEPPER MOTOR DRIVER NJM3777E3(SOP24)

RB-Dev-03 Devantech CMPS03 Magnetic Compass Module

Construction. sunil kumar Electromechanical energy meters. Parts List

LSI/CSI LS8292 LS8293. PRELIMINARY MICRO-STEPPING MOTOR CONTROLLER June 2013

WIRELESS DC MOTOR SPEED AND DIRECTION CONTROL USING RF COMMUNICATION

The rangefinder can be configured using an I2C machine interface. Settings control the

ADVANCED SAFETY APPLICATIONS FOR RAILWAY CROSSING

o What happens if S1 and S2 or S3 and S4 are closed simultaneously? o Perform Motor Control, H-Bridges LAB 2 H-Bridges with SPST Switches

1X6610 Signal/Power Management IC for Integrated Driver Module

Four Quadrant Speed Control of DC Motor with the Help of AT89S52 Microcontroller

EE 308 Lab Spring 2009

BV4112. Serial Micro stepping Motor Controller. Product specification. Dec V0.a. ByVac Page 1 of 18

EVDP610 IXDP610 Digital PWM Controller IC Evaluation Board

AEIJST - January Vol 4 - Issue 1 ISSN Automatic Railway Gate Controller by Using AT89C51

Construction of a high-voltage Buck-Boost capacitor charger. Transformer and logic

FRIDAY, 18 MAY 1.00 PM 4.00 PM. Where appropriate, you may use sketches to illustrate your answer.

ASTABLE MULTIVIBRATOR

NJM37717 STEPPER MOTOR DRIVER

Introduction to IC-555. Compiled By: Chanakya Bhatt EE, IT-NU

6V to 12V dc-dc boost converter using 555 timer IC

An Arduino-based DCC Accessory Decoder for Model Railroad Turnouts. Eric Thorstenson 11/1/17

Automatic Railway Gate Control & Track Switching

FMS Flight Simulator Encoder

Serial Servo Controller

H-bridge for DC motor control

ATV Modulator User Manual

A Sequencing LSI for Stepper Motors PCD4511/4521/4541

HT1620 HT1621 HT1622 HT16220 HT1623 HT1625 HT1626 HT1627 HT16270 COM

PLC-K506 Series FEATURES DESCRIPTION FEATURES

BMS BMU Vehicle Communications Protocol

Maintenance Manual ERICSSONZ LBI-31552E

Chapter 2: Your Boe-Bot's Servo Motors

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 11 Motor Control

REACTIVE POWER COMPENSATION IN DISTRIBUTION SYSTEM

Designated client product

HD66702 (LCD-II/E20) (Dot Matrix Liquid Crystal Display Controller/Driver) Description. Features

A3982 Stepper Motor Driver module

PICee Development System

33609/J Limiter/Compressor

DCS810 Brushed DC Servo Drive

12V Dimmer Kit, version 2

8253 functions ( General overview )

BASIC-Tiger Application Note No. 059 Rev Motor control with H bridges. Gunther Zielosko. 1. Introduction

PIC Functionality. General I/O Dedicated Interrupt Change State Interrupt Input Capture Output Compare PWM ADC RS232

KNC-PLC-K506 Series FEATURES DESCRIPTION FEATURES

HT162X HT1620 HT1621 HT1622 HT16220 HT1623 HT1625 HT1626 COM

High Current MOSFET Toggle Switch with Debounced Push Button

Houngninou 2. Abstract

Designated client product

No mark Time-limit SPDT (1c) A Time-limit DPDT (2c) B Time-limit SPDT (1c), Instantaneous SPDT (1c) S DIN W48 H48mm.

Lab Exercise 9: Stepper and Servo Motors

PAK-VIIIa Pulse Coprocessor Data Sheet by AWC

NJM3773 DUAL STEPPER MOTOR DRIVER

ML4818 Phase Modulation/Soft Switching Controller

I. INTRODUCTION II. LITERATURE REVIEW

ROTRONIC HygroClip Digital Input / Output

EE445L Fall 2012 Final Version B Page 1 of 7

Fig.1. A basic inductance and capacitance. (CR) oscillator.

EMBEDDED SYSTEM DESIGN FOR A DIGITAL MULTIMETER USING MOTOROLA HCS12 MICROCONTROLLER

LV8716QAGEVK Evaluation Kit User Guide

III. MATERIAL AND COMPONENTS USED

DCS Series Brush DC Servo Drive. Datasheet

Microprocessor & Interfacing Lecture Programmable Interval Timer

Auto-Fact Security System

International Journal of Advance Engineering and Research Development

International Journal of Advance Engineering and Research Development. Wireless Control of Dc Motor Using RF Communication

PBL 3775/1 Dual Stepper Motor Driver

L297 L297A STEPPER MOTOR CONTROLLERS

isma-b-w0202 Modbus User Manual GC5 Sp. z o.o. Poland, Warsaw

HW D2: Sequential Logic, Counters, Debounce

6. HARDWARE PROTOTYPE AND EXPERIMENTAL RESULTS

CV Arpeggiator Rev 1. Last updated

PBL 3717/2 Stepper Motor Drive Circuit

Controlling DC Brush Motor using MD10B or MD30B. Version 1.2. Aug Cytron Technologies Sdn. Bhd.

Embedded Systems and Software

Electronic Components

ECE 511: FINAL PROJECT REPORT GROUP 7 MSP430 TANK

PLC BASED RAILWAY LEVEL CROSSING GATE CONTROL

EE 308 Spring S12 SUBSYSTEMS: PULSE WIDTH MODULATION, A/D CONVERTER, AND SYNCHRONOUS SERIAN INTERFACE

css Custom Silicon Solutions, Inc.

Transcription:

Microcontroller-based DC Motor Controller Motion control plays a vital role in industrial automation. Manufacturing plants in industries like chemical, pharmaceutical, plastic and textile, all require motion control. And it may be a flatbelt application, flow-control application or mixing of substances. Different types of motors AC, DC, servo or stepper are used depending upon the application. Of these, DC motors are widely used because controlling a DC motor is somewhat easier than other kinds of motors. The motion of a DC motor is controlled using a DC drive. DC drive changes the speed and direction of motion of the motor. Some of the DC drives are just a rectifier with a series resistor that converts standard AC supply into DC and gives it to the motor through a switch and a series resistor to change the speed and direction of rotation of the motor. But many of the DC drives have an inbuilt microcontroller that provides programmable facilities, message display on LCD, precise control and also protection for motors. Using the DC drive you can program the motion of the motor, i.e., how it should rotate. Here are some of the features of this DC motor controller: 1. Controlled through microcontroller AT89C51 2. Message displayed on the LCD module Fig. 1: Circuit of the microcontroller-based DC motor controller

Fig. 2: Circuit of the power supply Fig. 3: Proposed panel arrangement for the DC motor controller Functions of Different Switches Switch S1 S2 S3 S4 S5 S6 S7 S8 Function To start motor To stop the motor Change the mode Change the direction Increase speed Decrease speed Increase time Decrease time 3. Start, s t o p a n d change of direction of the motor controlled by pushbutton switches and indicated by LED 4. C h a n g e s the running mode of the motor to continuous, reversible or jogging 5. Changes the speed of the motor 6. Time settings are possible for forward and reverse running of the motor Circuit description Fig. 1 shows the circuit of the microcontroller-based DC motor controller. At the heart of the DC motor controller is microcontroller AT89C51. Port pins P0.0 through P0.7 of the microcontroller are interfaced with data pins D0 through D7 of the LCD module, respectively. Port pins P3.0, P3.1 and P3.2 control the LCD operation through enable (E), register-select (RS) and read/write (R/ W) pins, respectively. Contrast of the LCD is set by preset VR1. Port pins P1.0 through P1.7 are connected to switches S1 through S8 for performing the various operations. Power-on reset signal for the microcontroller is generated by the combination of capacitor C1 and resistor R1. Switch S9 provides manual reset to the microcontroller. A 12MHz crystal provides the basic clock frequency to the microcontroller. Capacitors C2 and C3 provide stability to the oscillator. EA pin (pin 31) of the microcontroller is connected to 5V to enable internal access. Port pins P2.0 through P2.3 of the microcontroller are used for LED indication of run, stop, clockwise and anti-clockwise rotation. Port pins P2.4 through P2.6 are connected to the inputs of inverters N3, N2 and N1 of 74LS04 (IC2). The output of inverter N3 is used to trigger pin 2 of NE555 timer. Timer NE555 is configured as a monostable and its time period is decided by preset VR2 and capacitor C4. When pin 2 of NE555 goes low, output pin 3 becomes high for the predetermined period. The output of NE555 is connected to pole P of relay RL1. Normally-open (N/O) contacts of relay RL1 are connected to N/O1 and N/C2 contacts of relay RL2. N/C1 and N/O2 contacts of RL2 are connected to ground. The outputs of inverters N2 and N1 drive relays RL1 and RL2 with the help of transistors T1 and T2, respectively. D1 and D2 act as free-wheeling diodes. Poles P1 and P2 of RL2 are connected to IN1 and IN2 pins of motor driver L293D. OUT1 and OUT2 of L293D drive motor M. Fig. 2 shows the power supply circuit. The 230V AC mains is stepped down by transformer X1 to deliver the secondary output of 9V, 500 ma. The transformer output is rectified by a full-wave bridge rectifier comprising diodes D3 through D6, filtered by capacitor C6 and then regulated by ICs 7805 (IC5) and 7806 (IC6). Capacitors C7 and C8 bypass the ripples present in the regulated 5V and 6V power supplies. LED5 acts as a power- on indicator and resistor R10 limits the current through LED5. The proposed panel arrangement for the microcontroller-based DC motor controller is shown in Fig. 3. An actual-size, single-side PCB for the microcontroller-based DC motor controller is shown in Fig. 4 and its component layout in Fig. 5. Operation The eight pushbutton switches are connected for eight different functions as shown in the table. When S1 is pressed, the microcontroller sends low logic to port pin P2.5. The high output of inverter N2 drives transistor T1 into saturation and relay RL1 energises. So the output of NE555 is fed to inputs IN1 and IN2 of L293D through both the contacts of relay RL2. Now at the same time, after RL1 energises, the microcontroller starts generating PWM signal on port pin P2.4, which is fed to trigger pin 2 of NE555 through inverter N3. The base frequency of the generated PWM signal is 500 Hz, which means the time period is 2 ms (2000µs). The output pulse width varies from 500 µs to 1500 µs. The R-C time constant of the monostable multivibrator is kept slightly less then 500 µs to generate exactly the same inverted PWM as is generated by the microcontroller. When switch S2 is pressed, port-pin P2.5 goes high and RL1 de-energises to stop the motor. When switch S3 is pressed, relay

RL2 energises. Pin IN1 of motor driver L293D receives the PWM signal and pin IN2 connects to ground. As a result, the motor rotates in one direction (say, clockwise). When switch S4 is pressed again, relay RL2 de-energises. Pin IN2 of motor driver L293D receives the PWM signal and pin IN1 connects to ground. The motor now rotates in opposite direction (anti-clockwise). When switch S3 is pressed, different modes are selected in cyclic manner as given below: 1. Continuous mode. The motor rotates continuously with the set speed in either direction 2. Reversible mode. The motor reverses automatically after the set time 3. Jogging mode. The motor rotates for the set time in either direction and then stops for a few seconds and again rotates for the set time. It is also called pulse rotation Switches S5 and S6 are used to set the speed of the motor, either in increasing order or decreasing order, in continuous mode only. Switches S7 and S8 are used to set the time either in increasing order or decreasing order. Fig. 4: A single-side, actual-size PCB layout for the microcontroller-based DC motor controller Software The program is written in C language and compiled using Keil µvision3 compiler. It is well commented and easy to understand. The program has three major sections: initialisation and key press, display and motor control. Initialisation and key press. It consists of the main function that initialises timers, ports, LCD module and LED indication and then waits for key press. When any key is pressed, the program calls that particular function. In the main function, first the ports are initialised as input/output, then the LCD is initialised and cleared. At power-on reset or manual reset, message DC motor controller is displayed on the LCD and LED1 through LED4 turn off. When start switch S1 is pressed, message Motor Start is displayed for a second, and then the mode and current speed are displayed. Run LED and clockwise-direction LED are on. Now the program waits for key press. When Fig. 5: Component layout for the PCB any key is pressed, the program jumps to one of the functions (start, direction, mode, etc). Display. It uses the following functions: 1. writecmd function sends com-

Parts List Semiconductors: IC1 - AT89C51 microcontroller IC2-74LS04 hex inverter IC3 - NE555 timer IC4 - L293D motor driver IC5-7805, 5V regulator IC6-7806, 6V regulator T1, T2 - BC548 npn transistor D1-D6-1N4007 rectifier diode LED1-LED5-5mm LED Resistors (all ¼-watt, ±5% carbon): R1-10-kilo-ohm R2-R5-2-kilo-ohm R6-R10, R12, R13-220-ohm R11-1-kilo-ohm VR1, VR2-10-kilo-ohm preset Capacitors: C1-10µF, 16V electrolytic C2, C3-33pF ceramic disk C4, C7, C8-0.1µF ceramic disk C5-0.01µF ceramic disk C6-1000µF, 25V electrolytic Miscellaneous: X1-230V AC primary to 9V, 500mA secondary transformer X TAL - 12MHz crystal RL1-6V, 1C/O relay RL2-6V, 2C/O relay M - 6V DC motor S1-S9 - Push-to-on switch LCD module - 16 2 line - 14-pin bergstik SIP Connector (male & female) mand byte to the LCD. It takes one argument byte and sends it to P0. 2. writedata function sends data byte to be displayed on the LCD. It also takes one argument byte and sends it to P0. 3. writestr function writes the whole string (message) on the LCD. It takes pointer as an argument that points address of the first character of the string, then through the pointer it sends all the characters one by one to P0. 4. busy function checks the status of the busy flag of the LCD. If the flag is set, the LCD is not ready and the program remains within the loop. When the flag is reset, the LCD is ready and the program comes out of the loop. Motor control. It uses the following functions: 1. start function starts motor rotation in one of the modes (continuous, reversible or jogging). The mode is selected by mode-selection flag m. As explained earlier, in continuous mode the motor keeps rotating with the set speed. In reversible mode, the motor changes direction automatically after the set time. In jogging mode, the motor rotates for the set time, stops for a few seconds and then rotates. 2. stop function stops rotating the motor and displays the message on the LCD module. This is indicated by glowing of the stop LED. 3. direction function increments the counter by 1 every time and checks whether the count is even or odd. If the count is even, it selects clock-wise direction, and if the count is odd, it selects anticlockwise direction. This is also indicated on direction CLK and ACLK LEDs. 4. mode function changes modes in cyclic manner. It increases modeselection flag m every time. If m=0 it selects continuous mode, if m=1 it KS Project Manual selects reversible mode and if m=2 it selects jogging mode. If m=3 it is reset to 0 again and selects continuous mode and likewise. 5. incspeed function increases the width of the pulse by 100 µs. The generated PWM is of 500 Hz. That means total time is 2 ms=2000 µs. The width of the pulse is varied from 500 µs to 1500 µs in steps of 100 µs. To display the speed, the variable is first converted into speed factor 1 to 9 and then into ASCII. 6. decspeed function is the same as incspeed but here the width of the pulse is decreased by 100 µs. 7. inctime function increases the reversible time of the motor by one second. It increases the variable in multiples of 20. To display it on the LCD module, it is first divided by 20 and then converted into ASCII. 8. dectime function is the same as inctime but it decreases reversible time by one second. Delay. It uses the following functions: 1. keydly function generates a fix delay of around 50 ms for key debouncing. 2. delay function generates a variable delay by timer 0. The basic delay is of 100 µs. It is rotated in loop from five to 15 times to generate minimum 500µs and maximum 1500µs delay. 3. time function again generates a variable delay by timer 1. The basic delay is of 50 ms. It is rotated in multiples of 20 from 20 to 180 to generate minimum 1- second and maximum 9-second delay. #include<reg51.h> #include <string.h> sbit rs = P3^1; // rs pin of LCD sbit en = P3^0; // en pin of LCD sbit rw = P3^2; // rw pin of LCD sbit b = P0^7; // busy flag sbit led1=p2^0; // run indicator sbit led2=p2^1; // stop indicator sbit led3=p2^2; // clockwise direction indicator sbit led4=p2^3; // anticlockwise direction indicator sbit PWM=P2^4; // PWM output sbit RL1=P2^5; // relay 1 pin sbit RL2=P2^6; // relay 2 pin dcmd.c unsigned int x=10; / / ontime unsigned int y=10; / / offtime unsigned int m=0; // mode unsigned int d=0; // direction unsigned int t=100; // time unsigned int r=0; // run flag void start(void); // function initilization void mode(void); void direction(void); void incspeed(void); void decspeed(void); void inctime(void); void dectime(void); void time(unsigned int); void delay(unsigned int); void keydly(void); void busy(void); void writecmd(unsigned char a) // send command to LCD busy(); // check busy flag rs = 0; // select command register rw = 0; // write enable P0 = a; // send byte to LCD en = 1; // apply strobe pulse en = 0; void writedata(unsigned char b) // send data to LCD busy();

void busy() LCD // check busy flag rs = 1; // select data register rw = 0; // write enable P0 = b; // write enable en = 1; // send byte to LCD en = 0; // apply strobe pulse // check busy flag of en = 0; // disable display P0 = 0xFF; // P0 as input rs = 0; // select command register rw = 1; // read enable while(b==1) // if busy bit is 1 en=0; // remain withine loop en=1; en=0; void writestr(unsigned char *s) // send string message to LCD unsigned char l,i; l = strlen(s); // get length of string for(i=0;i<l;i++) writedata(*s); // till the length of string s++; // send characters one by one void start() // start rotating motor if(m==0) // for m=0 start continuous mode r=1; // set run flag P1=0xFF; // send all 1 s to P1 while(p1==0xff) // till no key is pressed led1=1; // indication on run LED PWM=1; // send high logic to PWM pin delay(x); // on time delay PWM=0; // now send low logic to PWM delay(y); // off time delay else if(m==1) // for m=1 start reversible mode r=1; // set run flag P1=0xFF; // send all 1 s to P1 while(p1==0xff) pressed // till no key is led1=1; // run LED=1 led3=1; led4=0; PWM=1; RL2=1; // send high on PWM pin // select one direction time(t); // wait for desired time RL1=1; // switch off RL1 led1=0; // run LED=0; time(20); // wait for 1 sec led1=1; // again run LED=1 led3=0; led4=1; RL2=0; // select other direction time(t); // wait for desire time RL1=1; // switch off RL1 led1=0; // run LED=0 time(20); // wait for 1 sec PWM=0; else if(m==2) // for m=2 start jogging mode r=1; // reset run flag P1=0xFF; // send all 1 s to P1 while(p1==0xff) pressed led1=1; PWM=1; // till no key is // send high on PWM pin time(t); // wait for 1 sec RL1=1; PWM=0; led1=0; time(20); // switch off RL1 // send low on PWM pin void direction() // alter the direction // key debounce delay d++; // increment count if((d%2)==0) // check for even or odd led3=1; // indicate on LEDs led4=0; RL2=1; // switch ON / OFF RL2 else led3=0; led4=1; RL2=0; void mode() // change mode of rotation // key debounce delay writecmd(0x80); // display message on first line first column m++; // increment count if(m==3) m=0; // if it is 3 reset it if(m==0) writestr( mode:continuous ); // otherwise display mode time(15); else if(m==1) writestr( mode:reversible ); time(15); else if(m==2) writestr( mode:jogging ); time(15); void decspeed() // increase speed int z; / / key debounce writecmd(0xc0); / / select second line on LCD if(y<14) / / if not max pulse width x--; y++; / / increase it convert it in to z=y-5+0x30; / / 1 to 10 scale and ASCII writestr( speed: ); // diaplay speed on LCD writedata(z); writestr( ); else if(y==14) writestr( min speed: 9 );// if max speed display message void incspeed() / / increase speed int w; writecmd(0xc0); // key debounce if(y>6) / / if not minimum width x++; y-- ; // decrease it w=y-5+0x30; // do same as above writestr( speed: ); writedata(w); writestr( ); else if(y==6) writestr( max speed: 1 ); // if min speed display message void inctime() / / increase time int p; / / key debounce delay writecmd(0xc0); if(t<180) / / if not max time

t+=20; / / increase it by 1 sec p=t/20; p=p+0x30; / / convert it in to ASCII writestr( time: ); // display it writedata(p); w r i t e s t r ( s e c ); else if(t==180) writestr( max time: 9 sec ); // if max time display message void dectime() / / decrease time int q; / / key debounce delay writecmd(0xc0); if(t>20) / / if not min time t-=20; / / decrease it q=t/20; q=q+0x30; / / do same as above writestr( time: ); writedata(q); w r i t e s t r ( s e c ); else if(t==20) writestr( min time: 1 sec ); // if min time display message void keydly() / / key debounce delay int a,b; for(a=0;a<50;a++) for(b=0;b<1000;b++); void time(unsigned int c) // change time in seconds int k; TL1 = 0xAF; // use timer 1 TH1 = 0x3C; // to generate 50 ms delay TR1 = 1; / / start timer for(k=0;k<=c;k++) / / rotate loop in multiples of 20 while(tf1==0); / / wait till timer overflow TF1 = 0; / / reset the flag TL1 = 0xAF; // reload it TH1 = 0x3C; TR1 = 0; / / stop timer void delay(unsigned int c1) // change time in micro seconds int a; TH0=0x9B; / / select timer 0 TL0=0x9B; / / to generate 100 micro second delay TR0=1; / / start timer for(a=0;a<c1;a++) / / rotate loop between 5 to 15 while(tf0==0); / / wait until timer overflow TF0=0; / / reset the flag TR0=0; / / stop timer void main() TMOD=0x12; // timer1 in 16 bit,timer 0 in 8 bit auto reload mode P2=0xE0; / / LEDs off, relays OFF P0=0x00; / / P0, P3 output ports P3=0x00; writecmd(0x3c); / / initilize LCD writecmd(0x0e); writecmd(0x01); writecmd(0x84); / / display message writestr( DC Motor ); // DC motor controller in writecmd(0xc3); / / center of LCD writestr( Controller ); agin:p1=0xff; / / P1 as input port while(p1==0xff); / / wait until any key press loop:switch(p1) case 0xFE: // for first key // key debounce writecmd(0x01); writestr( motor start ); time(50); // wait for 2.5 sec writecmd(0x80); writestr( mode:continuous );// display current mode and speed writecmd(0xc0); writestr( speed: 5 ); led1=1; / / Run LED ON led2=0; / / stop LED OFF led3=1; / / clockwise direction ON led4=0; / / anticlockwise direction OFF start(); / / sart rotating motor case 0xFD: // for second key // key debounce r=0; // run flag reset writecmd(0x01); writestr( motor stop );// display message led1=0; / / Run OFF led2=1; / / stop LED ON led3=0; / / clockwise direction OFF led4=0; / / anticlockwise direction OFF PWM=0; / / low logic to PWM pin RL1=1; / / relay1 off case 0xFB: // for third key mode(); / / select mode if(r==1) start(); / / jump to case 0xF7: // for fourth key direction(); / / change direction case 0xEF: // for fifth key incspeed(); / / increase speed case 0xDF: // for sixth key decspeed(); / / decrease speed case 0xBF: // for seventh key inctime(); // increase time case 0x7F: // for eigth key dectime(); // decrease time if(r==1) goto loop; / / if run flag is set jump of key detect else goto agin; / / if not jump to again