One wire problem

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

One wire problem

Post by ossir »

Hello

I try to read temperature with Dallas 18B20 sensor, but i get always "-1.-6 C" readings (value not changing).
I use "single one wire" example code with 16f887 chip and i have 4Mhz crystal and i use FC5.

Here is how i connected it to chip. Port pin is A0, resistor is 4.3k and Vdd is 5V.
Image
I hope somebody can help me with this.

BR
Ossi

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: One wire problem

Post by Benj »

Hello,

Your wiring setup looks to me.

The 4MHz crystal might be the cause of the issue. Could you use say a 20MHz crystal instead so the chip has more processing power to deal with the 1-wire strict timings.

ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

Re: One wire problem

Post by ossir »

Hi

I changed crystal to 20Mhz and now i get only "CRC Error". I double checked connections to sensor and if i disconnect the signal wire, then i get " No Device Found". Also i tried another DS18B20 sensor, but same results.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: One wire problem

Post by Benj »

Hello,

Can you attach your program so we can double check everything is ok there for you.

ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

Re: One wire problem

Post by ossir »

Benj wrote:Hello,

Can you attach your program so we can double check everything is ok there for you.
Here you are
Attachments
OneWire.fcf
(10.5 KiB) Downloaded 362 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: One wire problem

Post by Benj »

Hello,

I would change the Configuration oscillator setting from XT to HS to match the new 20MHz crystal.

Hopefully this should help things but let us know how you get on.

ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

Re: One wire problem

Post by ossir »

Benj wrote:Hello,

I would change the Configuration oscillator setting from XT to HS to match the new 20MHz crystal.

Hopefully this should help things but let us know how you get on.
Same "CRC Error"

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times

Re: One wire problem

Post by jgu1 »

Hi Ossir!

I have a project with this device. As Ben say It something with the timing, and my experience with Ds18B20 Ben is right. I have only managed to get this att. project running. You can test it, and as it is with a Pic16f886 it work´s. But you can try to change the chip. The oscillolator is set to 8 MHz by help Oscon set in Code.

Good luck

Jorgen
Attachments
1. Single OneWire_DS18B20_886_Virker.fcf
(15.5 KiB) Downloaded 404 times

ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

Re: One wire problem

Post by ossir »

jgu1 wrote:Hi Ossir!

I have a project with this device. As Ben say It something with the timing, and my experience with Ds18B20 Ben is right. I have only managed to get this att. project running. You can test it, and as it is with a Pic16f886 it work´s. But you can try to change the chip. The oscillolator is set to 8 MHz by help Oscon set in Code.

Good luck

Jorgen
I change the chip to 887 and it works! I try same project options setup and 8mhz internal crystal to "my code" and i get only -1.-6 C.

Do i need to calibrate it to get real values? Temperature value seems to be pretty close, but i'm not sure.

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times

Re: One wire problem

Post by jgu1 »

It requires no calibration. I can not explain to you what happens.
I have also struggled with getting them to work, and not all kinds Pic will work with DS18B20 in FC, that´s my experience. So far I see it seem to the work best around 8MHz and in this example I gave you.

Jorgen.

ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

Re: One wire problem

Post by ossir »

Is there any simply example for two sensors. I have only that attachment example, but it is too confusing to me because there is only litle explanations.
Attachments
2. Multiple OneWire.fcf
(45.24 KiB) Downloaded 369 times

Brendan
Posts: 243
Joined: Tue Nov 27, 2012 12:53 pm
Location: Cambridge, UK
Has thanked: 140 times
Been thanked: 118 times
Contact:

Re: One wire problem

Post by Brendan »

As I'm currently coding a 1-wire solution, given that I'm dealing with writing and reading EEPROMs (not just temperature sensors), I can very highly recommend the following device...

http://www.maximintegrated.com/en/produ ... ml/tb_tab0

This further supports search acceleration, where you have more than one addressable 1-wire device on the bus, and also 12V programming pulse generation (from a 12V source) should you need to program 1-wire devices as-well.

1-wire timing is pretty critical whereas the above device interfaces to your MCU (PIC, whatever) via simple TTL232 serial.
There is also an I2C alternative for this device, but unnecessary unless your ports are limited and you need to mux with other addressable I2C devices.

Regarding CRC calculation, this is most easily (and quickly) achieved by a CRC lookup table if you have the spare RAM or ROM space. Basically, for each successive data Byte you XOR with the existing CRC byte (commencing 0x0 for the usual seed of '0'), and the resulting value is the index value for the lookup table. You then simply extract the indexed Byte for the next XOR operation with the next data Byte, and repeat the operation for as many bytes you have. The last indexed Byte is then your CRC.

Just make sure that you use the right table as CRC polynomials do vary.


All the best,

Brendan
Last edited by Brendan on Wed Oct 15, 2014 12:32 am, edited 2 times in total.

Brendan
Posts: 243
Joined: Tue Nov 27, 2012 12:53 pm
Location: Cambridge, UK
Has thanked: 140 times
Been thanked: 118 times
Contact:

Re: One wire problem

Post by Brendan »

...Incidentally chaps,

The DS18B20 is not the same device as the DS1820 / DS18S20. More information here...

http://www.maximintegrated.com/en/app-n ... vp/id/4377

I have complained about family codes not being exposed for 1-wire comms in Flowcode, but a moot point as the present solution is more an educational implementation (understandably) and unsuitable for generic application. To work as intended, you will need the older DS1820 or DS18S20 drop-in replacement.

Alternatively, I'll repeat my above recommendation for the DS2480 1-wire interface. I can confirm it works flawlessly with Flowcode RS232, very easy to drive, removes all 1-wire woes at a stroke, and you can read or program any 1-wire device from its associated datasheet codes. Generally available in SMT package though.


All the best,

Brendan

ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

Re: One wire problem

Post by ossir »

I tried to make it work with two sensors, but i get only error message.
Attachments
MultipleOneWire.fcf
(12.63 KiB) Downloaded 197 times

ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

Re: One wire problem

Post by ossir »

I don't understand why it doesn't detect my sensors. I'm 99.99% there is no problem in connections. What can cause this detection problem?

I use 8Mhz internal oscillator, should i use something else?

Here is my MCU configuration, is there everything ok?

Image

If some one could help me with this i will appreciate it.

Brendan
Posts: 243
Joined: Tue Nov 27, 2012 12:53 pm
Location: Cambridge, UK
Has thanked: 140 times
Been thanked: 118 times
Contact:

Re: One wire problem

Post by Brendan »

1-wire timings are critical and must be strictly adhered to.

If you're trying to use the internal RC oscillator (8 MHz) then you could try playing with the OSCTUNE register as timing tolerance may play a part. Whether or not others have successully had it working on a specific PIC is only part of the story. Very advisable to use a higher frequency supported by external Xtal though.

Also, if your PIC isn't adequately decoupled or if there's supply noise, the RC oscillator will drift or modulate far more readily than an external crystal. For example, don't try sending data or activating other port pins during communication, or flashing LED's, etc.

If you have two devices connected to a 4k7 pull-up, 'weakness' won't help (depending on other influential factors). Try reducing it to 2k2 or 1k.

If all else fails, try using a DS1820 (without the 'B') for which the Flowcode component was originally designed.

Good luck,

Brendan
Last edited by Brendan on Fri Nov 21, 2014 6:45 pm, edited 2 times in total.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: One wire problem

Post by kersing »

The 16F887 has a default RC clock of 4 MHz, not 8 MHz (data sheet page 66). In your October 22nd flowchart you are not setting the clock to 8 MHz.

To set to 8MHz add C code icon with:

Code: Select all

OSCCON=0b01110000
Have you tested you chip setup with the default 1 second blinker? Just add (at the start of your existing flowchart) a loop with two output icons and two 500 millisecond delay statements (one between the two output icons and one just before the end of the loop). Add a resistor and led to the appropriate output pin and use a stopwatch to check the time required for the led to on and off 10 times.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

ossir
Posts: 27
Joined: Tue Oct 08, 2013 7:14 pm
Has thanked: 1 time
Been thanked: 1 time

Re: One wire problem

Post by ossir »

Yesterday i got some progress. I changed crystal to external 20Mhz and i make flowchart more simple. I checked clock with led blinker and scope and it's ok. Also i tried 2k pull up resistor, but no change.

How it works now:
- LCD shows two temperatures, but both temperature values is from one sensor (if two sensors is in use)
- Only one sensor works when i use two sensors.
- If i use single sensor, it still shows two temperatures. Both sensors works.
- Detect both sensors
- Temperature value seems to be correct.

I think there is some problem in my flowchart, but i don't know what.
Attachments
MultipleOneWire.fcf
(16 KiB) Downloaded 293 times

Post Reply