breadbord
Newbie level 3
Hello
Today i got a nasty problem with my temperature sensor the DS18B20.
Last week i tested with these temperature sensor on a motor of my car and on the oil, so i used the ROM code from the sensors.
But today when i start measurement i got one value the hole time,untill i disconnect the sensor or reset my board
when i reset my board i got a new value, this is the valid temperature but i keeps the same temperature the whole time. until i reset the board again and get the valid temperature
Also when i disconnect the sensor when the measurement is running i get 0,0065. I allways get this when i disconnect so this is also valid.
Anybody got the same problem like i have?
Here my code . It's written for a PIC 18F87J50 with mikroC. This code is only for one sensor
Today i got a nasty problem with my temperature sensor the DS18B20.
Last week i tested with these temperature sensor on a motor of my car and on the oil, so i used the ROM code from the sensors.
But today when i start measurement i got one value the hole time,untill i disconnect the sensor or reset my board
when i reset my board i got a new value, this is the valid temperature but i keeps the same temperature the whole time. until i reset the board again and get the valid temperature
Also when i disconnect the sensor when the measurement is running i get 0,0065. I allways get this when i disconnect so this is also valid.
Anybody got the same problem like i have?
Here my code . It's written for a PIC 18F87J50 with mikroC. This code is only for one sensor
Code:
//**********************************************************
//* TEMPERATURE SENSOR FUNCTIONS *
//**********************************************************
unsigned short *romcode[8];
unsigned short looper;
char *TussenOut;
char *Outputter[8];
unsigned int temp;
const unsigned short TEMP_RESOLUTION = 12;
char *text = "000,0000";
char *tussen;
char GetRom() {
Ow_Reset(&PORTD, 0);
Ow_Write(&PORTD, 0,0x33);
Delay_us(120);
for(looper=0;looper<=7;looper++){
romcode[looper]=Ow_Read(&PORTD, 0);
ByteToHex(romcode[looper], Outputter[looper]);
}
return Outputter;
}
char Display_Temperature(unsigned int temp2write) {
const unsigned short RES_SHIFT = TEMP_RESOLUTION - 8;
char temp_whole;
unsigned int temp_fraction;
// Check if temperature is negative
if (temp2write & 0x8000) {
text[0] = '-';
temp2write = ~temp2write + 1;
}
// Extract temp_whole
temp_whole = temp2write >> RES_SHIFT ;
// Convert temp_whole to characters
if (temp_whole/100)
text[0] = temp_whole/100 + 48;
else
text[0] = '0';
text[1] = (temp_whole/10)%10 + 48; // Extract tens digit
text[2] = temp_whole%10 + 48; // Extract ones digit
// Extract temp_fraction and convert it to unsigned int
temp_fraction = temp2write << (4-RES_SHIFT);
temp_fraction &= 0x000F;
temp_fraction *= 625;
// Convert temp_fraction to characters
text[4] = temp_fraction/1000 + 48; // Extract thousands digit
text[5] = (temp_fraction/100)%10 + 48; // Extract hundreds digit
text[6] = (temp_fraction/10)%10 + 48; // Extract tens digit
text[7] = temp_fraction%10 + 48; // Extract ones digit
// Print temperature on LCD
Uart1_Write_TExt(text);
}
void InitialiseDS18B20(){
Ow_Reset(&PORTB, 4); // Onewire reset signal
Ow_Write(&PORTB, 4, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTB, 4, 0x44); // Issue command CONVERT_T
Delay_us(120);
}
void GetTemp(){
Ow_Reset(&PORTB, 4); // Onewire reset signal
Ow_Write(&PORTB, 4, 0xCC); // Issue command SKIP_ROM
/*Ow_Write(&PORTB, 4,ROMCODE[0]);
Ow_Write(&PORTB, 4,ROMCODE[1]);
Ow_Write(&PORTB, 4,ROMCODE[2]);
Ow_Write(&PORTB, 4,ROMCODE[3]);
Ow_Write(&PORTB, 4,ROMCODE[4]);
Ow_Write(&PORTB, 4,ROMCODE[5]);
Ow_Write(&PORTB, 4,ROMCODE[6]);
Ow_Write(&PORTB, 4,ROMCODE[7]);*/
Ow_Write(&PORTB, 4, 0xBE); // Issue command READ_SCRATCHPAD
temp = Ow_Read(&PORTB, 4);
temp = (Ow_Read(&PORTB, 4) << 8) + temp;
Display_Temperature(temp);
}
//**********************************************************
//* END TEMPERATURE SENSOR FUNCTIONS *
//**********************************************************
char temperatuurlezer;
void main(){
UART1_Init(115200);
Uart1_Write_TExt("hello");
InitialiseDS18B20();
while(1){
Delay_ms(100);
GetTemp();
Uart1_Write_Text("\n\r");
}