Why Handshake PICAXE-20M2 and DS18B20 do not work?

HaraldWien

New Member
Servus aus Wien!
(Greetings from Vienna)
I am a PICAXE-Beginner and i would understand how works this mystic Thing.;)
I try a handshake-Procedure between PICAXE-20M2 and the Temperature-Sensor DS18B20.
I know that "ow..."-Procedures (OneWire) exists on PICAXE-X-Line.
But i will try understand the Basic-functions on my PICAXE-20M2.
The test-circuit is ok, commands "readtemp" and "readtemp12" works well.
I show this page (15) in DS18B20-Datasheet:
DS18B20 InitTiming.jpg
And i wrote this PICAXE-Programm for my PICAXE-20M2:
[HR][/HR]
Code:
[color=Green]; Progr: p20M2 Test Temperatursenor DALLAS 18B20
; Datum: 2014-09-18
; Autor: HaraldWien
; ***********************************************************[/color]
[color=Navy]#picaxe [/color][color=Black]20m2
init:
      [/color][color=Blue]let         [/color][color=Purple]dirsB [/color][color=DarkCyan]= [/color][color=Navy]%11111111
      [/color][color=Blue]let         [/color][color=Purple]dirsC [/color][color=DarkCyan]= [/color][color=Navy]%00000000
      [/color][color=Blue]pullup off[/color]
[color=Black]main:       
      [/color][color=Blue]if [/color][color=Purple]pinC.1 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then
            pause [/color][color=Navy]10
            [/color][color=Blue]goto [/color][color=Black]main
      [/color][color=Blue]end if[/color]
[color=Green];#rem
      [/color][color=Blue]output c.3
      high c.3
      pulsout c.3[/color][color=Black],[/color][color=Navy]50
      [/color][color=Blue]input c.3
      pause [/color][color=Navy]100
      [/color][color=Blue]goto [/color][color=Black]main[/color]
[color=Green];#endrem    
      [/color][color=Blue]low b.0
      let [/color][color=Purple]w0 [/color][color=DarkCyan]= [/color][color=Navy]0
      [/color][color=Blue]let [/color][color=Purple]w1 [/color][color=DarkCyan]= [/color][color=Navy]0
      [/color][color=Blue]let [/color][color=Purple]w2 [/color][color=DarkCyan]= [/color][color=Navy]0
      [/color][color=Blue]let [/color][color=Purple]w3 [/color][color=DarkCyan]= [/color][color=Navy]0
      [/color][color=Blue]for [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]to [/color][color=Navy]4 [/color][color=Green]; die 4 Frequenzen
            [/color][color=Blue]debug
            pause [/color][color=Navy]1000  
            [/color][color=Blue]select case [/color][color=Purple]b0
                  [/color][color=Blue]case [/color][color=Navy]1
                        [/color][color=Blue]let [/color][color=Purple]b7 [/color][color=DarkCyan]= [/color][color=Navy]50
                        [/color][color=Blue]setfreq m4
                  case [/color][color=Navy]2
                        [/color][color=Blue]let [/color][color=Purple]b7 [/color][color=DarkCyan]= [/color][color=Navy]100
                        [/color][color=Blue]setfreq m8
                  case [/color][color=Navy]3
                        [/color][color=Blue]let [/color][color=Purple]b7 [/color][color=DarkCyan]= [/color][color=Navy]200
                        [/color][color=Blue]setfreq m16
                  else
                        let [/color][color=Purple]b7 [/color][color=DarkCyan]= [/color][color=Navy]400
                        [/color][color=Blue]setfreq m32
                  endselect
            for [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]1 [/color][color=Green]; Art der Pulserkennung f?r pulsin
                  [/color][color=Blue]for [/color][color=Purple]b2 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]to [/color][color=Navy]100 [/color][color=Green]; Pause zwischen pulsout und pulsin
                        [/color][color=Blue]output c.3
                        high c.3
                        pulsout c.3[/color][color=Black],[/color][color=Purple]b7
                        [/color][color=Blue]input c.3
                        pauseus [/color][color=Purple]b2
                        [/color][color=Blue]pulsin c.3[/color][color=Black],[/color][color=Purple]b1[/color][color=Black],[/color][color=Purple]w2
                        [/color][color=Blue]pause [/color][color=Navy]800
                        [/color][color=Blue]if [/color][color=Purple]w2 [/color][color=DarkCyan]<> [/color][color=Navy]0 [/color][color=Blue]then
                              high b.0
                              exit
                        end if
                  next
                  if [/color][color=Purple]w2 [/color][color=DarkCyan]<> [/color][color=Navy]0 [/color][color=Blue]then
                        exit
                  end if
            next                          
            if [/color][color=Purple]w2 [/color][color=DarkCyan]<> [/color][color=Navy]0 [/color][color=Blue]then
                  exit
            end if
      next        
      debug
      pause [/color][color=Navy]1000
      [/color][color=Blue]goto [/color][color=Black]main   [/color]
[HR][/HR]
When i am execute the Code between #rem and #endrem i get this Picture from my Oscilloskope:
DS18B20 Oszi.jpg
So i think the pulses are ok: PICAXE send a 500us-Pulse and then after a pause 20us the DS18B20 answers with a 100us-Pulse.

But when i execute the normale Coding (with #rem #endrem is active) the "pulsin"-command can't get the answer-pulse from DS18B20.
Word w2 is value 0 and pin b.0 is value LOW after program ending.

Is there a friend they can say me why this is so?

Many greetings from sunny Vienna:)
Harald
 

AllyCat

Senior Member
Hi Harald,

Welcome to the forum.

PICAXE send a 500us-Pulse and then after a pause 20us the DS18B20 answers with a 100us-Pulse.
I haven't examined your code in detail, but the issue is probably that it will take much longer than 100 us before the PICaxe reads the data line. Each PICaxe instruction takes typically 400 us to execute. Try outputting a pulse (perhaps on another pin) where the read instruction is located in the code. Also beware that DEBUG takes a very long time to execute.

Cheers, Alan.
 

HaraldWien

New Member
Thank's for your answere Alan!
I've been thinking that it is a timing issue.
But how is it done with the Basic command "readtemp".
I there no handshake-procedure?
What means "Try outputting a pulse (perhaps on another pin) where the read instruction is located in the code".
Please give me a code-example.
 

Buzby

Senior Member
... But how is it done with the Basic command "readtemp". Is there no handshake-procedure ? ...
The firmware inside the PICAXE handles all the handshaking and fast bit manipulation. All this work is 'hidden' in the 'readtemp' instructions.

It is this high level of firmware complexity that slows the PICAXE, but that's the trade-off for having such an easy learning curve.
 

HaraldWien

New Member
I can see one now that it's better for it to use a PICAXE-ooX2.
But I wanted to at least make the handshake with the PICAXE-ooM2.
Next week I get my PICAXE-20X2, then I will order further test the 1-Wire functions.
Thank you
Harald
 

AllyCat

Senior Member
Hi Harald,

What means "Try outputting a pulse (perhaps on another pin) where the read instruction is located in the code".
Please give me a code-example.
That was intended purely as a test to see approximately when the input instruction would "look" at the signal line. If you have a double-beam scope or logic analyser then send the pulse to a "spare" pin (or perhaps narrow pulses each side of the input command) to act as a "marker" where the input occurs. For example:
Code:
;#rem
      output c.3            ; Note: This instruction may not be needed because "High" automatically sets the pin as an Output
      high c.3
      pulsout c.3,50
      PULSOUT c.4,1     ; TEST:  This pulse shows (approximately) when the original input command would be executed
      input c.3               ; This is now delayed (even longer) by inserting the test Pulsout
      PULSOUT c.4,1      ; TEST:  This pulse indicates how long the group of instructions takes to execute 
      pause 100    
      goto main
Cheers, Alan.
 
Top