Page 1 of 1
One wire problem
Posted: Mon Sep 29, 2014 1:51 pm
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.

I hope somebody can help me with this.
BR
Ossi
Re: One wire problem
Posted: Tue Sep 30, 2014 5:06 pm
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.
Re: One wire problem
Posted: Wed Oct 01, 2014 2:06 pm
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.
Re: One wire problem
Posted: Wed Oct 01, 2014 2:25 pm
by Benj
Hello,
Can you attach your program so we can double check everything is ok there for you.
Re: One wire problem
Posted: Wed Oct 01, 2014 4:53 pm
by ossir
Benj wrote:Hello,
Can you attach your program so we can double check everything is ok there for you.
Here you are
Re: One wire problem
Posted: Wed Oct 01, 2014 5:01 pm
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.
Re: One wire problem
Posted: Wed Oct 01, 2014 5:33 pm
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"
Re: One wire problem
Posted: Wed Oct 01, 2014 6:46 pm
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
Re: One wire problem
Posted: Thu Oct 02, 2014 10:29 am
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.
Re: One wire problem
Posted: Thu Oct 02, 2014 12:59 pm
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.
Re: One wire problem
Posted: Thu Oct 02, 2014 2:20 pm
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.
Re: One wire problem
Posted: Tue Oct 14, 2014 6:35 pm
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
Re: One wire problem
Posted: Wed Oct 15, 2014 12:10 am
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
Re: One wire problem
Posted: Wed Oct 22, 2014 4:59 pm
by ossir
I tried to make it work with two sensors, but i get only error message.
Re: One wire problem
Posted: Fri Nov 21, 2014 5:21 pm
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?
If some one could help me with this i will appreciate it.
Re: One wire problem
Posted: Fri Nov 21, 2014 6:22 pm
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
Re: One wire problem
Posted: Fri Nov 21, 2014 6:32 pm
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:
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.
Re: One wire problem
Posted: Sat Nov 22, 2014 11:26 am
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.