one wire protocol
TRANSCRIPT
ONE WIRE PROTOCOLTEMPERATURE SENSORS:LM35 vs. DS18B20
Contents1.Introduction
1-wire protocol
2.How do they work ?
4.Code examples
3.Temperature sensor : LM35 vs. DS18B20
1. Overview of OWPOWP : copyright by MAXIMFeatures:
Bi-directionalSerial signal, half-duplexPower auto charge(by the internal capacitor in
slaves)One Master controls many slaves (different IDs)
in single line
1. Overview of OWP
1. Overview of OWP
2.WorkingCommunication with time slotsSlave self-clocked from master edge (high to
low pulse)Time slot:
+bit 1: pull bus low in short Tx > 1-2us
+bit 0: pull bus low in long Tx=60-120usSlaves sample in 15-60usMaster sample at 15us
2.Working
ex: The transaction sequence for accessing the DS18B20 is as follows:
Step 1.Reset bus
Step 2. ROM Command
Step 3. Function Command
3.TEMPERATURE SENSORS DS18B20 vs. LM35
3.1 DS18B20 -DIGITAL SIGNAL
Unique 1-Wire® Interface Requires Only One Multi-drop Capability Simplifies Distributed Temperature-Sensing Applications Requires No External Components Can Be Powered from Data Line; Power Supply Range is 3.0V to 5.5V Measures Temperatures from -55°C to +125°C (-67°F
to +257°F) ±0.5°C Accuracy from -10°C to +85°C Thermometer Resolution is User Selectable from 9 to
12 Bits Converts Temperature to 12-Bit Digital Word in 750ms
(Max) (Reference :DS18B20 datasheet)
3.1 DS18B20:RESET
//*************************************************************//ham onewire_reset() reset va xac nhan co ngoai vi tren mach //tra ve bit presence_pulse :0->co device ket noi va nguoc lai//-------------------------------------------------------------void onewire_reset()
onewire_pin_tris=0; //set_output_pinonewire_pin=0;__delay_us(250);__delay_us(230);onewire_pin_tris=1; //set_input_pin realease bus__delay_us(70); //sample presence pulsepresence_pulse=onewire_pin; //return 1:no device;0:device(s)__delay_us(410);
3.1 DS18B20:READ BIT
//master keo xuong low bus >1us roi realease bus lay mau trong khoang 15us//delay them khoang 60us la lay mau xong 1 bit onewire_read_bit()
onewire_pin_tris=0;onewire_pin=0;__delay_us(6);onewire_pin_tris=1; //realease bus __delay_us(8);DQ=onewire_pin; //sample in less than 15us after pull low the line
//return value to bit DQ
3.1 DS18B20:WRITE BIT
//ghi bit 1: ghi 0 trong >1us(chon 6us) sau do release bus trong >60us//ghi bit 0: ghi 0 trong 60-120us( chon 65us) sau do realese bus >1us(chon 5us )void onewire_write_bit1()
onewire_pin_tris=0; //pull low the lineonewire_pin=0;__delay_us(6);onewire_pin_tris=1; //realease bus__delay_us(64);
void onewire_write_bit0()
onewire_pin_tris=0;onewire_pin=0;__delay_us(65); //at least 60usonewire_pin_tris=1; //realease bus;recovery time__delay_us(5); //recovery time
DS18B20 Memory Map
3.1 DS18B20: LCD DISPLAY TEMP
Step1
•Initialization MCU , LCD…
•Reset and detect any 1-wire device connected on the bus
•If (no device) reset again
Step2
•Write Rom command :Skip Rom (only one slave on the bus)
•Write Function Command: Convert T
•Wait for 750ms
•Write Function Command: Read Scratchpad
Step3
•Convert 2 first data bytes in Scratchpad to ASCII
• Display temperature on LCD
•Return step1
3.2 LM35-ANALOG SIGNALCalibrated directly in ˚ Celsius (Centigrade) Linear + 10.0 mV/˚C scale factor0.5˚C accuracy guarantee able (at +25˚C)Low cost due to wafer-level trimmingVs from 4 to 30 voltsLow self-heating, 0.08˚C in still airNonlinearity only ±1⁄4˚C typicalLow impedance output, 0.1 Ω for 1 mA load
(Reference :DS18B20 datasheet)
3.2 LM35: LCD DISPLAY TEMP
Step1
•Initialization MCU , LCD…
•Adc_init();
Step2
•Read_adc();
Step3
•Convert adc to temperature(Vadc=t(C )* 10(mvolt))
• Display temperature on LCD
•Return step1
Simulation Result:
Temperature Sensors
DS18B20 LM35
Signal transmit -digital signal -analog signal
Data Process -1-wire protocol(1 master + many slaves)
-analog digital conversion
Resolution -0.0625 C -10mv/C + ADC 10bit0.5C
Price(Tme_30/5/2011) -27000VND -22000VND
Source code: (tested on board)Onewire.c ; onewire.hMPLAB
project:PIC_DS18B20 ;PIC_temp_sensorProteus file
References:
-All about OWP-1-Wire Overview-DS18B20 datasheet-LM35 datasheet-PIC16F887 datasheet