Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Display a temperature

Status
Not open for further replies.

radialspel

New Member
Hello!!

Om working on a project where i'm reading 8 diffrent temperatures and display them on a 2x16 LCD display.

The microcontroller i use have 10-bit ADC and the result of a read is somewhere between 0x000 to 0x3FF. How do i convert from hex to decimal?? It's no use that it for example stands: Temp1: 0x28E on the display.. I'm using the CC5X C-compiler
 
radialspel said:
Hello!!

Om working on a project where i'm reading 8 diffrent temperatures and display them on a 2x16 LCD display.

The microcontroller i use have 10-bit ADC and the result of a read is somewhere between 0x000 to 0x3FF. How do i convert from hex to decimal?? It's no use that it for example stands: Temp1: 0x28E on the display.. I'm using the CC5X C-compiler

I can't help you with C, but there's plenty of assembler routines on the PIClist.
 
Where in the code does it form the string? C does the conversions. You just change from "%x" to "%d".

sprintf(lineBuf, "TEMP: 0x%2x",temp);
sprintf(lineBuf, "TEMP: %3d", temp);
 
You need to scale the result first. The AD will output 0 at the lowest temperature and 0x3FF at the highest temperature. To let the result make any sense you would need to know exactly how big these minimums and maximums are...

For example :
Output of 0 - 0°C
Output of 0x3FF - 200°C..

-> 1 unit of the A/D's output then represents: 200°C / 0x3FFF = 0,1955...
Now multiply this number with the result from the AD and you know the temperature in degrees...

For example an AD output of 1C2 would be: 1C2 * 0,1955 = 87,875°C...
This result can be printed in C using the formatting routines in sprintf() like mentioned above

So, you should first figure out the relation between the A/D's output and the actual temperature so you know what the minimums and maximums are
 
Actually, you're going to start with a 16 bit unsigned integer. So the efficient way to handle it:
0x03ff/0xFFFF = 2^6, so to avoid integer division prolems, bit shift <<6 to the left.

So, if 0x00=0C and 0xFF=200C, now you use a divisor of 328, which works better.

unsigned int temp=(getADC()<<6)/328;
unsigned char linebuf[16];

sprintf(lineBuf, "TEMP: %3d", temp);
printLCD(linebuf);
 
Oznog said:
Actually, you're going to start with a 16 bit unsigned integer. So the efficient way to handle it:
0x03ff/0xFFFF = 2^6, so to avoid integer division prolems, bit shift <<6 to the left.

So, if 0x00=0C and 0xFF=200C, now you use a divisor of 328, which works better.

unsigned int temp=(getADC()<<6)/328;
unsigned char linebuf[16];

sprintf(lineBuf, "TEMP: %3d", temp);
printLCD(linebuf);

Most microcontrollers allow you to select right or left alignment of the result. If you choose left alignment you will get a 10 bit result with the upper 6 bits set to 0, so you don't have to shift or 'AND' anything
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top