The development of high performance motor drives is very important in industrial as well as other purpose applications. Generally, a high performance motor drive system must have good dynamic speed command tracking and load regulating response. The dc motors are used in various applications such as defense, industries, Robotics etc. DC drives, because of their simplicity, ease of application, reliability and favorable cost have long been a backbone of industrial applications. The project provides the efficient and simple method to control speed of DC motor using ATMEGA16 microcontroller and L298N motor driver IC.
With the use of ATMEGA16 and l298N we can drive the dc motor at desired speed having a feedback loop and in this project we have used proportional integral and derivative method in which errors are not only solved but also taken to its minimal value with very low amount of error oscillations.
The proportional part of PID examines the magnitude of the error and it reacts proportionally. A large error receives a large response
To address the first issue with the proportional control, integral control attempts to correct small error (offset).
The derivative part of the control output attempts to look at the rate of change in the error signal. Derivative will cause a greater system response to a rapid rate of change than to a small rate of change.
WORKING OF PROJECT
First the speed of the dc motor connected is set with the help of a variable resistance of 10k which is connected to A0 pin which works as ADC port in the microcontroller. As the controller gets the speed set by the user it starts counting the pulse which it is getting from a CMOS sensor and on the basis of that it measures the current speed of motor.After that the user entered speed and the current speed of the motor is compared and the difference is calculated as error and in accordance to that error the pwm signal given to the L298n IC for driving motor through microcontroller is varied.
Project Source Code
Project Source Code
###$regfile "M16DEF.DAT"$crystal = 8000000$baud = 9600$hwstack = 32$swstack = 8$framesize = 40Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Prescale = 8Config Lcdpin = Pin , E = Portc.4 , Rs = Portc.5 , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0Config Lcd = 16 * 2Config Adc = Single , Prescaler = Auto , Reference = AvccConfig Timer0 = Counter , Edge = RisingOn Ovf0 Tim0_isrEnable InterruptsEnable Timer0Tcnt0 = 0Config Portc = OutputDim A As IntegerDim B As IntegerDim C As IntegerDim D As SingleDim E As SingleDim F As SingleDim G As SingleDim H As SingleDim I As SingleDim J As SingleDim K As SingleDim L As SingleDim M As SingleDim X As SingleDim Y As SingleDim Errr As IntegerDim Ad As IntegerDim Onn As IntegerDim P_gain As SingleDim I_gain As SingleDim D_gain As SingleDim Dt As SingleDim Set_rpm As IntegerDim Previous_error As SingleDim D_error As SingleDim I_error As SingleDim Error As SingleDim Feedback_rpm As IntegerDim Otpt As IntegerSet_rpm = 0Previous_error = 0D_error = 0I_error = 0P_gain = 0.65I_gain = 0.005D_gain = 0.005Dt = 0.5A = 0B = 0C = 0D = 0E = 0F = 0H = 0G = 0I = 0J = 0K = 0L = 0M = 0X = 0Y = 0Otpt = 0Previous_error = Set_rpm - Feedback_rpmStart AdcDoSet_rpm = Getadc(0)Locate 2 , 1Lcd Set_rpmTcnt0 = 0Start Timer0Waitms 500Stop Timer0A = Tcnt0B = F * 255C = A + BD = C / 1E = D * 5E = E + 0G = EFeedback_rpm = GX = Set_rpm - 2Y = Set_rpm + 2If G > X And G < Y ThenG = Set_rpmEnd IfClsLocate 1 , 1Lcd GF = 0Error = Set_rpm - Feedback_rpmH = Error * DtI_error = I_error + HI = Error - Previous_errorD_error = I / DtJ = P_gain * ErrorK = I_gain * I_errorL = D_gain * D_errorM = J + KOtpt = M + LPrevious_error = Error' Errr = Set_rpm - OtptOnn = Onn + OtptIf Onn > 254 ThenOnn = 254End IfCompare1a = OnnLoopTim0_isr:F = F + 1ReturnEndExplanation of main course of program:Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Prescale = 8Config Lcdpin = Pin , E = Portc.4 , Rs = Portc.5 , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 , Db7 = Portc.0Config Lcd = 16 * 2Config Adc = Single , Prescaler = Auto , Reference = AvccConfig Timer0 = Counter , Edge = RisingOn Ovf0 Tim0_isrTimer 0 is configured as counter which counts the input pulse from the sensor.Timer 1 is configured as PWM to give the output signal to the L298n.Lcd and adc is also configured.Start Timer0Waitms 500Stop Timer0A = Tcnt0Timer is started to count the pulse for every 500 ms.Value is stored into variable A.A = Tcnt0B = F * 255C = A + BD = C / 1E = D * 5E = E + 0G = EConversion of pulses into rpmFeedback_rpm = GX = Set_rpm - 2Y = Set_rpm + 2If G > X And G < Y ThenG = Set_rpmEnd IfClsLocate 1 , 1Lcd GF = 0Error = Set_rpm - Feedback_rpmH = Error * DtI_error = I_error + HI = Error - Previous_errorD_error = I / DtJ = P_gain * ErrorK = I_gain * I_errorL = D_gain * D_errorM = J + KOtpt = M + LPrevious_error = Error' Errr = Set_rpm - OtptOnn = Onn + Otpt
Filed Under: Electronic Projects