// Declaration file for temperatuere measuring via SMT 160/30 sensor
// Major rutine writed in ASM to minimalize measuring errors
//
// This idea to measure temp. is a litlle bit different from clasic one:
// we don't measure a real DUTY CYCLE (DC) and time, when is log1,
// but we are reading sensor (and count if is in log1 -> stridaL) after the same
// period and for the same time (aprox 108ms) then temperature is linear dependence
// on DC and result is in stridaH var.
// The temp. resolution is 0.5C (if stridaL=256 => stridaH=1 => 0.5C)
//
// This idea (and ASM rutine) is taken from Ondrej Vitous http://www.hw.cz/programovani/pic_temperature/vitous@hw.cz
// ( only czech page)
#define PORT PORTB
#define PIN 2 // pin number where is sensor
#define CIDLO PORT,PIN
#define SMT160_INPUT TRISB,PIN
#define MAX 80
/* MAX [0-135]
Tmax = (MAX/2 + 60); ex. MAX=130 => Tmax=130/2 + 60=125 C
Tmin = [(MAX+1)-136]/2 when MAX=130 then Tmin=-2,5C
=> deltaT=127.5C, resolution 0.5C
MAX 0 10 50 80 100 120 130 135
Tmax [C] 60 65 85 100 110 120 125 127.5
Tmin [C] -67.5* -62.5* -42.5 -27.5 -17.5 -7.5 -2 0
* - out of sensor range (-45C - +130C)
*/
char countL ; // counter lower byte
char countH ; // counter higher byte
char stridaL ; // log1 lower counter (if stridaL=256 => 0.5C)
char stridaH ; // log1 higher counter
char TEMP_J; // measured tempearture - tenths [C]
char TEMP_D; // measured tempearture - tens (hundreds) [C]
char minus ; // this is negative values flag, if is 1 we are under zero
void temperature() // main rutine
{
TEMP_D=0;
TEMP_J=0;
asm
{
MOVLW d'32' ; 2 cycles
MOVWF _countL
MOVLW d'54' ; 2
MOVWF _countH
CLRF _stridaL ; 1
CLRF _stridaH ; 1
BCF STATUS,Z ; 1
repeatA nop ; 1 measuring loop (sampling time) - 13600x
repeatB
BTFSC CIDLO ;1/2
INCF _stridaL,1 ;1
BTFSC STATUS,Z ;1/2
INCF _stridaH,1 ;1
DECFSZ _countL,1 ;3/2
GOTO repeatA
DECFSZ _countH,1 ;3/2
GOTO repeatB
; 3x rotate meassured DC
BCF STATUS,C
RLF _stridaL,1
RLF _stridaH,1
RLF _stridaL,1
RLF _stridaH,1
RLF _stridaL,1
RLF _stridaH,1
; RETURN
}
// and now convert temperature from DC to degrees (linear dependence)
if (stridaH < MAX) //60C - Tmax
{
minus=0;
TEMP_D=stridaH>>1;
TEMP_J=stridaH;
TEMP_D=TEMP_D+60;
if (TEMP_J % 2) TEMP_J=5; // 0,5 C or 0.0C
else TEMP_J=0;
}
else
{
if(stridaH>135) //(Tmin - 60C)
{
minus=0;
TEMP_D=(stridaH - 136); // ex.TEMP_J=185-136 = 49C
TEMP_J=TEMP_D;
TEMP_D>>=1; // temp_d/2
if (TEMP_J % 2) TEMP_J=5; // 0,5 C
else TEMP_J=0;
}
else // (Tmin - 0C) ex. stridaH=130 => t=(136-130)/2=-3C
{
minus=1;
TEMP_D=(136-stridaH);
TEMP_J=TEMP_D;
TEMP_D>>=1;
if (TEMP_J % 2) TEMP_J=5;
else TEMP_J=0;
}
}
}
Copyright © 2002-2006 SourceBoost Technologies