PDA

View Full Version : Switch sensor vs. switch PIC pin



fratello
- 5th April 2011, 15:16
I made one thermometer with LED display for my car. I intend to use two DS18B20 sensors. Which method it's better : 1.using a switch for sensor-and a single pin of 16F628A (picture 1); 2.switching between sensor from one port of PIC (figure 2).
The distance from PIC to switch are about 40 cm and from PIC to sensors are about meters. Thanks in advance for reply !

ScaleRobotics
- 5th April 2011, 15:49
Hi Fratello,

Why not just put them on the same bus with no switch?

According to the data sheet, you can talk to them both separately:


Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area.

It looks like you have enough digits in your display to represent A or B for each temp, so you can tell them apart.

fratello
- 5th April 2011, 16:05
Thank for reply !
The reading of temperature is ...chaotic ! Sometimes I want to see the temperature of outside, sometimes -the temperature of inside ! Without any rule !
So, I need one switch... OK, the ideea to use both sensor on the same bus it's good, but...i need to read the serial number of each sensor and keep this serials in eeprom ?! It is one simply way to do this with PBP commands ? I made once one termometer using 1-wire commands and I remember it's not so easy :(...

Archangel
- 6th April 2011, 05:56
You could have your Main loop check the status of a switch, not in your sensor loop, if closed it jumps to a sub routine to check one and if open it goes to a different sub routine. the DS18B20 temp sensors never get switched, they are always on, so no noise problem.
In the sub routines use your owout / owin and jumps to display refresh routine with pertinent data.
You could even have the main loop read both sensors every loop and have your subs just display the variables your data is stored in.

fratello
- 6th April 2011, 06:08
So the second variant it's better ?!

Archangel
- 8th April 2011, 09:44
Hi Fratello,
Well your complaint was noise interfered with data when you switch the device in /out. If you leave it "in circuit" all the time it eliminates that possibility. By using a separate input to detect a switch the noise is confined there. You might also consider using a pin that has an interrupt available, so it changes in "real time", instead of waiting for a loop to get around to it.

fratello
- 8th April 2011, 18:05
So...This is correct ?

...
If portA.7= 1 then
valoare=temperature
semn=sign
else
valoare=temperature2
semn=sign2
Endif

Gosub Selectie
Gosub Display ' B for Common CATOD;without B for Common ANOD

Goto Main

'================================================= =====================================
Selectie :

IF semn ="-" then
DIGIT_3="-"
else
DIGIT_3=" "
ENDIF

IF valoare DIG 2 = 0 THEN
DIGIT_2 = " "
ELSE
DIGIT_2 = valoare dig 2
ENDIF

DIGIT_1 = valoare dig 1
DIGIT_0 = valoare dig 0

RETURN
'================================================= =====================================
Display: ' For Common ANOD
for i=0 to 4
TEMP = DIGIT_3 : gosub segments
COMMON_3 = 1 : PAUSE 1 : COMMON_3 = 0


TEMP = DIGIT_2 : GOSUB segments
COMMON_2 = 1 : PAUSE 1 : COMMON_2 = 0

TEMP = DIGIT_1 : GOSUB segments
COMMON_1 = 1 : DP = 0 : PAUSE 1 : COMMON_1 = 0 : DP = 1

TEMP = DIGIT_0 : GOSUB segments
COMMON_0 = 1 : PAUSE 1 : COMMON_0 = 0
next i
RETURN
Thanks for support !5335

fratello
- 11th April 2011, 19:02
One of my DS18B20 it's about 4 meters from PIC. What is the smaller value of resistor used for this sensor ? Can I try with 1k ? Thanks !

pedja089
- 12th April 2011, 00:01
I have used 15m cable and pull up resistor 680 ohms. Resistor value depends greatly on the capacity of cable. And the capacity of the cable depends on the length.

fratello
- 17th April 2011, 16:23
With 5 meters of cable from PIC to DS18B20, no need to decrease value of R (still 4k7). Thanks for support !

fratello
- 4th August 2011, 11:17
...but, in some cases, I decrease the value to 3k9...for the same lenght of cables !