Interface_project
Interface_project
Group Members ID No
1. Bezawit Berhane UGR/3912/13
2. Ami Birhanu UGR/9923/13
3. Amin Geleto UGR/5191/13
4. Getaw Yeha UGR/1867/13
5. Selamawit Dache UGR/7203/13
List of Figures II
Abstract 2
Introduction 3
Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
System Design 5
Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
LPC2148 Microcontroller . . . . . . . . . . . . . . . . . . . . . 5
Temperature Sensor(LM35) . . . . . . . . . . . . . . . . . . . 6
Display Unit(LCD display) . . . . . . . . . . . . . . . . . . . . 7
Relay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
DC motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Microcontroller Configuration . . . . . . . . . . . . . . . . . . . . . 7
Software Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Software Implementation 9
Programming Environment . . . . . . . . . . . . . . . . . . . . . . 9
Code Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Simulation in Proteus 14
Simulation Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Simulation Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Discussion 18
System Performance . . . . . . . . . . . . . . . . . . . . . . . . . . 18
I
Conclusion 20
Future Improvements . . . . . . . . . . . . . . . . . . . . . . . . . . 20
References 22
Appendix 23
II
List of Figures
1
Abstract
This project involves the design and simulation of a temperature control sys-
tem using the LPC2148 microcontroller. The system is simulated in Proteus,
a software tool that allows for virtual testing of microcontroller-based sys-
tems. The objectives, methods, results, and conclusions of the project are
presented in this report.
2
Introduction
Background
Temperature control systems are essential in various applications, ranging
from industrial processes to household appliances. These systems maintain
desired temperature levels to ensure safety, efficiency, and comfort. In indus-
trial settings, precise temperature control can improve product quality and
process efficiency, while in residential environments, it enhances comfort and
reduces energy consumption.
Microcontroller-based systems are at the heart of many modern tempera-
ture control applications. Microcontrollers offer a compact, cost-effective so-
lution for implementing control algorithms and interfacing with sensors and
actuators. The LPC2148 microcontroller, in particular, is a popular choice
due to its powerful features, including a 32-bit ARM7TDMI-S core, multiple
analog-to-digital converters (ADC), and numerous input/output (I/O) ports.
These features make it well-suited for real-time control applications such as
temperature regulation.
Proteus is a versatile simulation tool that allows designers to create and
test embedded systems in a virtual environment. Using Proteus, developers
can prototype and debug their designs before moving to physical hardware,
saving time and resources. This project leverages Proteus to simulate a
temperature control system based on the LPC2148 microcontroller, enabling
thorough testing and validation of the control algorithms and system behav-
ior.
Existing temperature control technologies employ various methods, such
as on/off control, proportional-integral-derivative (PID) control, and model
predictive control. While effective, these methods can face challenges such as
overshooting, lag, and stability issues, especially in dynamic environments.
This project aims to address some of these challenges by implementing an ef-
ficient and reliable temperature control system using modern microcontroller
technology.
In today’s rapidly advancing technological landscape, the demand for
3
smarter, more efficient control systems is increasing. This project aligns
with current trends by integrating advanced control algorithms and utilizing
simulation tools to optimize system performance. The insights gained from
this project can contribute to the development of more sophisticated and
robust temperature control solutions in the future.
Objective
The primary objective of this project is to design and simulate a tempera-
ture control system using the LPC2148 microcontroller. The system aims to
maintain a specified temperature within a given environment by reading tem-
perature data from a sensor, and activating appropriate actuators to adjust
the temperature as needed. The specific objectives are as follows:
4
System Design
Block Diagram
Components
LPC2148 Microcontroller
The LPC2148 microcontroller is a versatile and powerful member of the
LPC2000 series from NXP, designed for embedded applications requiring
high performance and low power consumption. The following key compo-
nents within LPC2148 were used for the temperature control system in this
project:
Analog-to-Digital Converter (ADC): The 10-bit ADC with 14
channels allows for accurate and high-resolution reading of analog sig-
5
nals from temperature sensors, crucial for precise temperature moni-
toring and control.
Temperature Sensor(LM35)
The LM35 is a popular integrated circuit (IC) used for measuring temper-
ature. The LM35 is an analog temperature sensor. It produces a voltage
output that is directly proportional to the Celsius temperature it’s sensing.
The scale factor is a constant 10mV per degree Celsius. This means for every
1°C rise in temperature, the output voltage increases by 10mV. This linear
relationship allows for straightforward conversion of voltage to temperature.
The LM35 operates over a wide temperature range, typically from -55°C to
150°C. As its output is analog voltage, it can be interfaced with LPC2148
using ADC.
6
Display Unit(LCD display)
An LCD is a flat-panel display that uses liquid crystals to produce images.
16 × 2 LCD was used for this project. It role within the project is to display
the current temperature and show whether it is above, the same as or below
the limit set.
Relay
A relay is an electrically operated switch. It consists of a set of input termi-
nals for a single or multiple control signals, and a set of operating contact
terminals. The switch may have any number of contacts in multiple contact
forms, such as make contacts, break contacts, or combinations thereof. Its
role within the project is to turn DC motor on and off based on the sensed
temperature. It is also connected to LED.
DC motor
A DC motor is an electrical motor that uses direct current (DC) to produce
mechanical force. It was used within the project to simulate fan. It is
connected to the relay.
LED
As it is not possible to simulate heater in proteus, LED was used to show
more clearly if the temperature control system was working fine.
Microcontroller Configuration
1. ADC settings
AD0 was selected as ADC. Hence the settings made are for AD0.
7
AD0GDR was used to check the completion of conversion. The
DONE bit will be set once the conversion is over.
AD0GDR was used to read the 10-bit A/D value.
2. GPIO configurations
The GPIO pins were used to interface with relay and LCD display.
LCD RS, RW and E pins were connected to P1.16,P1.17 and P1.18
respectively. The data pins D0 to D7 were connected to P1.24 to P1.31.
The two relays were connected to P0.22 and P0.23.
Software Architecture
1. initialize LCD
4. while(1)
11. turn on the led simulating the heater and display low temperature
12. else
13. display normal temperature and turn both fan and led off
8
Software Implementation
Programming Environment
The development and implementation of the temperature control system
were carried out using the Keil µVision integrated development environment
(IDE). Keil provides a comprehensive suite of tools for ARM microcontroller
development, including an editor, compiler, and debugger. These tools facil-
itated efficient coding and debugging processes for the LPC2148 microcon-
troller. The IDE’s robust support for ARM architecture and its seamless
integration with the hardware allowed for precise control over the system
components. The use of Keil significantly streamlined the development work-
flow, enabling rapid prototyping and testing of the temperature control logic.
Additionally, Keil’s simulation capabilities provided a reliable platform for
validating the system’s performance before deployment, ensuring a stable
and functional implementation.
Code Structure
Functions within the code
1. LCD.H
void LCD_CMD(unsigned char cmd){
IO1PIN = ((IO1PIN & 0x00FFFFFF) | (cmd << 24));
delay(2);
IO1SET |= (1<<18);// enable = 1
IO1CLR |= (1<<16)|(1<<17);
delay(2);
IO1CLR |= (1<<18); // enable = 0
delay(5);
}
9
The LCD CMD function is used to send command to the LCD which
is useful for initialization of the LCD and setting cursor position at any
time to display.
void LCD_WRITE(unsigned char* data){
unsigned int k=0;
while(data[k]!=0){
The LCD WRITE function is used to display any character array. This
function is used to display the ambient temperature.
void LCD_INIT(){
IO1DIR |= 0xFF070000;
//delay(10);
LCD_CMD(0X38);
LCD_CMD(0X0C);
LCD_CMD(0X06);
LCD_CMD(0X01);
LCD_CMD(0X80);
}
The LCD INIT function is used to initialize the LCD. It sets the LCD to
8-bit, auto-increments the cursor, clears the screen and sets the cursor
position to top left.
2. ADC.H
unsigned int GET_ADC_DATA(void){
unsigned int mydata;
unsigned int v;
float v1;
PINSEL0 |= 0x000000300;
AD0CR = 0x00;
AD0CR |= (1<<6) | (13<<8) | (1<<16) | (1<<21);
10
AD0CR |=(1<<24);
//check end of conversion
while((AD0GDR&(1<<31))==0);//check for done bit
mydata = AD0GDR;
mydata = mydata>>6;//ADC result avialable from 15:6
mydata&=0x3FF;
v1 =((float)mydata*3.3)/1024;
v = (int)(v1*1000);
v = ((int)v/10);
return v;
}
The function GET ADC DATA is used to get the sensed temperature
from LM35.
3. CLOCK INIT.H
void PLL_INIT(void){
PLL0CON = 0X01; // enable PLL
PLL0CFG = 0x24; // set CCLK to 69MHz
PLL0FEED = 0xAA; // feed sequence
PLL0FEED = 0x55;
while((PLL0STAT&(1<<10))==0); // Check whether CCO
latched
PLL0CON = 0x03; // enable and connect PLL
PLL0FEED = 0xAA; // feed sequence
PLL0FEED = 0x55;
VPBDIV = 0x00; //PCLK = 1/4 CCLK;
}
The function PLL INIT is used to initialize the clock. PLLk was set
to 1/4 of CCLK.
void ms_delay(unsigned int ms){
//using timer 0
T0CTCR = 0x00; // set as timer
T0PR = 60000-1; // define PR
T0TC = 0; // reset timer
T0TCR = 0x01; // enable timer
while(T0TC < ms);
T0TCR = 0x00; // disable timer
11
The function ms delay is used to provide delay in ms. It accepts input
in ms and provides delay.
4. Main.c
#include <LPC214X.H>
#include <stdio.h>
#include <CLOCK_INIT.h>
#include <UART.H> // TXD0 RXD0
#include <LCD.H> //RS=P1.16 RW=P1.17 E=P1.18 D0-D7=P1.24 -
P1.31
#include <ADC.H> //ADC PIN = AD0.6/P0.4
void LCD_STATE(unsigned int T);
unsigned int TEMP_LIMIT;
int main(void){
unsigned char *str;
unsigned int temp;
char val[10];
int ADC_val;
TEMP_LIMIT = 35;
PLL_INIT();
LCD_INIT();
LCD_CMD(0x0C);
LCD_CMD(0x80);
LCD_WRITE("Temperature=");
IO0DIR |= 0xC00000;
while(1){
temp = GET_ADC_DATA();
LCD_CMD(0x8C);
sprintf(str,"%iC",temp);
LCD_WRITE(str);
LCD_CMD(0xC0);
LCD_STATE(temp);
}
}
void LCD_STATE(unsigned int T){
if ( T > (TEMP_LIMIT)) {
IO0SET = 0x800000;
LCD_WRITE("HIGH TEMP ");
}
else if(T < (TEMP_LIMIT)){
IO0SET = 0x400000;
LCD_WRITE("LOW TEMP ");
}
12
else {
IO0CLR = 0xC00000;
LCD_WRITE("NORMAL TEMP");
}
}
13
Simulation in Proteus
Simulation Setup
LPC2138, LCD display, LM35, relay, DC motor and LED was added to
scheme.
The Vss pins of the LPC2138 were connected to ground. VREF, V3A,
V3 pins were connected to 3.3V power.
The RS, RW and E pins were connected to P1.16, P1.17 and P1.18 re-
spectively. The pins D0 to D7 were connected to P1.24 to P1.31.
Pin 1 of LM35 was connected to 5V DC source and pin 3 was connected
to ground. Pin 2 was connected to P0.4.
Two relays were used. They were connected to the ground and 3.3V
source as shown in the figure. They were also connected to pins P0.22 an
P0.23. DC motor and LED were connected to the each relay.
14
Simulation Diagram
15
Testing and Results
16
Figure 4: Result of test at T > TEMP LIMIT
17
Discussion
System Performance
The system demonstrates reliable performance in maintaining the desired
temperature range. The use of relays to control the LED and motor pro-
vides a clear and immediate response to temperature changes. This ensures
that the environment remains within the specified limits, thereby preventing
potential damage or inefficiencies caused by extreme temperatures.
Advantages
Real-time Monitoring: The continuous temperature monitoring al-
lows for immediate detection of any deviations from the desired range.
18
Automated Control: The automated activation of the LED and
motor relays eliminates the need for manual intervention, enhancing
the system’s efficiency and reliability.
19
Conclusion
Future Improvements
For further improvements to the temperature control system, several en-
hancements could be considered:
20
Advanced Control Algorithms:
Energy Efficiency:
Extended Functionality:
21
References
[1–7]
22
Appendix
23
k++;
}
}
void LCD_INIT(){
IO1DIR |= 0xFF070000;
//delay(10);
LCD_CMD(0X38);
LCD_CMD(0X0C);
LCD_CMD(0X06);
LCD_CMD(0X01);
LCD_CMD(0X80);
}
// ADC.h
unsigned int GET_ADC_DATA(void);
unsigned int GET_ADC_DATA(void){
unsigned int mydata;
unsigned int v;
float v1;
PINSEL0 |= 0x000000300;
AD0CR = 0x00;
AD0CR |= (1<<6) | (13<<8) | (1<<16) | (1<<21);
AD0CR |=(1<<24);
//check end of conversion
while((AD0GDR&(1<<31))==0);//check for done bit
mydata = AD0GDR;
mydata = mydata>>6;//ADC result avialable from 15:6
mydata&=0x3FF;
v1 =((float)mydata*3.3)/1024;
v = (int)(v1*1000);
v = ((int)v/10);
return v;
}
// CLOCK_INIT.H
void PLL_INIT(void);
void ms_delay(unsigned int ms);
void PLL_INIT(void){
PLL0CON = 0X01; // enable PLL
PLL0CFG = 0x24; // set CCLK to 69MHz
PLL0FEED = 0xAA; // feed sequence
PLL0FEED = 0x55;
while((PLL0STAT&(1<<10))==0); // Check whether CCO latched
PLL0CON = 0x03; // enable and connect PLL
PLL0FEED = 0xAA; // feed sequence
24
PLL0FEED = 0x55;
VPBDIV = 0x00; //PCLK = 1/4 CCLK;
}
void ms_delay(unsigned int ms){
//using timer 0
T0CTCR = 0x00; // set as timer
T0PR = 60000-1; // define PR
T0TC = 0; // reset timer
T0TCR = 0x01; // enable timer
while(T0TC < ms);
T0TCR = 0x00; // disable timer
}
//MAIN.C
#include <LPC214X.H>
#include <stdio.h>
#include <CLOCK_INIT.h>
#include <UART.H> // TXD0 RXD0
#include <LCD.H> //RS=P1.16 RW=P1.17 E=P1.18 D0-D7=P1.24 -
P1.31
#include <ADC.H> //ADC PIN = AD0.6/P0.4
void LCD_STATE(unsigned int T);
unsigned int TEMP_LIMIT;
int main(void){
unsigned char *str;
unsigned int temp;
char val[10];
int ADC_val;
TEMP_LIMIT = 35;
PLL_INIT();
LCD_INIT();
LCD_CMD(0x0C);
LCD_CMD(0x80);
LCD_WRITE("Temperature=");
IO0DIR |= 0xC00000;
while(1){
temp = GET_ADC_DATA();
LCD_CMD(0x8C);
sprintf(str,"%iC",temp);
LCD_WRITE(str);
LCD_CMD(0xC0);
LCD_STATE(temp);
}
25
}
void LCD_STATE(unsigned int T){
if ( T > (TEMP_LIMIT)) {
IO0SET = 0x800000;
LCD_WRITE("HIGH TEMP ");
}
else if(T < (TEMP_LIMIT)){
IO0SET = 0x400000;
LCD_WRITE("LOW TEMP ");
}
else {
IO0CLR = 0xC00000;
LCD_WRITE("NORMAL TEMP");
}
}
26