Home
fulltext01
Contents
1. e t c t Figure 2 PID algorithm Mainly the used PID controller is a digitalized version thus the equation consequently digitalized as well Kd T LE 2 4 1 Cap N V P D c Kple e 4 KiTe Name Omar Jones Course Electronics Engineering Final year 3 gt 3 2 PWM Puls Width Modulation Is a very powerful technique that reduces the cost and time by digitalizing the analog signals means either on or off where PWM is monitoring by encoding the input and decoding the output of the system to manage analog device devices The duty cycle represents a ratio between the ON time and the Total time In this system a frequency of 500Hz has been provided which makes the Total time period 2ms Embedded programming for the 80x51 Dr Goran Bezanov see the following figure Whole Period Off Ti On Time S 25 1570 Figure 3 Duty cycle This could be simplified to the following equations Lu P eb Te Lt T SS The periods that the PID and PWM are running on have to be ran on the same period because the PWM take the duty cycle value from the PID calculations The output from the Arduino is a PWM digital output thereby it s connected to a transistor to control the Fan speed oimply it turns the motor on and off to saturate the calculated duty cycle The frequency or the named period can be increased or decreased regarding to the usage and the used devi
2. 8 LINZ ie go 9 4 1 3 Writing the DOUG e erietree nr reU RERO Rene xao Putant rr rr rr nar nana 10 4 1 4 Wiring COde SCaliNQO rserssrrsersorrsrrrerrnrrrr ere rens rr r rr erna anna 10 15 4 1 5 TCRR Timer Counter Control registers 16 17 MAN Ei cu EC ii e na EA ET a E er Eia 18 4 2 2 FIBBOUIMO SB V2 2 noriai ra E E i 18 4 2 3 ATmega328 AND 8051 Family comparison 19 5 Hardware Components sissrssessrersersrrrerrerrrerrrrn rens cece rer eene enint RESAS 20 5 1 LM35DH Temperature Sensor Lese 20 5 2 Brushless DC Motor Fan ssesesseemHHe ene 21 5 3 POTentiometer knob inssrnssssssrrerserrersrrrre rss rr cece ecesseeeeesessseteeeeessn 5 4 BJT Transistor iius eerie rn rtr rb e meet t Kanna 22 DO LEE PROTECT T TT m Tm 22 6 RESUM RNC 23 MLB I 23 D xcix ugs E 24 8 Heferences sossesseerereeeeersrsererrrrrrrrrrr sr ee ee e se se he esses se ie esse se esse ie essere sees 25 902101928505 AR E 26 9 1 VBB ee a ee nnrr nran 26 9 2 Code R 21 29 F PIOJGCUP NOTOS ERR S 30 9 3 1 Soldering Freeduino sssmmssssrssrrerrerrrrrrrrerrerrr rr rr eens een enone 31 PEEL ient TEST RTT Mm 31 9 3 3 After some Enhancements Leseeeueeeesee 32 vi 1 1 Introduction The system designed
3. 3 1 2 Aim The project is aimed to develop an embedded DC Motor controller using PID controller on ATmega328 microcontroller The Digital PID control has been initialized in a structure of programming the microcontroller via USB using Wiring programming language in Arduino software Basically the program takes the desired temperature and feedback from temperature sensor as inputs and calculates the Duty Cycle by PID controller algorithms to deliver a suitable power to the fan as an output The progress of the project has been divided mainly in two parts the software part which includes the programming of the microcontroller and the hardware part the sensor the fan the knob and Arduino To get an acceptable output to the DC motor which runs regarding to the applied temperature the code of this process has been simulated on Arduino although the simulation gave no accurate results as expected thus it needed actual testing The synchronizations of the different operations have been calculated in the microcontroller but to get a suitable output an experimental progress gave a better result Mainly the result of the PID control code should be tested with oscilloscope to make sure of the input output voltage and signals and not depending on software simulator only Simultaneously a correction of the code is expected under signals measurements Implementing the PID controller will give a better result although this high precision wo
4. 3 D Gain 0 5 PID Coefficients example void setup M und setPoint An open project written debugged and supported by Massimo Banzi David Cuartielles Tom Igoe Gianluca Martino and David Mellis Based on processing by Casey Reas and Ben Fry Figure 6 Arduino software There s no regular simulator for Arduino normally you see the result when the hardware Freeduino is connected but there s a separate program used to simulate Arduino files called Virtual Bread Board see appendix Name Omar Jones Course Electronics Engineering Final year 3 4 1 3 Writing the code At beginning the C language was used to produce the functions and the needed commands Since the used software Arduino demands Wiring language to run the microcontroller the old version of the program had to be edited to Wiring language as well The Wiring language structure is similar to the C C still there are a couple of main functions names and usage are different i e void main and while 1 were replaced with void oop Arduino helps to setup the settings of loading and compiling the program by choosing the right board port the type of the hardware and microcontroller 4 1 4 Wiring code As explained above the Wiring language is similar to C C language so we start with declaration of the needed variables A special function called setup is needed though to make an additional declaration of the Input Output port
5. Asse LI 8051 8031 80C51 80C31 PERIPHERALS V1 3 X33 IE IE IE IE IE IE IE IE IE IE IE IE IE IE IE IE IE IE IE IE IE IE IE IE 9 E E EE EE IE IE RESTRICTED VERSION WITH 2048 BYTE CODE SIZE LIMIT CURRENTLY USED 785 BYTE 38 x 5 Cg annua AL OE EE SE SE E IE 3 3 3 IE IE E E EE EE E EE IE E IE IE IE IE IE IE IE IE IE IE IE IE IE IE IE 9 IE else if error gt 255 inis Run dScope Simulator Debugger else if error lt 8 i pid out 8 Idos ASM ASSIGN BreakDisable BreakEnable TAB INS ia Start C wVision S1 evaluation BAldScope crllabsiDUTY i C pWision S1 evaluation Figure 5 Keil uVision dScope The simulator dScope could be run from Keil program from the run popup menu as shown above The input output ports operate in 8 bit the user could see the output results directly by changing the inputs bits to High or Low We can even set the inputs Timer Counter bits to specify the suitable mode a couple of steps should be followed by setting the compiler is C51 and C language After a while AVRstudio 4 was used to code and simulate ATmega g for the same program to see the differences and similarities in using different type of 8051 Basically the AVRstudio is very similar to Keil uVision it simulates in the same way as well but we can use more types of mic
6. Final year 3 error average Setpoint calculate the difference delay 10 10ms delay if error gt 1 Duty C pid error prev error call pid function out error 32 run fan calculated error minimum output to run the fan delay 200 200ms delay analogWrite PWM Pin out write to the Fan digitalWrite 13 HIGH write to the blue cool diod delay 500 0 5s delay prev error error save old error to be used by the PID function Duty C 0 reset register j else out 0 analogWrite PWM fPin out motor off it s too cold and start blinking the blue diod digitalWrite 13 HIGH write to the blue cool diod delay 200 digitalWrite 13 L OW write to the blue cool diod delay 200 j j j End Main l PID Function int pid int error ctrl int prev error Ctrl double p 0 i 0 d 0 int sum 0 p P Gain error Proportional part i Gain error ctrl prev error ctrl integral part d D Gain error ctrl prev error ctrl derivative part sum p i d PID return sum Program End 29 Name Omar Jones Course Electronics Engineering Final year 3 8 3 Project photos 8 3 1 Soldering Freeduino RI y T wtf ee 5 LT m 1 g LLL y 2 b i ax m l Wr o E 30 Name Omar Jones Course Electronics Engineering Final year 3 8 3 2 Project test
7. Name Omar Jones Course Electronics Engineering Final year 3 8 3 3 After some enhancements 32 Name Omar Jones Course Electronics Engineering Final year 3 Upphovsr tt Detta dokument h lls tillg ngligt pa Internet eller dess framtida ers ttare under 25 ar fran publiceringsdatum under f ruts ttning att inga extraordin ra omst ndigheter uppst r Tillg ng till dokumentet inneb r tillst nd f r var och en att l sa ladda ner skriva ut enstaka kopior f r enskilt bruk och att anv nda det of r ndrat f r ickekommersiell forskning och f r undervisning verf ring av upphovsr tten vid en senare tidpunkt kan inte upph va detta tillst nd All annan anv ndning av dokumentet kr ver upphovsmannens medgivande F r att garantera ktheten s kerheten och tillg ngligheten finns l sningar av teknisk och administrativ art Upphovsmannens ideella r tt innefattar r tt att bli n mnd som upphovsman 1 den omfattning som god sed kr ver vid anv ndning av dokumentet p ovan beskrivna s tt samt skydd mot att dokumentet ndras eller presenteras i s dan form eller i s dant sammanhang som r kr nkande f r upphovsmannens litter ra eller konstn rliga anseende eller egenart F r ytterligare information om Link ping University Electronic Press se f rlagets hemsida http www ep liu se Copyright The publishers will keep this document online on the Internet or its possible replacement for a perio
8. atmel com Its not possible though to specify different frequency for each pin though whereas a Timer Counter setting applies the concerned two pins Nevertheless there are three pairs that could have three different frequencies Basically there are only two Timers Counters that have been changed in this project Since we need to set pin 5 to write 10 bit for the moment then pin 5 6 TCCROA and TCCROB have to be modified An explanation of this modification is illustrated in the following way gt TCCROA Table4 TCCROA Bit 7 4 are Compare output Mode for Channel A amp B we are only interesting in fast PWM mode Bit 3 2 are reserved Bit 1 0 Wave Generation Mode these bits with combination with WGM13 12 bits see table 5 TCCROB modifies the type of generation mode WGM12 WGM11 WGM10 Timer top Top Timer HEX Decimal E eg edd sp OE Table5 Fast PWM mode 10 bit 16 Name Omar Jones Course Electronics Engineering Final year 3 gt TCCROB Bit a I e ONE RO ICES1 WGMI3 RW RW R RW RW RW RW RW oS ee ee ee eee Read Write Initial value Table6 TCCROB Bit 7 Input Capture Noise Canceller this bit filters the incoming noise but on the other hand it will make a longer delay Bit 6 Input Capture Edge Select is a trigger capture event Bit 5 reserved Bit4 3 WGM13 12 Wave Generation Mode Bit2 0 Clock Select these three bits set the prescaler in other word the freq
9. calculate these errors to deliver a suitable duty cycle value to the fan as illustrated in the figure above Since the range is between 10 C and 25 C the corresponding voltage range from the sensor is between 0 1V and 0 25V respectively The conversion to digital will find the way to match the Setpoint and feedback 5V 2 n n bit 5V 256 20mV bit 5V 1024 gt 5mV bit lt this is a better accuracy Obviously we can quantize the minimum voltage change from the sensor at 10mV C it meets the required reading conversion 0 1V 5mV 20 decimal resolution this is the start edge of the mentioned range 0 25V 5mV 50 decimal resolution this is the end of the range maximum The other way to calculate it 0 1V 5V 1024 20 48 20 decimal resolution 0 25V 5V 1024 51 2 20 decimal resolution a better calculation Mainly to define the analog chain signal in ones and zeros each period of these chains have to be sampled and get its new digital definition The following discrete function shows how the ADC gets the above values it adds each level of these bars that operate in range of 0000000000 to 1111111111 binary levels The figure below defines the analog signal 0 5 Volts which the knob will send to Freeduino to adjust the Setpoint A D Converter Analog Input Samples Figure 8 ADC quantizing function 14 Name Omar Jones Course Electronics Engineering Final year 3 Then the interesting range
10. this project was a suggestion from Dr Goran Bezanov the supervisor of this project at London South Bank University The purpose of this suggestion is to reduce costs and time by using embedded solutions with simple electronics circuits 6 1 List of used Hardware Software Software o IDE Integrated Development Environment Kiel uVision dScope 51 evaluation AVRstudio 4 Arduino Virtual Bread Board simulator o Documentation Microsoft Word Microsoft Excel Smart Draw Paint gt Hardware Atmega328 Freeduino Arduino Atmega328 ADC Resistor 1 x 4 7 k Q Transistor 1 x NPN BJT Thermometer knob 1 X LM35DH Potentiometer 1 x 10k Q Fan 1 x DC motor 12V 0 19A PC box wires amp soldering 23 Name Omar Jones Course Electronics Engineering Final year 3 6 Project Planning A Gantt chart was build to match the requirements and the deadlines GANTT CHART 3 MONTH TIME LINE Final year Project PID Controller March April May Tasks Week 1 Week2 Week3 Week 4 Week I Week2 Week3 Week 4 Week 1 Week 2 Week3 Week 4 Setting Final Project Pre paring Software Keil and references Identifying the problem AA Software tuterial A Report Writing A Z 2 Tr Setting the PID calculations e Making a basic design to the Hardware ELI New Process Writing the code Analyze data a Develop improved process A Hardware desig amp test ZA Hardwar
11. with emphasis on embedded solution using PID control and digital signals to control a DC motor speed Several IDE were used in order to implement the microcontroller Furthermore three different microcontroller of 8051 family have been tested as well The microcontroller will read analog signals from a Temperature sensor as feedback b Potentiometer Knob as Setpoint control The output will be delivered as digital signal in order to control the speed of the DC motor Fan The applied technique of controlling the motor is PWM Puls Width Modulation will adjust the analog device via a transistor The Setpoint input to the microcontroller will be an analogue potentiometer regulator which will set a particular temperature degree in the scale of 10 25 C this could be changed if desired The feedback to the input will be received from a temperature sensor then the PID control will compare the result of both inputs to generate the suitable puls to the fan cooler DC motor This program has been written using Wiring language in Arduino software to load it later to the Freeduino Arduino hardware to run the application Furthermore the hardware part is quite simple to follow which is the purpose of using the embedded system Nevertheless the report will guide the reader through the experimental process of the approaches whereas many issues have formed this project is Name Omar Jones Course Electronics Engineering Final year
12. ATmega328 PWM output pins are totally 6 pins in three pairs These three pairs are divided in this way due the fact that we have 3 prescaler Let s have a look first at the PWM pin numbers in ATmega328 and the corresponding pins in Arduino ATmega328 5 11 12 15 16 17 Arduino 3 5 6 9 10 1 Table2 PWM pin number The reason that the above table mentioned is to explain the code when we are using the Arduino pins numbers Arduino bootloader sets the prescaler and the frequency to the attended pins automatically at start Pin 3 and 11 run on 500Hz frequency when the other pins run on 1kHz www Arduino cc 15 Name Omar Jones Course Electronics Engineering Final year 3 4 1 4 Timer Counter Control register In this case an increment needs to be done to use 10 bit instead of 8 bit There are three TCCR Timer Counter Control Register could be modified to the specific mode and bits in the A channel TCCR n4 Timer Counter Control Register Pin number Arduino TCCROB TCCROA R TCCR1B TCCR1A 9 J0 A TCCR2B TCCR2A Table3 TCCR Its obvious that the change in Timer counter bit quantity effect the frequency so if we want to change it then the prescaler has to be changed TCCR system clock prescaler value The frequency could be changed by changing specific bits in the B channel TCCRnB Controller Registers the bits and Wave Generation Mode to meet the required behavior to pair pairs of pins www
13. Institutionen f r systemteknik Department of Electrical Engineering Examensarbete DESIGN AND DEVELOPMENT OF AN EMBEDDED DC MOTOR CONTROLLER USING A PID ALGORITHM Examensarbete utf rt 1 Elektronik av Omar Jones Omar Jones LiTH IS Y EX 10 4417 SE Link ping 2010 06 15 208 UN QUOS UNI A Po M ah vh 7 IN j e Te E A NG y une TEKNISKA HOGSKOLAN LINKOPINGS UNIVERSITET Department of Electrical Engineering Link ping University S 581 83 Link ping Sweden Link pings tekniska h gskola Institutionen f r systemteknik 581 83 Link ping Name Omar Jones Course Electronics Engineering Final year 3 DESIGN AND DEVELOPMENT OF AN EMBEDDED DC MOTOR CONTROLLER USING A PID ALGORITHM Examensarbete utf rt 1 Elektronik vid Link pings tekniska h gskola London South Bank University av Omar Jones LiTH IS Y EX 10 4417 SE Link ping London 2010 06 15 Handledare Goran Bezanov London South Bank University Examinator Jonny Lindgren Link ping universitet Name Omar Jones Course Electronics Engineering Final year 3 Institution Avdelning Datum 2010 06 15 Division Department Date Division of Electronic Systems Department of Electrical Engineering Link opings universitet SE 581 83 Link ping Sweden Spr k Rapporttyp ISBN Language Report category ISRN LJ Svenska Swedish Licentiatavhandling LiTH ISY EX 10 4417 SE x Engelska English DX Examensarbete Ser
14. ated The PWM Puls Width Modulation in the ATmega328 as automatically calculated whereas a special Pin as used only to calculate the Duty cycle to the output The Arduino software makes it easy to load the code directly to the board via USB and see the result of the PWM However there are lots of similarities due the fact that all of them belong to the 8051 family its possible to edit any of them using c or assembler the timers frequency and registers PCINT14 RESET PC6 O 1 28 O PC5 ADC5S SCL PCINT 13 PCINT16 RXD PDO CI 2 27 O PC4 ADCA SDA PCINT 12 PCINT17 TXD PD1 O03 26 O PC3 ADC3 PCINT11 PCINT18 INTO PD2 O 4 25 1 PC2 ADC2 PCINT10 PCINT19S OC2B INT1 PD3 O 5 24 PC1 ADC1 PCINT9 PCINT20 XCK TO PD4 Q 6 23 I PCO ADCO PCINTS vcc CI 7 22 J GND GND 018 21 O AREF PCINT6 XTAL1 TOSC1 PB6 O 9 20 AVCC PCINT 7 XTAL2 TOSC2 PB7 L 10 19 PB5 SCK PCINT5 PCINT21 OCOB T1 PD5 11 18 L PB4 MISO PCINT4 PCINT22 OCOA AINO PD6 LJ 12 17 O PB3 MOSI OC2A PCINTS3 PCINT23 AIN1 PD7 O 13 16 PB2 SS OC1B PCINT2 PCINTO CLKO ICP1 PBO LJ 14 15 O PB1 OC1A PCINT1 Figure 10 ATmega328 Atmel 19 Name Omar Jones Course Electronics Engineering Final year 3 5 Hardware components The listed hardware components are interfaced with Atmega328 via Freeduino a brief description of wiring each component is listed below 5 1 LM35DH Temperature sensor The IC temperature sensor gives an ana
15. ce and its won performance in this project the regular frequency is used Frequency 1 T so If T 2ms then the frequency is 500Hz There are special pins on the Freeduino PCB for the PWM the new upgrade of the 8051 family such as ATmega8 and ATmega168 ATmega328 include many typical useful features A good and simple example of the Puls Width Modulation if we have a motor which is connected to a switch we can switch it On and Off very fast the speed of switching on and off is equivalent to the period frequency in the PWM Name Omar Jones Course Electronics Engineering Final year 3 So the time that we spend while the switch is On or Off will set the duty cycle apparently if the time is equal on both On and Off will reduce the speed of this motor to 5096 which is the mentioned duty cycle 4 Technical approach The user will be able to manipulate the speed of a DC motor Mainly the speed of the DC motor depends on time for how long this motor will be On Off and set the needed power to be delivered to the fan The PID controller part is responsible of making accurate algorithms depending on the input values errors Before forwarding the signal it must be digitalized and scaled to be implemented in order to process it to the output After the delay calculations have been done the next step is to generate puls chain to the output In the mean time a feedback from the output must be considered to give more accurate result an
16. d of 25 years starting from the date of publication barring exceptional circumstances The online availability of the document implies permanent permission for anyone to read to download or to print out single copies for his hers own use and to use it unchanged for non commercial research and educational purpose Subsequent transfers of copyright cannot revoke this permission All other uses of the document are conditional upon the consent of the copyright owner The publisher has taken technical and administrative measures to assure authenticity security and accessibility According to intellectual property law the author has the right to be mentioned when his her work is accessed as described above and to be protected against infringement For additional information about the Link ping University Electronic Press and its procedures for publication and for assurance of document integrity please refer to its www home page http www ep liu se Omar Jones
17. d to make of it a real closed loop progress The accuracy itself can be determined regarding to the requirements in this project eventually the input signal has been divided into 15 steps degrees therefore the output should be adjusted to give an expected result see the diagram below knob Desired Temperature PID Control Puls Generate ATmega328 Freeduino Arduino DC motor Fan Cooler Heating Source Temperature Sensor Figure 4 Flow chart Name Omar Jones Course Electronics Engineering Final year 3 4 1 1 Software Writing the code of any program to be loaded on a microcontroller could be used of many different IDE Integrated Development Environment programs in this project a couple of these IDE were tested to produce the suitable code At beginning of writing the first code the Keil uVision2 software was used to code and dScope to simulate the program using 8051 microcontroller and C51 compiler Keil uVision software is quite popular when it comes to program 8051 a tutorial of using this program for a relative microcontroller usage was found in Embedded programming for the 80x51 book Dr Goran Bezanov Unfortunately the tutorial was for a previous released version that was not compatible with the operative system Windows7 that installed on my computer to solve this problem Windows XP was installed as a virtual program on Windows7 to run Keil uVision l Windows XP Windows Vir
18. e course amp components order c t __ eg Presentatio Key Dates KEY 53 Setting Final Project 10 5 All data collected 103 Identify problem 12 5 All data analyzed Milestone marker start 263 Intial Report 14 5 Final Report Submitted Expected L4 Preparation Completed 18 5 Final Report Submitted Actual ilestone marker end 3 Milestone marker en 4 4 Start writing the code 174 Hardware part delivered Gantt bar i 7 5 Hardware circuits ompleted Figure 14 Gant Chart The plan and some other additional parts were changed due the fact that a better solution was found though the core of the old plan was held very close to the approached plan Basically almost all the milestones were fulfilled successfully except that the final report was expected to be submitted four days earlier A special edition of this report was edited specifically to follow the Link ping University requirements thus it took a little further time to be submitted 24 Name Omar Jones Course Electronics Engineering Final year 3 7 References 1 G Bezanov Embedded programming for the 80x51 Published by MIG Consulting Ltd London 2008 ISBN 978095581531 7 2 Power Electronics Converters Applications and design 3 Mohan Undeland and Robbins Power Electronics Converters Applications and design published by Wiley ISBN 0 471 50537 4 4 Atmel datasheet 2010 www atmel com dyn
19. ency Thus the PWM frequency has to be adjusted regarding to the used fan typically dc fans operate between 30 150 Hz www freescale com Unfortunately we can t use the full strength of ATmega328 The tests show that 500Hz is fine to run the fan within the accepted margin The used power supply was connected directly to the fan 12V the ground was connected to the transistors output 5 3 Potentiometer Knob 10k O potentiometer is used to control Setpoint level it has three pins that connected to Freeduino The outside pins are connected to 5V and GND it doesn t matter what side Finally the middle pin is the output from the knob to Freeduino pin 1 5 4 BJT Transistor Using BJT transistor or MOSFET won t change the result so the BUT NPN is the used transistor in order to control the fan 3 Pin configuration 1 Emitter 2 Base J 3 Collector 1 Figure 12 BJT Transistor Left BJT NPN Right Between PWM pin and the transistor a resistor was placed to prevent overheating whereas the saturation mode will be different over 25 C www rapidonline com datasheet 21 Name Omar Jones Course Electronics Engineering Final year 3 5 5 The Project Let s put things together the following figure shows the complete system the ground GND from Freeduino should be connected to the 12V power supply Figure 13 The complete project There were many tests to define what was missing in wiring and code thoug
20. erstand real time control aspects of motor control circuits 4 Produce high quality technical report with substantial analytical content The environment of working with the code at beginning was managed with an IDE later on the software ran on hardware components at workshop a Soldering amp Safety course at LSBU was held by the staff Name Omar Jones Course Electronics Engineering Final year 3 Technical Background and Context gt 3 1 PID Proportional Integral Differential A brief demonstration of the PID controllers background which is the most common controller in industry the algorithm of this technique is being used in order to output a better accurate signal regarding to the desired value and to save energy by giving only what the system needs In this closed loop transfer function the input signal to the PID controller is the desired reference value subtracts by the feedback signal from the output which called error The controller receives digital signals and after calculations the signal forwards to be processed see figure 2 r t e t c t y t Control Progress Figure 1 Closed Loop y t The PID analog calculation is shown as following 7 eet ram DO es de t c t Kpe t Ki e T dT Kd EE J0 i Gr P D The figure below shows the standard PID controller it s the same basic procedure of using even the digital version Embedded programming for the 80x51 Dr Goran Bezanov
21. from the sensor readings index analogRead inputPin add the reading to the total total total readings index advance to the next position in the array index index 1 If we re at the end of the array if index gt numReadings wrap around to the beginning index 0 calculate the average average total numReadings delay 100 add a 100ms delay Arduino 2010 functionality As the oop function is a forever loop a delay has to be implemented between calculations and pin reading writing The delay function is a standard function in the Wiring language the regular delay X whereas X is a value in mille second There s another standard delay function calculates in micro second instead as well 12 Name Omar Jones Course Electronics Engineering Final year 3 In fact the ATmega328 offers quite generous precision whereas the A D C is 10 bit converter which is 1024 decimal This precision could be reduced if desired by Wiring language Though the sensor has a lower accuracy than what the Arduino can offer It s about 0 5 C but this if the power voltage to the LM35DH is exactly 5 Volts otherwise this would effects the resolution The fact is that the sensor gets the power from the Freeduino Arduino which is in its turn get the power through USB connection from the PC Normally the power via USB is slightly different less or more than 5Volts this fact won t change t
22. h the fan works fine within an acceptable range in 500Hz from PWM At first when the 1kHz frequency on PWM pin was tested the fan gave a very high frequency noise but no rotation When the frequency decreased to 500Hz the fan worked fine Still an enhancement to the result could be done if we replace the used fan with a better one A couple of transistors and thermometers were fried because of wiring faulty There were short in two places the whole board was replaced with a new one and of course soldering the components again took a place at the workshop as well Checking the small wiring components when unexpected faulty happens is very essential and will save a lot of time The design of how the components are wired could be done in a better way Although the knob for the potentiometer was in the way under trying to put everything in a box to give the hardware a descent looks 22 Name Omar Jones Course Electronics Engineering Final year 3 6 Result The project as final step used Arduino as IDE ATmega328 microcontroller placed on Freeduino with output on pin 3 for PWM which runs on 500Hz Basically the results of each method were explained with relevant details after the concerned steps Mainly the project worked as planned the fan runs regarding to the Setpoint and the sensor feedback The Fan runs very smooth between the different speed levels regarding to the PID implemented values see appendixes The idea of making
23. he results a lot regarding to the requirements In the oop function the current values can be read this is a modified code for illustration sake only The input from the potentiometer or the required temperature has to be scaled as well As the potentiometer gets power from Arduino we have two choices the 3 5 Volts or 5 Volts the used voltage is 5 in this project to get higher voltage per bit oVolts 1023 bit ca 5 mV bit So the range of the values that the program needs to read have to match the same range of the feedback Unless if the required accuracy is high to control very small values Here we have the two choices again of hardware or software solution they are both efficient though To match the same range as the feedback range the Setpoint will be scaled in a way that the values above and beneath this specific range will be treated as following If the temperature is less than 10 C then the fan will stay in waiting mode Off and if the temperature is above 25 C then the fan will run in full speed Otherwise the error will be considered to calculate the fan speed note start motor in figure 7 OW P ee e NPO2woRao 00528990 O0u90o092N802RU093995259E6 Figure 7 Input Output signals 13 Name Omar Jones Course Electronics Engineering Final year 3 The difference between the Setpoint and the feedback which called error has to come to the point to be zero or close to zero at least PID control function will
24. ietitel och serienummer C uppsats Title of series numbering D uppsats Ovrig rapport Titel Kontrol av DC Motor i enbyggda system med hjlp av PID amp PWM Title DESIGN AND DEVELOPMENT OF AN EMBEDDED DC MOTOR CONTROLLER USING A PID ALGORITHM F rfattare Omar Jones Author Sammanfattning Abstract Projektet utf rdes p engelska vid London South Bank University Rapporten syfter p anv ndning av metoder och tekniker som minimerar kostnader och tid Med hj lp av ATmega328 mikrokontroller kan man styra en DC motor i closed loop hantering Nyckelord PID PWM thermometer feedback sensor potentiometer Setpoint Brushless DC Motor AD DA Converter Name Omar Jones Course Electronics Engineering Final year 3 Abstract This project was held at London South Bank University in the UK with corporation with staff from Link ping University in Sweden as Bachelor thesis This report will guide you through the used techniques in order to achieve a successful cooler Fan project with a minimum budget and good energy saving methods The steps of setting the used software and components are supported with figures and diagrams You will find full explanation of the used components and mathematics in additional to a complete working code Name Omar Jones Course Electronics Engineering Final year 3 Summary A PID controller has been used in order to regulate particular closed loop systems Digital implementation
25. log voltage of 10mV C it has 3 pins Vout 2 3 anp 9 Figure 11 LM35DH Left Bottom View Right Its quite easy to wire it the right picture shows a bottom view of it and so if we start clockwise starting from the little metal holder actually it s for the purpose of pointing the pin number one The first pin Vs is for power supply LM35DH takes voltage from 4V to 30V In this project LM35DH takes power from Freeduino Arduino power supply which is 5 volts The second pin Vout can be connected directly to Freeduino pin 0 or via other components to calibrate special temperature range We can even get more accurate temperature by connecting several precision temperatures in series this is the hardware solution Finally the third pin is to ground it should be connected to the Freeduino Arduino ground The accuracy could be increased if the measurements give strange results by covering the legs with aluminum or any shielding method to prevent distortion 20 Name Omar Jones Course Electronics Engineering Final year 3 5 2 Brushless DC motor Fan The used fan in this project was taken from an old PC at the workshop at University Here is a quick review of this fan performance Size Volt Speed Airflow Noise Ampere mm v RPM CFM dB A 12 Table9 Fan A very important aspect that was not considered from the beginning is how fast the dc fan response to the input frequ
26. n t be easy to be observed by naked eyes due the fact that the change of temperature in this specific project won t be in a very big range in a short time However full explanation of the PID controller will be illustrated in the mentioned section A PID controller code was loaded to the microcontroller though the Arduino software makes it possible to use a ready function for the PID controller Name Omar Jones Course Electronics Engineering Final year 3 2 1 Objectives e Become familiar with the 8051 microcontroller family e Designing an embedded system to control hardware components to reduce costs and energy e Using the strength of the C language or a similar language to write an effective code e Writing a technical report 2 2 Deliverables Software o A complete programming code running on Arduino o PID control accurate calculations Hardware o Circuit design amp wiring 3 Documentation o High quality technical final report o Illustration of the stages including the mathematical calculations o User manual to the system the microcontroller and the Thermometer o Program code in C language Wiring language o Logbook Name Omar Jones Course Electronics Engineering Final year 3 2 3 Requirements to Meet Project Aim Objective This project 1 Program in C Wiring for ATmega328 microcontroller 2 Design digital control algorithms and implement closed loop control using PID principles 3 Und
27. of reading from sensor is 50 20 30 or 31 Regarding to the earlier calculation we have 15 steps representing the 15 degrees This means that the analog 15 steps equal 30 digital steps which gives a good rate margin A higher resolution will help to calculate an accurate speed to the fan While reading the Setpoint values in the oop function the operation of scaling will take a little time which requires delay thus the de ay function has to be implemented after each function The minimum limited duty cycle is approximately 12 596 that make the motor runs on the slowest speed The corresponding value in binary 1000 0000 decimal 32 Hex 20 this limitation merely sets by the DC motor Apparently the minimum needed voltage is approximately 0 64V Then the error value increases dramatically to adjust the fan speed by adding this edge value to the error sensor Setpoint The default PWM output pin in ATmega328 provides 8 bit so the full speed takes 255 when the duty cycle is 10096 to supply the fan with 5V When the internal A DC gives 10 bit the ATmega328 provides up to 16 bit to the PWM output pin Output pins are controlled by Timer Counter Control Registers for each two pins there are two of these Timers Counters for channel A and Channel B Each Timer Counter contains of 8 bits to control the behavior of the output pins By setting the proper timer control we can get 10 bit to the PWM output pin as well The
28. ol e EEERPESPPPEE era NER Re ERRARE Function prototype int pid int error ctrl int prev error ctrl 27 Name Omar Jones Course Electronics Engineering Final year 3 void loop Setpoint analogRead setpointPin reading setpoint delay 100 100ms delay Reading temperature average of 10 samples subtract the last reading total total readings index read from the sensor readings index analogRead sensorPin add the reading to the total total total readings index advance to the next position in the array Index index 1 delay 50 50ms delay if we re at the end of the array if index gt numReadings wrap around to the beginning index 0 calculate the average average total numReadings send it to the computer as ASCII digits delay 20 20ms delay Temperature 5b average 100 1024 if average lt 20 if the temperature is too low equal to or less than 10 degrees digitalWrite 13 HIGH turn the blue LED on which is connected to the digital pin 13 out 0 analogWrite PWM Pin out Fan off delay 100 j j else if average gt 52 analogWrite PWM_Pin 255 Fan Full speed it s too hot delay 100 j else otherwise calculate the needed speed tmp analogRead 1 reading setpoint Setpoint tmp 10 delay 100 100ms delay 28 Name Omar Jones Course Electronics Engineering
29. rature in order to limit the range of the required temperature and to make code available to be changed to a different range To get an accurate temperature again we can choose either to put three or more sensors in series or solve it using code 11 Name Omar Jones Course Electronics Engineering Final year 3 Well we shall use code as this project emphasize on it a reading of 10 samples was implemented which can be easily changed to the desired samples quantity The time delay of reading the ten values is the time that the operations inside the for loop takes The array contains ten elements adds a new served value each cycle When the container is full the next cycle will reset it and start adding new values from the beginning So first we read ten times and then get the average temperature This sort of reading has to be declared inside the setup function void setup initialize the variables we re linked to read from sensor LM35DH for int current Reading 0 current Heading lt numReadings current Heading 4 readings current Reading 0 Setpoint analogRead 1 knob 0 5 V pinMode PWM Pin OUTPUT DC motor control The Arduino forum Jones Taking several samples would be more elegant solution than just throw a delay it would work with the delay too but it won t give high accuracy and performance void loop subtract the last reading total total readings index read
30. resources prod_documents doc8271 pdf 2010 05 09 5 IDE new software 2010 WWW arduino cc 2010 05 09 6 Microcontroller circuit packet 2010 www freeduino org 2010 05 09 7 BUT amp Sensors 2010 www alldatasheet com 2010 05 09 8 The Wiring Language functionality 2010 www tem eu 2010 05 09 9 Arduino IDE 2010 www virtualbreadboard com 2010 05 09 10 Freeduino Circuit 2010 www solarbotics com photo 2010 05 09 25 Name Omar Jones 8 Appendex VBB simulator Wiring C Program Code Project pictures building amp operating Course Electronics Engineering Final year 3 File Edit Tools Help ag baa IJD u SEC CS 2 Reape Q amp amp r e l8 9 C c dioe xi VBB gA aj aj Solution MotorKnob Ledi E MotorKnob Sg BreadboardSheet VBB meo z i Source0 SRC mu Led EN LedArray Wm DotMatrixLED8x8 gen D7D amp D5D4D3D2D DO Al am Jump4 ror vv ii Jump8 x E Seg pm OOO OOO OO OOO RV OO 8 F DigitalPot sp NI Lal E NumericKeypad Mi PushButton Y ToggleSwitch Piui KA X1 10 p SlidePOT vi lo _ PanelMeter x2 50 lv2 50 Circuit LS ere ae Stroke black 4 VDD d analgin StrokeWidth 1 vss Fill yellow T Pullup FablD i Pulldown Logic Instrui Il 3n 14 38 SV a a Pr i 1 X S al 0 15 05 2010 Appendex1 VBB Vi
31. rocontroller instead it has a full support to the Atmel microcontroller which means that the library of microcontroller is quite bigger than Keil uVision Name Omar Jones Course Electronics Engineering Final year 3 Finally Arduino open source program was used to code a slightly different code with same functionality as the earlier code However the last used software was the most suitable due the ease of loading the microcontroller that is installed on a compatible hardware 4 1 2 Arduino Arduino Alpha is the new open source production which provides many useful and typical functions The software is always updated to the latest related hardware to make it easier to load the software on the microcontroller and to discover the new features in the new microcontroller A very big library could be found online or even included in the software for some basic functions Its almost the same differences between the C language and C could be represented between Arduino and AVRstudio or Keil uVision although the Arduino was programmed by java The available programming language in this software is Wiring language which is extremely similar to C C My project Arduino 0018 io 2S File Edit Sketch Tools Help Sic Di int setPoint 0 required temperature value int setPointPin 1 required temperature pin int fanPUM Pin 3 int error D int prev error 0 int out 0 double P Gain 1 I Gain 0
32. rtual Bread Board simulator v3 6 0 26 Name Omar Jones Course Electronics Engineering Final year 3 8 2 Code JPR IDIOTIC RII IIIS IIIS I III II IIIA TI III II II III II III II II III II II III III IIIA Final Year Project Title DESIGN AND DEVELOPMENT OF AN EMBEDDED DC MOTOR CONTROLLER USING A PID ALGORITHM Author Omar Jones Course Bachelors Electronics Electrical Engineering Submission date 27th of May 2010 Introduction PID control DC motor control Fan via PWM pin on ATmega328 With setpoint amp sensor Software Arduino Wiring language Hardware Freeduino JED ISIS IIIS IIE II III II III II II III II II III II II III II II III II III II SIA Define Variables we ll be connecting to double Setpoint Input tmp 0 const int numReadings 10 int readings numReadings q the readings from the analog input int index 0 the index of the current reading int total 0 the running total int average 0 the average int Duty_C 0 int error 0 int prev error 0 int out 0 double P Gain 2 I Gain 0 3 D Gain 0 3 PID Coefficients example A O pin numbers int sensorPin 0 int setpointPin 1 int PWM Pin 2 3 void setup initialize the variables we re linked to read from sensor LM35DH for int thisReading 0 thisReading lt numReadings thisReading readings thisReading 0 Setpoint analogRead 1 potentiometer 0 5 V pinMode PWM_Pin OUTPUT DC motor contr
33. s This is only a declaration it has to be declared in a specific way to inform the compiler if it s an OUTPUT or INPUT to inform the pin number and the type Analog or Digital even inside the oop function which is equivalent to main function in the regular programming languages The colored selected phrases are standard reserved commands See the following function declaration void setup initialize the variables we re linked to Inputs 1 sensor analogRead sensorPin read from sensor LM35D 2 setPoint analogHead setPointPin knob 0 5 V Outputs 3 pinMode PWM Pin OUTPUT DC motor control Library functions turn the PID on 4 myPID SetMode AUTO Example on library declaration There are many library files that could be used for different function needs it s also available to download special functions from Arduino homepage but we are going to produce our won code in this project 10 Name Omar Jones Course Electronics Engineering Final year 3 We start reading from the potentiometer set the required temperature on the object that we need to take care of The second Input is the feedback value from the sensor which is a thermometer of LM35DH type Again the first tested temperature sensor was LM335 it works in a very similar way to the used thermometer LM35DH This is a simple comparison between the two tested temperature sensors Calibrate Sensor LM335 10mV Kel
34. s have also been used in many applications to reduce costs and time and to get better results compared with the corresponding analogue solutions The project implements a PID controller using the 8051 family Microcontroller family as a processing element ATmega328 microcontroller will be used in an embedded application so that it will process signal inputs and deliver suitable signal outputs based on a designed and implemented PID control algorithm in IDE Integrated Development Environment Mainly the microcontroller will read from inputs the required temperature and feedback of the current temperature from a thermometer sensor The output will be control the speed of a DC motor which is a fan in this case The speed of the fan controlled via a NPN transistor which in its turn will be driven by chains of digital signals Puls Width Modulation The calculation of the implied output signal is explained regarding theories such as PID and PWM Also a brief illustration of setting Timers Counters of the intended 8051 microcontroller family is included Name Omar Jones Course Electronics Engineering Final year 3 Index NE odisse T 1 UA om CTTT M 2 ZNESUILeD Tm 3 ZW ADUENTU ETT 3 ZO sisse inici E TIDETUR 4 Technical Background and Context ome 5 OMA uil E 6 S EC di sia trit t ED 7 SN NL uc CETT
35. tual PC 3 Windows XP Windows Virtual PC o 5 ml Action v Tools v Ctrl Alt Del e Ctrl Alt Del C pVision 51 evaluation FANPRO PRJ DUTYC C Hj File Edit Project BST Options Tools Window Help Action v Tools Nu 3 B 6 B 0 dScope Debugger N ES ESI EE e FAI EJETYEEJ SIE ES lol Ro 00 Rizo PC lint Diagnostic Facility R2 00 R3 0 R4 03 R5 E R6 00 R 6 DPTR 430 Parallel Port 1 Go Port 1 7 Bits 0 5502 GoTiicus PEF PEAKE 502 Steplnto Pins OFF jzivivIviviviviv StepO ver Close StepOut Stop View 3 ftinclude lt reg51 RDK include lt math h 77 rogram itdefine F CPU Application Manager tinclude lt util delay h gt TST A C fidefine Delaytus FER fidefine output P3 fidefine input P8 ES unsigned short int x 8 y 8 global variabls unsigned short int zero 8 88 tmpON 6 tmpOFF 8 milli 8 881 m wosa s ner Ex Port 0 7 Bits 0 PO OxFF yv iviviv iv iv iv Pins OxFF jv jv jv jv jV Iv IV IV Close xxxxxxxxPID Function unsigned long int PID Func int error int prev error PID calculat i unsigned short int Kp 1 Ki 1 Kd 1 P 8 I 8 D 8 pid out 8 if error gt 8 amp amp error lt 255 4 P Kp error I Ki error milli D Kd error preu error nilli pid out P I D H Port 3 TG S i ns P3 FEREETET Vv Pins 10x00 FEET IV
36. uency that the mode will run on CS12 CS11 CS10 0 J J ji t X 684 J jtfkHz O Table7 TCCROB Frequency The selected frequency is the default frequency from the bootloader in case the wanted frequency is 1kHz then no need for changing anything in case we need this particular frequency www alldatasheet com The only limitation in this program that caused a faulty on the fan behavior is the fan switching frequency In fact 8 bit output to the PWM pin is more than enough to operate this fan so the fan can t run on a higher frequency than its own frequency The solution is to run the fan in 8 bit from pin 3 that operates on 500Hz 17 Name Omar Jones Course Electronics Engineering Final year 3 4 2 1 Hardware Core In this section we will go through the PCB that ATmega328 installed on and a comparison between three of 8051 family those were used in order to achieve this project 4 2 2 Freeduino SB 2 2 Freeduino is an upgrade of open source hardware which is available to everyone to edit enhance share and sell This kit is uses 16MHz SMD crystal which is ATmega328 clock and can deliver up to 500mA which can be integrated with power supply to deliver up to 1A The hardware compatibility with different operative systems such as Windows Linux and Mac make of it a very useful and popular product In fact it s made to be used for motors LEDs and temperature control projects Its supplied with PC s
37. uitable functionality The output of programs could be tested on the LEDs www freeduino org Basically Freeduino Arduino provides the capability of the installed microcontroller and makes it easy to reach the pins of it to interface with external parts Nevertheless the price is quite low in additional to all the tiny parts are soldered on the PCB the picture below shows the used l O pins and the other main hardware functions Figure 9 Freeduino SB v2 2 18 Name Omar Jones Course Electronics Engineering Final year 3 4 2 3 ATmega328 and 8051 Family Mainly the use of the ATmegaX will give as good result as the 8051 With help of AVR Studio 4 software we can simulate the C code for ATmega8 which is equivalent to Keil uVision and Arduino using ATmega328 Here s a very brief technical comparison betweenA I mega328 ATmega8 and 8051 in this project Microcontroller ATmega328 ATmega8 8051 10 bit 8 bit 8 bit Automatic Automatic Timers declaration Automatic editable Automatic editable C code manual Frequent used IDE AVRstudio project Table8 8051 family The A D Converter component communicate with the 8051 via PO Port which offers 8 pins furthermore this interface enables a flag informing the 8051 that the packet has been transferred Embedded Programming for the 80x51 Dr Goran Bezanov The cost could be reduced by using the ATmega328 instead whereas the external A D Converter will be elimin
38. vin 40 C to 100 C LM35DH 10mV C Centigrade Table1 Precision Temperature sensors The first sensor LM335 was replaced with LM35DH because it starts within a closer temperature range to the required one in this project and it gives result in Celsius Centigrade as well Now we don t have to scale the input from the sensor which it goes in the following way Celsius power supply voltage input from sensor 100 273 15 2 10 Values that the LM35DH sensor returns are 10mV C degree This means that first we have to multiply it with 100 to reach 1 C So if we need to set a specific temperature we use this Celsius power supply voltage input from sensor 100 2 10 Let s set some temperature degrees 10 C 5 input from sensor 100 1024 Input from sensor 20 48 gt 20 decimal 20 C 40 decimal 25 C 51 decimal 10 C is the minimum or the lowest degree that used in the program 25 C is the maximum or the highest degree in this program In these 15 degrees steps we get 15 different voltages To get a linear relationship between the temperature degrees and the input voltage starting from this point we have to calibrate the output from the sensor using hardware in fact two resistors Instead of adding more hardware we can scale the input in program as we have already calculated the responding values of the minimum and maximum temperature Its quite essential to convert the current tempe
Download Pdf Manuals
Related Search
fulltext01 fulltext01.pdf fulltext01.pdf diva-portal.org fulltext01.pdf diva-portal.se
Related Contents
WO 2012/111772 A 1 Samsung S19A450BW Hướng dẫn sử dụng 取扱説明書ダウンロード かんたんスタートガイド ダウンロード(4MB) BC OnLine Deposit Account System User's Guide for Applying Samsung RL38HGPS2 fridge-freezer SonicWALL Email Security 7.0 8000 Security Camera User Manual DOCUMENTATION GSAC hussman IGSV-ASCS-0303 User's Manual TP-Link Archer D9 Quick Installation Guide Copyright © All rights reserved.
Failed to retrieve file