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.

lookuptable help

Status
Not open for further replies.
thermisor value is calucte using data from the datasheet

resistance =12k at 25 degree(according to datasheet
thermistor value=resitance at 25* Rt/R25
i dont know its correct or not
for example 12k*1.9=2280 (resistance at 10 degree according to datasheet).this is how i calculated.
as this is my first design and program ,iam totally a beginner in this field.
 
hi,
For reference only, this is the ADC sim I commented on.
 
hi,
For reference only, this is the ADC sim I commented on.

10μS isn't a great deal then... I thought that after a read on the ADC the internal hold cap would be pretty much used up... I expected worse.

Live and learn as they say...
 
hi rems,
Checked your Thermistor pdf tables, our values are very close.
 
ok.thanks.the thermistor which i use is 5kohm.and beta value is 3760.EPCOS - B57276K123A30 .So can i use this lookup table.could you please check my code to set up the ADC value.iam attaching my schematic also.
 
ok.thanks.the thermistor which i use is 5kohm.and beta value is 3760.EPCOS - B57276K123A30 .So can i use this lookup table.could you please check my code to set up the ADC value.iam attaching my schematic also.

hi rems,
These are plots for your thermistor, using 12K Rt1 and also a linearised version.

Ian will help with your code, I dont use 'C', sorry:)

EDIT:
Larger plot, you should be able to scale from this OK.
 
Last edited:
i need to convert the adc value to temperature using lookuptable and sent it to pc using RS232 interface.
need to read the value in this protocol
<STX> <channelno>< temperature>< checksum>< etx>.thanks
 
hi rems,
Looking at your circuit, it appears you using OPA's between the NTC circuit and the PIC, what type of OPA is it, I cannot make it out on the drawing.

By reconfiguring the OPA's you could improve the resolution of the Therm/Temperature operation.

E.
 
Here's a good start... I've enhanced your code

Code:
#include<htc.h>
__CONFIG(0x2F84);
__CONFIG(0x1EFF);
#define _XTAL_FREQ 4000000	// I used 4mHz
#define STX 20				// change these to suit
#define ETX 21


void ADCInit()
	{
	ANSELA = 0xF;
	ANSELB = 0;
	ANSELE = 0;
	ADCON1 = 0xA0;	
	}

unsigned int ADCread(unsigned char ch)
	{
	if (ch>13) 		// i have 4 thermistors voltage connected 
		return 0;	// to input of pic16f1937
	ADCON0 = 0;
	ADCON0 = ch<<3; // select ADCchannel
	ADCON0 = 1;		// swich on adc module
	NOP();
	NOP();
	GO=1;			//START CONVERSION
	while(GO); 		//waiting conversion to finish
	ADCON0=0;
	return (int)ADRESH *256 + ADRESL;
	}

long GetADC(unsigned char ch)	// oversample 24 times
	{
	char loop = 23;
	long result = 0;
	while(loop--)
		result += ADCread(ch);
	return result;
	}

void HSerinit()
	{
	TRISC = 0xC0;					// should really be set
	SPBRG = 25;						// 4mhz xtal 9600 BAUD
	TXSTA = 0x24;					// TXEN and BRGH
	RCSTA = 0x90;					// SPEN and CREN
	}

unsigned int getTemp() 	// This will work out the temp
	{					// Its in fixed point so 663 is 66.3 degrees
	int idx;
	long High,Low, Actual;
	float temp1,temp2;
	int tempArray[] = {18436,17305,16101,14845,13570,12288,11048,9874,
						8774,7754,6826,5984,5235,4579,4005,3500};
			// these are oversampled values
	High = Low = tempArray[0];
	Actual = GetADC(0);
	for (idx=0;idx<16;idx++)
		{
		if( Actual < tempArray[idx])
			{
			Low = tempArray[idx+1];
			High = tempArray[idx];
			}
		else
			{
			if(High == Low) return 0;	// this bit works out a percentage
			temp1 = High - Low;			// and fills in the gaps
			temp2 = High - Actual;
			temp1 = temp2 / temp1;
			temp2 = (50 * temp1) + ((idx-1) * 50);
			return (unsigned int) temp2;	// returns 0.0 to 75.0 (fixed )
			}								// remember the decimal point.
		}
	return 750;		
	}

void SendTemp(unsigned int temp)
	{
	unsigned char CRC=0, idx;
	unsigned char sendArray[6];
		// Change this to suit YOUR application
	sendArray[0] = STX;
	sendArray[1] = 2;
	sendArray[2] = temp / 256;
	sendArray[3] = temp % 256;
	sendArray[5] = ETX;
	for(idx = 1;idx<4;idx++)
		CRC^= sendArray[idx];
	sendArray[4] = CRC;
	for(idx = 0;idx<6;idx++)
		{
		while(!TXIF);
		TXREG = sendArray[idx];	// send to PC
		}
	}
	
void main()
	{
	unsigned int temperature;
	OSCCON = 0x3B; 		// internal 4 meg
	NOP();
	NOP();
	HSerinit();			// set up Tx ports
	ADCInit();			// set up adc
	while(1)
		{
		temperature = getTemp();		// get actual temp
		SendTemp(temperature);			// send
		}
	}
 
Last edited:
Oversampling just means... read many times then divide... You take the mean value ie..

I read 24 times so I get a really stable reading then I use that high value to scale down to a useful reading to display
 
could you please tell me what will be the interpolation formulae to read temperature using adc values.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top