OneWire/DS18B20 with arduino @ 8MHz ??

I’ve prototyped my device using a standard Arduino @ 16MHz.

Now that I’ve gone to a custom board using more representative hardware, which is running @ 3.3V and 8MHz, my DS18B20 device is giving me some strange readings. I’m not running in parasite mode, I am powering the DS18B20 @ 3.3V, which is within the acceptable range according to the datasheet.

Has anyone else experienced this problem?

EDIT: It’s probably 5~10% of readings that are erroneous

Yes the DS18S20 has critical timing for example the Master Write slot needs to be between 60uS and 120uS, if you half the clock speed then you will be outside that limit. So you will probably have to hack the library or if it is using the inbuilt delay routines hack those to account for the change in clock speed.


Thanks heaps. Was hoping that WASN'T the case...


ok BUT...

shouldn't all of that be automatically accounted for by changing the clock speed in the board.txt definition?

All my serial stuff kept working when I changed the crystal and made the appropriate change in the board definition.

Depends on how they wrote the 1 wire library.

I am having same kind of problems running ATMega328p @ 3,7V/8MHz and a few DS18B20 sensors with parasite power. I looked into the OneWire library and found out that it uses several times delayMicroseconds() function and during temperature conversion delay() function. As the microcontroller is running with half of the "normal" speed should I take that into account by dividing the delays by two? The thing that is confusing me is that for example LiquidCrystal library is also using delayMicroseconds() function, but I can´t see how it would take the clockspeed into account – and it is running really nicely @ 3,7V/8MHz. I would really appreciate if someone would be so kind and elaborate the hoccus poccus behind all this?

elaborate the hoccus poccus behind all this?

All delays are ultimately controlled by the clock speed as are the instruction timing. You can have a delay in two ways 1) Have a loop with a known number of instruction cycles. 2) Have a hardware timer counting down on each clock cycle.

With the second method the counters can have pre scaling counters and so it could be easy to compensate for a change in clock frequency by changing the pre scaling on the clock. But however it is done delays do depend on the processor clock.

Yep I can’t see any delays that SHOULDN’T automatically be correct when the 8MHz clock is selected.

At the moment I’m getting around it by checking if there was an unreasonably large change in temperature since the last reading - if so, discard the most recent and take another reading.

Still like to get it working properly though.

Perhaps I'm just stating the obvious but... Don't you need to changes boards.txt and the fuses on the 168 or 328 to change clock freq? I change clock freq between 1Mhz, 8Mhz and 16Mhz depending on the project I'm working on. Never have a timing issue if I add a section to boards.txt and change the fuses to match.

Never have a timing issue if I add a section to boards.txt and change the fuses to match.

I know - that's the issue. It SHOULD work by changing to the correct board speed, but it just doesn't.