News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

DS18B20 Problem

Started by Giuseppe MPO, Apr 14, 2021, 10:58 PM

Previous topic - Next topic

Giuseppe MPO

Good evening,
I can't get a DS18B20 temperature sensor to work. I don't insert the code because even with the simple program lines described in the manual I have the same results.
The problem is the following, I insert the program in a PIC18F25K22 and everything works perfectly, the same program inserted in the PIC18F25K42
I cannot in any way make it work.
Inserting the oscilloscope I see the PIC call but from the 18B20 no answer, ever.

Help

RGV250

Without any code or information the only question I can ask is, have you studied the datasheet to see if there are any different peripherals on the pin that you are using.

Bob


LeonJ

I also can not get the DS18B20 to work on a PIC18F27K42 running at any clock speed whereas Les' code works fine on a PIC16F1575/9 and others.

I'm quite sure there are no interference with the DQ pin from peripherals etc. The bit-stream is visible on the bus but the DS18B20 does not respond correctly. (Most likely due to timing issues).

Since the project requires a MultiDrop OW bus and is time sensitive with numerous interrupts (which should all be disabled during the OneWire calls), I've opted for the DS2482-100 OneWire/I2C bridge chip instead. (Still not implemented or tested).

 

Giuseppe

I send a piece of code I hope it will be useful


'--------------Test 1-Wire ds18b20------------------------------

Symbol DQ = PORTA.0        'set TRISA.0 = 0 digital input
Dim temp_ds As Word
Dim C As Byte
Dim CPerD As Byte

'---------------------------------------------------------------
main:

GoSub ds18b20



GoTo main

'------------------------------------------------------------------
ds18b20:

                          ' Sends via mode = 1 a bus initialization consisting of a Reset = 0 for> 480uS
OWrite DQ, 1, [$CC, $44]  ' Send Skip Rom command ($ CC) + ($ 44) Convet T command. Converts temperature and stores in
Repeat                    ' 2 Byte of the ScratchPad (Byte 0 and Byte 1) the value
DelayMS 25                ' Wait until conversion is complete
ORead DQ, 4, [C]          ' Continue reading Low pulses Until. 4 stands for Mode (No Reset Bit Mode)
Until C <> 0              ' the DS1820 has finished the conversion because the bus from 0 has gone to 1
OWrite DQ, 1, [$CC, $BE]  ' Send Read ScratchPad command

ORead DQ, 2,[temp_ds.LowByte,temp_ds.HighByte, C, C, C, C, C, CPerD]
'
' Calculate the temperature in degrees Centigrade
'
HSerOut2 [temp_ds]      'byte lsb $2d - byte msb $38
DelayMS 3


temp_ds = (((temp_ds >> 1) * 100) - 25) + (((CPerD - C) * 100) / CPerD)


HSerOut2 [temp_ds]      'byte lsb $2d - byte msb $38
DelayMS 3

Return

Giuseppe MPO

Thanks Giuseppe your code is similar, maybe practically the same as mine that works perfectly on all the other PICs but on the PIC18F25K42 it refuses to work. I have little experience on the K42 series, I need to investigate and understand what interferes.

RGV250

Hi,
Have you tried the code on another pin, A0 has CLC on the K42 where the 18F25K20 does not. Not sure if that would affect it but changing the pin may show it.
A6 or 7 seem to have the least peripherals if you are using the internal oscillator.

Bob

Giuseppe MPO

For now I have tried on C3, checking with an oscilloscope and with a logic analyzer the commands can be seen that come out in an inconclusive way and, obviously, the 18b20 does not respond.

Ground

is important pullup DQ with 4k7.

Pepe


Pepe

Example in proteus

Giuseppe MPO


tumbleweed

Quoteput ANSEL0 = 0
Not required... the compiler automatically sets all pins to digital mode for you at startup

F1_SOF equ $ ; ds18b20.BAS
    movlb 0X3A
    clrf ANSELA
    clrf ANSELB
    clrf ANSELC
    clrf SLRCONA
    clrf SLRCONB
    clrf SLRCONC
    movlb 0X3E
    clrf CM1CON0
    clrf CM2CON0

dr-zin

Really?  I thought the default for all Microchip PIC pins that could be analog or digital was to startup in analog mode?  I always include a "All_Digital True" statement near the top of every program I create so I can turn off the A/Din features (when not utilized).  Guess I should experiment a little?  Thanks for the tip...

tumbleweed

The default for the chip is analog mode, but the compiler automatically inserts code to switch them all to digital mode for you (see the above asm output).

"All_Digital True" is now the default, but I don't think it's always been that way in past versions.


towlerg

Two things, 18F27K42 can be a little quaint (see ADC for examples) plus are you sure you have DS18B20? Both non B and parasitic version have different protocol.

Giuseppe MPO


Having tried everything, there is nothing to be done, it does not work.
I tried to change pins, changed sensor, changed clock, set to 4MHz, it doesn't work.
If I change PIC, with 18F25K22 everything works perfectly

Pepe

the version free don't do it

Giuseppe MPO


dr-zin

Tumbleweed,

Great!!!  So...... now I have to specifically set the A/D pins to analog(ue) if I want to use them that way, I suppose.  I do see a reference in the new manual about having to set ADCON1 register to select the pins that are to be used that way.  Whatever...  After all, the software and chip need to be made aware of which feature I want.  Besides, I use digital mode far more often than analog.  I can live with that as long as I know about it.  Thanks again for the info.

Giuseppe MPO

I solved ...
Let's say not really solved,
with the PIC18f25K42 there was just nothing to do, I tried everything....
I needed a PIC with a CIP ZCD I replaced the PIC18F25K42 with the PIC16F1619
and everything worked as soon as I connected it.

Thanks everyone for the help.