PDA

View Full Version : 1-Wire



WarPony
- 8th May 2008, 21:43
Can anyone help me with the syntax for writing to a one-wire devices scratch pad?
I want to set the Th, Tl, and config bytes (byte 3,4,5).

I was thinking

Owout PortX.X, 1, [$CC, $4E] 'skip ROM search and write to scratch pad
Owout PortX.X, 1, [$XX, $XX,$XX] bytes 3, 4, and 5

Do I need place holders for the first to two bytes on the scratch pad? If so, what is that syntax?

Darrel Taylor
- 8th May 2008, 22:44
It looks like you are using a DS18B20.
It's best to include that kind of information with the questions.
If not then this won't apply.

DS1820 resolution
http://www.picbasic.co.uk/forum/showthread.php?p=47692

WarPony
- 9th May 2008, 00:00
Thanks old chap

i have been beating my head into the wall

I understand the alarm registers are 8 bit with the MSB being the sign bit. Is that a straight decimal conversion? i.e. 25 degrees Celsius would be %00011001

Again

Thanks a lot

Darrel Taylor
- 9th May 2008, 02:58
Sure, that'll work. Added: (not the beating your head part)
Or you could just use 25.


OWOUT DQ, 1, [$CC, $4E, 25, 0]High limit = 25°C
Low limit = 0°C

If you want to use negative alarms, it's easier to use a variable


LowLimit VAR BYTE
HighLimit VAR BYTE

HighLimit = 20
LowLimit = -10

OWOUT DQ, 1, [$CC, $4E, HighLimit, LowLimit]
Do you know how to read the alarm status yet?
<br

WarPony
- 9th May 2008, 21:17
Think so

How's this?

Alarm_H VAR Bit
Alarm_L Var Bit

Owout DQ, 1, [$CC, $EC]
Owin DQ, 1, [Alarm_H, Alarm_L]

Is it going to send back a 1 or 0 alarm bit?

Darrel Taylor
- 10th May 2008, 01:21
Think so

How's this?
Well, not so good.

There is only 1 Alarm status bit, No SkipROM, and mode 4 (bit data) is used to retrieve it after the AlarmSearch command.


Alarm VAR BIT

OWOUT DQ, 1, [$EC]
OWIN DQ, 4, [Alarm]

If there is an alarm, you have to read the temperature to figure out whether it's too high or too low.

It will return a 0 if there is an alarm, 1 if not. But you can reverse that easily with...
Alarm = Alarm ^ 1

hth,

WarPony
- 10th May 2008, 05:50
Thanks Darrell

I see. I forgot to change the mode bit. Still learning.

I really need a setpoint temperature for the "smarter" HVAC thermistat I am working on. I think I will just use another 18B20 as my setpoint temp and not worry about the alarms.

Darrel Taylor
- 10th May 2008, 20:37
I really need a setpoint temperature for the "smarter" HVAC thermistat I am working on. I think I will just use another 18B20 as my setpoint temp and not worry about the alarms.
You lost me there.
Using another 18B20 as a setpoint, would make it a "Variable point".

If you want to make a thermostat, it's probably easiest to just read the temperature and compare it against the desired "setpoints" in your program.
<br>

WarPony
- 11th May 2008, 20:04
Absolutely

I am entering a setpoint in the software and also going to have another 18B20 outside to give me the "variable setpoint". This way the system knows if it really needs to turn on or to just pause until it warms up or cools down

Darrel Taylor
- 11th May 2008, 22:14
AH HA! I see now.

Very good. Carry On.
<br>