electronics projects farhan shakeel

Upload: farhanshakeel

Post on 15-Jul-2015

2.630 views

Category:

Documents


27 download

TRANSCRIPT

KS Project ManualeFY june 2009Microcontroller-baseddc Motor controller Motion control plays avitalroleinin-dustrialautoma-tion.Manufacturingplants inindustrieslikechemical, pharmaceutical,plasticand textile,allrequiremotion control. And it may be a fat-belt application, fow-control applicationormixingof substances.Differenttypes of motorsAC, DC, servo or stepperareuseddepend-ing upon the application. Of these, DC motors are widely usedbecausecontrolling aDCmotorissomewhat easierthanotherkindsof motors. The motion of a DC mo-toriscontrolledusingaDC drive. DC drive changes the speedanddirectionofmo-tionofthemotor.Someof the DC drives are just a recti-fer with a series resistor that converts standard AC supply intoDCandgivesittothe motor through a switch and aseriesresistortochange thespeedanddirectionof rotationofthemotor.But many of the DC drives have aninbuiltmicrocontroller that provides programmable facilities,messagedisplay on LCD, precise control and alsoprotectionformotors. Using the DC drive you can programthemotionofthe motor,i.e.,howitshould rotate.Herearesomeofthe featuresofthisDCmotor controller:1.Controlledthrough microcontroller AT89C512.Messagedisplayedon the LCD moduleFig. 1: Circuit of the microcontroller-based DC motor controller KS Project ManualeFY june 20093.Start, s t opand changeof directionof themotor controlled by pushbut-tonswitch-esandin-dicatedby LED4 . C h a n g e s the running modeofthemotortocontinuous,re-versible or jogging5. Changes the speed of the motor6.Timesettingsarepossiblefor forwardandreverserunningofthe motorcircuit descriptionFig.1showsthecircuitofthemicro-controller-basedDCmotorcontroller. At the heart of the DC motor controller ismicrocontrollerAT89C51.Portpins P0.0 through P0.7 of the microcontrol-lerareinterfacedwithdatapinsD0 throughD7oftheLCDmodule,re-spectively. Port pins P3.0, P3.1 and P3.2 controltheLCDoperationthrough enable(E),register-select(RS)and read/write(R/W) pins, respec-tively.Contrast of the LCD is set bypresetVR1. PortpinsP1.0 throughP1. 7 areconnected toswitchesS1 throughS8for performingthe variousopera-tions.Power-onresetsignalforthemi-crocontrollerisgeneratedbythecom-binationofcapacitorC1andresistor R1. Switch S9 provides manual reset to themicrocontroller.A12MHzcrystal providesthebasicclockfrequencyto the microcontroller. Capacitors C2 and C3providestabilitytotheoscillator. EApin(pin31)ofthemicrocontroller isconnectedto5Vtoenableinternal access.PortpinsP2.0throughP2.3of themicrocontrollerareusedforLED indicationofrun,stop,clockwiseand anti-clockwiserotation.PortpinsP2.4 through P2.6 are connected to the inputs ofinvertersN3,N2andN1of74LS04 (IC2). The output of inverter N3 is used to trigger pin 2 of NE555 timer.TimerNE555isconfguredasa monostableanditstimeperiodisde-cided by preset VR2 and capacitor C4. When pin 2 of NE555 goes low, output pin3becomeshighforthepredeter-mined period. TheoutputofNE555isconnected to pole P of relay RL1. Normally-open (N/O)contactsofrelayRL1arecon-nected to N/O1 and N/C2 contacts of relayRL2.N/C1andN/O2contacts ofRL2areconnectedtoground.The outputsofinvertersN2andN1drive relaysRL1andRL2withthehelpof transistors T1 and T2, respectively. D1 andD2actasfree-wheelingdiodes. Poles P1 and P2 of RL2 are connected toIN1andIN2pinsofmotordriver L293D.OUT1andOUT2ofL293D drive motor M.Fig.2showsthepowersupply circuit. The 230V AC mains is stepped down by transformer X1 to deliver the secondaryoutputof9V,500mA.The transformeroutputisrectifedbya full-wavebridgerectifercomprising diodesD3throughD6,flteredbyca-pacitorC6andthenregulatedbyICs 7805(IC5)and7806(IC6).Capacitors C7andC8bypasstheripplespresent in the regulated 5V and 6V power sup-plies. LED5 acts as a power-on indica-torandresistorR10limitsthecurrent through LED5.Theproposedpanelarrangement forthemicrocontroller-basedDCmo-tor controller is shown in Fig. 3. An actual-size, single-side PCB for themicrocontroller-basedDCmotor controllerisshowninFig.4andits component layout in Fig. 5. operationThe eight pushbutton switches are con-nectedforeightdifferentfunctionsas shown in the table.WhenS1ispressed,themicro-controllersendslowlogictoportpin P2.5.ThehighoutputofinverterN2 drivestransistorT1intosaturation 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 RL1energises,themicrocontroller startsgeneratingPWMsignalonport pinP2.4,whichisfedtotriggerpin 2ofNE555throughinverterN3.The base frequency of the generated PWM signal is 500 Hz, which means the time periodis2ms(2000s).Theoutput pulse width varies from 500 s to 1500 s. The R-C time constant of the mon-ostablemultivibratoriskeptslightly 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.WhenswitchS3ispressed,relay Fig. 2: Circuit of the power supply Functions ofDifferent Switches SwitchFunctionS1 TostartmotorS2 TostopthemotorS3 ChangethemodeS4 ChangethedirectionS5 IncreasespeedS6 DecreasespeedS7 IncreasetimeS8 DecreasetimeFig. 3: Proposed panel arrangement for the DC motor controller KS Project ManualeFY june 2009RL2 energises. Pin IN1 of motor driver L293DreceivesthePWMsignaland pinIN2connectstoground.Asare-sult, the motor rotates in one direction (say, clockwise).WhenswitchS4ispressedagain, relayRL2de-energises.PinIN2of motor driver L293D receives the PWM signal and pin IN1 connects to ground. The motor now rotates in opposite di-rection (anti-clockwise). WhenswitchS3ispressed,differ-ent modes are selected in cyclic manner as given below:1.Continuousmode.Themotorro-tatescontinuouslywiththesetspeed in either direction 2.Reversiblemode.Themotorre-verses automatically after the set time 3.Joggingmode.Themotorrotates 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 rotationSwitches S5 and S6 are used to set thespeedofthemotor,eitherinin-creasingorderordecreasingorder,in continuous mode only. Switches S7 and S8 are used to set thetimeeitherinincreasingorderor decreasing order. softwareThe program is written in C language and compiled using Keil Vision3 com-piler.Itiswellcommentedandeasy to understand. The program has three majorsections:initialisationandkey press, display and motor control.Initialisation and key press. It con-sists of the main function that initialises timers, ports, LCD module and LED in-dication and then waits for key press. When any key is pressed, the program calls that particular function.In the main function, frst the ports are initialised as input/output, then the LCD is initialised and cleared. At pow-er-onresetormanualreset,message DC motor controller is displayed on the LCD and LED1 through LED4 turn off.WhenstartswitchS1ispressed, message Motor Start is displayed for a second, and then the mode and cur-rent speed are displayed. Run LED and clockwise-direction LED are on. Now the program waits for key press. When any key is pressed, the program jumps to one of the functions (start, direction, mode, etc). Fig. 4: A single-side, actual-size PCB layout for the microcontroller-based DC motor controller Fig. 5: Component layout for the PCB Display. It uses the following func-tions:1.writecmd functionsendscom-KS Project ManualeFY june 2009mandbytetotheLCD.Ittakesone argument byte and sends it to P0.2.writedatafunctionsendsdata byte to be displayed on the LCD. It also takesoneargumentbyteandsendsit to P0. 3.writestrfunctionwritesthe wholestring(message)ontheLCD.It takes pointer as an argument that points addressofthefrstcharacterofthe string, then through the pointer it sends all the characters one by one to P0.4. busy function checks the status of the busy fag of the LCD. If the fag is set, the LCD is not ready and the pro-gramremainswithintheloop.When the fag 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 rota-tioninoneofthemodes(continuous, reversibleorjogging).Themodeis selected by mode-selection fag m. As explained earlier, in continuous mode themotorkeepsrotatingwiththeset speed.Inreversiblemode,themotor changesdirectionautomaticallyafter the set time. In jogging mode, the mo-tor rotates for the set time, stops for a few seconds and then rotates.2. stop function stops rotating the motoranddisplaysthemessageon theLCDmodule.Thisisindicatedby glowing of the stop LED.3.directionfunctionincrements thecounterby1everytimeand checkswhetherthecountisevenor odd.Ifthecountiseven,itselects clock-wise direction, and if the count is odd, it selects anticlockwise direction. This is also indicated on direction CLK and ACLK LEDs.4.modefunctionchangesmodes incyclicmanner.Itincreasesmode-selectionfagmeverytime.If m=0 itselectscontinuousmode,ifm=1it Parts ListSemiconductors: IC1-AT89C51 microcontrollerIC2-74LS04 hex inverterIC3-NE555 timerIC4-L293D motor driverIC5-7805, 5V regulatorIC6-7806, 6V regulatorT1, T2-BC548 npn transistorD1-D6-1N4007 rectifer diodeLED1-LED5-5mm LEDResistors (all -watt, 5% carbon): R1-10-kilo-ohmR2-R5-2-kilo-ohmR6-R10, R12, R13-220-ohmR11-1-kilo-ohmVR1, VR2-10-kilo-ohm presetCapacitors: C1-10F, 16V electrolyticC2, C3-33pF ceramic diskC4, C7, C8-0.1F ceramic diskC5-0.01F ceramic diskC6-1000F, 25V electrolyticMiscellaneous: X1-230V AC primary to 9V,500mA secondarytransformerXTAL-12MHz crystalRL1-6V, 1C/O relayRL2-6V, 2C/O relayM-6V DC motorS1-S9-Push-to-on switchLCD module-162 line-14-pin bergstik SIPConnector (male & female) #include#include sbit rs = P3^1; // rs pin of LCDsbit en = P3^0; // en pin of LCDsbit rw = P3^2; // rw pin of LCDsbit b = P0^7; // busy fag sbit led1=P2^0; // run indicatorsbit led2=P2^1; // stop indicatorsbit led3=P2^2; // clockwise direction indicatorsbit led4=P2^3; // anticlockwise direction indicatorsbit PWM=P2^4; // PWM outputsbit RL1=P2^5; // relay 1 pinsbit RL2=P2^6; // relay 2 pindcmd.c unsigned int x=10; / / ontime unsigned int y=10; / / offtimeunsigned int m=0; // modeunsigned int d=0; // directionunsigned int t=100; // timeunsigned int r=0; // run fagvoid start(void); // function initilizationvoid 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 fagrs = 0; // select command registerrw = 0; // write enableP0 = a; // send byte to LCDen = 1; // apply strobe pulseen = 0;}void writedata(unsigned char b) // send data to LCD{ busy(); selectsreversiblemodeandifm=2it selects jogging mode. If m=3 it is reset to0againandselectscontinuous mode and likewise.5.incspeedfunctionincreasesthe width of the pulse by 100 s. The gener-ated PWM is of 500 Hz. That means total timeis2ms=2000s.Thewidthofthe pulse is varied from 500 s to 1500 s in steps of 100 s. To display the speed, the variable is frst converted into speed fac-tor 1 to 9 and then into ASCII.6.decspeedfunctionisthesame as incspeed but here the width of the pulse is decreased by 100 s.7.inctimefunctionincreases the reversibletimeofthemotorbyone second. It increases the variable in mul-tiplesof20.TodisplayitontheLCD module,itisfrstdividedby20and then converted into ASCII. 8. dectime function is the same as inctimebut itdecreasesreversible time by one second.Delay.Itusesthefollowingfunc-tions:1.keydlyfunctiongeneratesa fxdelayofaround50msforkeyde-bouncing.2. delay function generates a vari-able delay by timer 0. The basic delay is of 100 s. It is rotated in loop from fve to 15 times to generate minimum 500s and maximum 1500s delay.3.timefunctionagaingeneratesa 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.KS Project ManualeFY june 2009// check busy fagrs = 1; // select data registerrw = 0; // write enableP0 = b; // write enable en = 1; // send byte to LCDen = 0; // apply strobe pulse }void busy() // check busy fag of LCD{en = 0; // disable displayP0 = 0xFF; // P0 as inputrs = 0; // select command registerrw = 1; // read enablewhile(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 stringfor(i=0;i