Temperature sensor

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys, need some help from you all, master of AVR :D ...
My Question is, how to use temperature sensor at avr butterfly?...could some1 show me the sample program using the existing temperature sensor at avr butterfly..and how that's sensor working?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AVR butterfly sensor is NTC, see it's working principle.
Since butterfly code and application GCC port are open, You may take a look onto temperature readout part.
Would suggest finding a good reading from Smiley Micros on subject in forum, too.
Not sure about what's is a question, indeed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to the forum.

Pages 21 and 22 of the AVR Butterfly Evaluation Kit User Guide explains the Negative Temperature Coefficient Thermistor used on the Butterfly, and provides an equation for calculating the temperature based upon the ADC readings.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kas wrote:
AVR butterfly sensor is NTC, see it's working principle.
Since butterfly code and application GCC port are open, You may take a look onto temperature readout part.
Would suggest finding a good reading from Smiley Micros on subject in forum, too.
Not sure about what's is a question, indeed.

i already studied about the NTC which is AVR butterfly sensor, and from the schematic of the avr butterfly, that NTC used PF0, to used it we need to used ADC too??, i'm not clearly understand about this... :cry:
Hope some1 can help me..i just need a simple program using NTC...which register it stored the value of temperature??...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would have doubts You will receive a program (code) here.
Having and presenting Your own will generate strong support. The documentation is freely available, indeed. NTC is hooked up onto PF0, configured as ADC input. ADC converts voltage into readings in degrees. Thus for producing digital value ADC is needed. Load GCC port of butterfly code, and look onto corresponding part. Will take some reading in tutorials, too, regarding ADC operation. The register of that value is a certain variable. It is documented down to single line comments, at least ADC part. Enjoy.

A hint - tutorials are for reading.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dust off the hard drive...

Well, this was from one of my first AVR programs, on a butterfly, in Bascom.

I'll leave it to you to decide how to convert it to your language of choice, and how to display information on the Butterfly's LCD using your language of choice.

Nothing to clever or optimized here, the goal was just to make it work.

Therm:
'Test set up for reading the Butterfly's included Neg Temp Coef Thermister
'It is tied to Port F, Pin 0 and is read via ADC0, (Channel 0)
'Configure ADC:
'Butterfly NTC Thermister is on ADC Channel 0
'Formula to convert Thermister reading to Temp is in the BF User Guide, P. 22
'ADC Reading is 487 while ambient temp is about 81 'F, this is about correct.
'Breath on thermister, readings get smaller, eg 488, 463, 459, etc.
'Therm 488 = 27.1 'C  = 80.8 'F
'Therm 483 = 27.4 'C  = 81.3 'F
'Use single mode and auto prescaler setting
'The single mode must be used with the GETADC() function
'The prescaler divides the internal clock by 2,4,8,16,32,64 or 128
'because the ADC needs a clock from 50-200 KHz
'The AUTO feature will select the highest clockrate possible automatically.

'Have NOT tested the program with 0 degrees, or with Negative Temps.

Config Adc = Single , Prescaler = Auto , Reference = Internal
Start Adc                                                   'Power Up this component / sub-system

'W = ADC Value
'T1 = Temp in 'C
'T2 = Temp in 'F
'TS = Temp as a string, 'F

Fc = 1                                                      'Set Flag  Flash Colon on LCD

Do
  W = Getadc(0)                                             'Return with reading W
  T1 = 1024 - W                                             'Calc 'C from ADC reading
  T1 = W \ T1
  T1 = Log(t1)
  T1 = T1 + 14.2617
  T1 = 4250 \ T1
  T1 = T1 - 273                                             ' Deg C

  T2 = T1 * 9
  T2 = T2 \ 5
  T2 = T2 + 32                                              ' Deg F

  Ts = Str(t2)
  Ts = Left(ts , 4)                                         'Trim it down

'UnRem Print to dump data on PC CRT with Terminal Emulator program
' Print "Therm: " ; W ; "  " ; T1 ; "  C  " ; T2 ; " F  " ; Format(ts , "     ")

  Cls
  Lcd Ts

  Waitms 250
Loop
Return

Good luck with your project, hopefully this will get you started.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have done some reading about NTC thermistors recently. They all have a curve to them. Professor Steinhart has a formula that will extrapolate along the curve. You need 3 resistances at 3 temperatures (like 0 deg C, 25 deg, and 100 deg). There is a calculator at US Sensors that converts these readings into the a,b, and c coefficients used by the Steinhart Equation. The equation uses the resistance of the sensor to calc the temperature. I think the 'trick' is calculating the resistance of the sensor correctly. I use a known R from VCC to the NTC, and read the volts on the NTC. You calc the current thru the series resistor using the V across the resistor. I originally used 5.00 - Vad to get the volts, and the temps were off. The lesson was use the Real Vcc like 4.92 - Vsd. Hope this helps.


//       220           4K-400
// +5---/\/\/\----+---\/\/\/\/\---gnd
//      rref      |      NTC
//                v		

float ntcv;   //v across thermister
float ntcvsm; //v smoothed
float ntci;   //current thru thermistor
float ntcr;   //r of thermistor
float ntcrsm; //r smoothed
float lnr;    //ln(r)
float lnrcu;  //ln(r)^3
float tk;     //kelvin
float oneovertk;
float rref=220.0; //in series with thermistor

#if 0
__flash float a=1.663443e-3; //3k duralast chevy temp sensor from autozone
__flash float b=1.849225e-4;
__flash float c=5.42688e-8;
#endif

#if 0
float a=1.778139e-3; //wells mfg tu165 from autozone $9.99
float b=1.511277e-4;
float c=9.472924e-7;
#endif

//-------------------------
void calcntctemp(void){
//calc temp from ntc thermistor on pin8 or pin10?
//steinhart eqn: 1/T= a+ b(LnR)+c(LnR)^3 
//20 fp ops + a log

  addat[0] = readadchan(0);  //debug chg to ad ch 1  ad ch0 on pin8
  ntcv = addat[0]*ad2volts;  //volts across thermistor
	ntcvsm = ntcvsm + .125*(ntcv-ntcvsm); //v smoothed
  ntci = (5.0-ntcvsm)/rref;  //amps thru thermistor
  ntcr = ntcvsm/ntci;        //ohms of thermistor
  ntcrsm = ntcrsm + .125*(ntcr - ntcrsm); //r smoothed
  lnr = log(ntcrsm);         //ln of r
  lnrcu = lnr*lnr*lnr;       //ln r cubed
  oneovertk = ntca + ntcb*lnr + ntcc*lnrcu; //the Steinhart equation!
  tk = 1.0/oneovertk;        //deg in K
  degC = tk-273.15;          //deg C
  degF = 1.8*degC + 32.0;    //deg F
}

//-------------------------
void ntcloop(void){
//read ntc on a/d ch 0  
char c;

  cprintf("ntc thermistor\n");
	cprintf("ad  degc   degf   v      a      r   q=quit\n");
  while(c != 'q'){
    if(kbhit()){
      c=getchar();
    }
    calcntctemp();
    cprintf("%03x %#6.1f %#6.1f %#6.3f %#6.3f %#6.1f \r",
		  addat[0],degC,degF,ntcvsm,ntci,ntcrsm);
    delnms(10);
  }
}

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Guys, I'm done with my ADC program but now i need to find a formula that convert ADC value to temperatures,from the NTC formula in the AVR butterfly evaluation kit user guide, it's using a >>>Ln<<< how to write the natural log in C...anyone know how to use it..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Butterfly SKD "sensors.c" employs look up table for each temperature value (75 discrete values). No need calculate logarithmic function, and definitely quite reasonable solution.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

what do you mean by" sensor.c"..how to get it...im not understand..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, should mention that before:
http://users.forthnet.gr/ath/kgiannak/
it's Kostas Giannakakis' web site containing that software develpment kit (SKD). Really nice articles and code.
Have fun reading.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

its ok..i'm already used library ..with this function, i can put "log". We know the value of exponent 'e' is 2.718, so ln x = (log x / log 2.718 )..:)..and its working...anyway thanks...