ARM LPC2129 Mini Development Board – Temperature Sensor Interfacing(ADC)
The “LPC2129 Interfacing Temperature Sensor” wiki discussed here is in reference to the rhydoLABZ make LPC2129 Development Board-Mini, however it makes no difference even if the board used is either LPC2138 Development Board-Mini or LPC2148 Development Board-Mini.i.e, this interfacing guide is common for LPC2129/LPC2138/LPC2148 Mini Development Boards from rhydoLABZ.The LPC2129 Development Board – Mini has on board temperature sensor MCP9700, here in this section we discuss the interfacing of the same with its host controller LPC2129. LPC2129 has two 10-bit successive approximation ADCs. ADC0 has 6 channels & ADC1 has 8 channels. The maximum possible input to ADC is 3.3V which gives output reading as 1023 (The maximum value that can be represented in 10 bits), and thus the resolution is 3.3V/1023=3.22 mV.
On the Mini Development Board the temperature sensor MCP9700 is connected to pin P0.28 of the controller i.e, AD0.1 via jumper J11. The MCP9700/9700A and MCP9701/9701A family of Linear Active Thermistor™ Integrated Circuit (IC) is an analog temperature sensor that converts temperature to analog voltage. It has an accuracy of ±2°C from 0°C to +70°C (MCP9700A/9701A) ±4°C from 0°C to +70°C (MCP9700/9701) while consuming 6µA (typical) of operating current. Sensitivity is 10mV/°C. At 0°C, the output is 500mV. So that’s the spec and description for MCP9700, now lets see its actual working here below.
Schematic:
The figure above shows the MCP9700 provided on the LPC2129 Mini Development Board. And the sample code for reading the values from it is given below. To use temperature sensor, don’t forget to short jumper J11. Leaving it open frees P0.28 and it can be used for any other desired purpose.
Sample Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
/******************************************************************************** HEADER FILES ********************************************************************************/ #include<lpc21xx.h> #define RS 0x00020000 /* RS - P1.17 */ #define RW 0X00040000 /* R/W - P1.18 */ #define EN 0X00080000 /* E - P1.19 */ #define CLR 0X00FE0000 unsigned int adc_value=0; /******************************************************************************** * Function : Delay * * * * Description : Function for Delay * * * * Parameters : x - Delay time * ********************************************************************************/ int Delay(unsigned int x) { x=x*12000; while(x!=0) { x--; } return 0; } /******************************************************************************** * Function : LCD_Command * * * * Description : Function to give command to LCD * * * * Parameters : command - command * ********************************************************************************/ void LCD_Command(char command) { int Temp; IO1CLR = CLR; /* Clearing the port pins */ IO1SET = EN; /* Enable pin high */ IO1CLR = RS; /* RS=0 for command register */ IO1CLR = RW; /* R/W=0 for write */ Temp = (command & 0xF0) << 16; /* Taking the first nibble of command */ IO1SET = IO1SET | Temp; /* Writing it to data line */ Delay(2); IO1CLR = EN; /* Enable pin low to give H-L pulse */ } /******************************************************************************** * Function : LCD_Command1 * * * * Description : Function to give command to LCD * * * * Parameters : command1 - command * ********************************************************************************/ void LCD_Command1(char command1) { int Temp; IO1CLR = CLR; /* Clearing the port pins */ IO1SET = EN; /* Enable pin high */ IO1CLR = RS; /* RS=0 for command register */ IO1CLR = RW; /* R/W=0 for write */ Temp = (command1 & 0xF0) << 16; /* Taking the first nibble of command */ IO1SET = IO1SET | Temp; /* Writing it to data line */ Delay(2); IO1CLR = EN; /* Enable pin low to give H-L pulse */ IO1CLR = CLR; /* Clearing the port pins */ IO1SET = EN; /* Enable pin high */ IO1CLR = RS; /* RS=0 for command register */ IO1CLR = RW; /* R/W=0 for write */ Temp = (command1 & 0x0F) << 20; /* Taking the second nibble of command */ IO1SET = IO1SET | Temp; /* Writing it to data line */ Delay(2); IO1CLR = EN; /* Enable pin low to give H-L pulse */ } /******************************************************************************** * Function : LCD_Data * * * * Description : Function to give data for displayto LCD * * * * Parameters : data - data * ********************************************************************************/ void LCD_Data(char data) { int Temp; IO1CLR = CLR; /* Clearing the port pins */ IO1SET = EN; /* Enable pin high */ IO1SET = RS; /* RS=1 for data register */ IO1CLR = RW; /* R/W=0 for write */ Temp = (data & 0xF0) << 16; /* Taking the first nibble of command */ IO1SET = IO1SET | Temp; /* Writing it to data line */ Delay(2); IO1CLR = EN; /* Enable pin low to give H-L pulse */ IO1CLR = CLR; /* Clearing the port pins */ IO1SET = EN; /* Enable pin high */ IO1SET = RS; /* RS=1 for data register */ IO1CLR = RW; /* R/W=0 for write */ Temp = (data & 0x0F)<<20; /* Taking the second nibble of command */ IO1SET = IO1SET | Temp; /* Writing it to data line */ Delay(2); IO1CLR = EN; /* Enable pin low to give H-L pulse */ } /******************************************************************************** * Function : LCD_String * * * * Description : Function to display string on LCD * * * * Parameters : String to be displayed * ********************************************************************************/ void LCD_String(unsigned char *dat) { while(*dat!='\0') /* Check for termination character */ { LCD_Data(*dat); /* Display the character on LCD */ dat++; /* Increment the pointer */ } } /******************************************************************************** * Function : LCD_Init * * * * Description : Function to initialise LCD * * * * Parameters : None * ********************************************************************************/ void LCD_Init(void) { Delay(15); LCD_Command(0x30); Delay(10); LCD_Command(0x30); Delay(5); LCD_Command(0x30); LCD_Command(0x20); LCD_Command1(0x28); LCD_Command1(0x01); /* Clear display */ LCD_Command1(0x06); /* Auto increment */ LCD_Command1(0x0C); /* Cursor off */ }/******************************************************************************* * Function : ADC_Conversion * * * * Description : Function to get ADC reading * * * * Parameters : None * ********************************************************************************/ int ADC_Conversion() { int ab; /* Variable to store ADC value */ Delay(1); ADCR = ADCR|0x01000000; /* Start conversion */ while((ADDR&0x80000000)!=0x80000000); /* Wait here till conversion is over */ ab = (ADDR&0x0000FFC0); /* Extracting the result */ ab = (ab>>6); /* Shift 6 bits right */ return ab; /* Return the result */ } /******************************************************************************** * Function : Int_ASCII * * * * Description : Function to store integer value in array * * * * Parameters : value - value to be stored * * * cnt - no: of digits * ********************************************************************************/ void Int_ASCII(int value,char cnt) { int i = 0; /* Local variables */ char array[7]; int values; values= value; for(i=1;i<=cnt;i++) /* Store the received value in array */ { array[i] = values%10; values = values/10; } for(i=cnt;i>=1;i--) /* Display it on LCD */ { LCD_Data(array[i]+'0'); } } /******************************************************************************** * Function : Sensor_Check * * * * Description : Function to take ADC reading & display it on LCD * * * * Parameters : None * ********************************************************************************/ void Sensor_Check() { ADCR=0x00200602; /* PDN=1,CLKDIV=6,channel=AD0.2 */ LCD_Command1(0x80); LCD_String("Sensor Checking...."); LCD_Command1(0xC0); LCD_String("Temp:"); adc_value=ADC_Conversion(); /* Get the result of conversion */ adc_value=((adc_value*3.22)-500); adc_value=(adc_value/10); LCD_Command1(0xC4); /* 2nd row, 5th location */ Int_ASCII(adc_value,2); /* Display the result on LCD */ } /******************************************************************************** * Function : PORT_Initial * * * * Description : Function for PORT Initialisation * * * * Parameters : None * ********************************************************************************/ void PORT_Initial(void) { IO1DIR = 0x00FE0000; /* LCD pins set as o/p */ PINSEL0 = 0x00000000; PINSEL1 = 0x05000000; /* ADC function for 0.28 & 0.29 */ PINSEL2 = 0x00000000; } /******************************************************************************** MAIN FUNCTION ********************************************************************************/ int main() { PORT_Initial(); /* Initialise the ports */ LCD_Init(); /* Initialise LCD */ LCD_String("Rhydo Technology"); LCD_Command1(0xC0); /* 2nd row, 1st location */ LCD_String(" Cochin "); LCD_Command1(0x80); /* 1st row, 1st location */ LCD_String("Sensor Checking."); LCD_Command1(0x01); /* Clear screen */ while(1) { Sensor_Check(); /* Take ADC reading */ } } |
Once the above code is loaded on to the controller, it starts reading the temperature values and the same will be displayed on the LCD module as shown in the image below.Topics related to ARM LPC2129 Mini Development Board:
- ARM LPC2129 Mini Development Board – Overview
- ARM LPC2129 Mini Development Board – LED Interfacing
- ARM LPC2129 Mini Development Board – LCD Interfacing
- ARM LPC2129 Mini Development Board – UART0 Interfacing
- ARM LPC2129 Mini Development Board – UART1 Interfacing
- ARM LPC2129 Mini Development Board – Switches Interfacing
- ARM LPC2129 Mini Development Board – BUZZER Interfacing
- ARM LPC2129 Mini Development Board – POT Interfacing (ADC)
- ARM LPC2129 Mini Development Board – Temperature Sensor Interfacing(ADC)
- ARM LPC2129 Mini Development Board – Interfacing Servo motor
- ARM LPC2129 Mini Development Board – CAN Interfacing
Resources:
- Softwares
How to buy:
- Click here to buy rhydoLABZ ARM LPC2138 Mini Development Board
- Click here to buy rhydoLABZ ARM LPC2148 Mini Development Board
- Click here to buy rhydoLABZ ARM LPC2129 Mini Development Board
Support:
Please share your ideas with us, visit our forum for discussion