problem with DS18S20

General discussion on mikroBasic for AVR.
Post Reply
Author
Message
volcane
Posts: 5
Joined: 13 Jul 2008 19:47

problem with DS18S20

#1 Post by volcane » 13 Jul 2008 20:10

Hi!

I am using samples from the maxim DS18S20+PAR and does not work, with DS18S20+ works well, the file I'm using is one_wire_ds18x20.abas for the compiler MikroBasic for AVR.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#2 Post by yo2lio » 13 Jul 2008 20:25

Hello,

This library don't work with temperature sensors in parasite power mode.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

volcane
Posts: 5
Joined: 13 Jul 2008 19:47

#3 Post by volcane » 13 Jul 2008 20:54

Hi!

some indication on how to change it?

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#4 Post by yo2lio » 13 Jul 2008 21:09

I use my library for parasite power mode, unfortunately is written for PIC MCU.

Code: Select all

module OneWire_base1

implements

Sub Function Ow_Reset_(Dim Byref pp_port as Byte, Dim pin as Byte) as Boolean
Dim Save_INTCON, Save_PRODH, Save_PRODL as Byte
  Save_INTCON = INTCON And $C0
  INTCON = INTCON and $3F
  Save_PRODH = PRODH
  Save_PRODL = PRODL
  FSR2Ptr = @pp_port
  FSR1Ptr = @pp_port + 18
  PRODH = 1 << pin
  ASM                        ' OW_HIZ
    movf PRODH,w
    iorwf INDF1,f
  End ASM
  result = false
  Delay_uS(2)
  ASM                        ' OW_LO
    comf PRODH,w
    andwf INDF1,f
    comf PRODH,w
    andwf INDF2,f
  End ASM
  Delay_uS(500)
  ASM                        ' OW_HIZ
    movf PRODH,w
    iorwf INDF1,f
  End ASM
  Delay_uS(70)
  If (INDF2 And PRODH) = 0 Then result = true End If
  Delay_uS(430)
  PRODH = Save_PRODH
  PRODL = Save_PRODL
  INTCON = INTCON Or Save_INTCON
End Sub

Sub Procedure Ow_Write_(Dim Byref pp_port as Byte, Dim pin, data as Byte)
Dim i, Save_INTCON, Save_PRODH, Save_PRODL as Byte
  Save_INTCON = INTCON And $C0
  INTCON = INTCON and $3F
  Save_PRODH = PRODH
  Save_PRODL = PRODL
  FSR2Ptr = @pp_port
  FSR1Ptr = @pp_port + 18
  PRODH = 1 << pin
  PRODL = data
  i = 0
  While i < 8
    ASM                    ' OW_LO
      comf PRODH,w
      andwf INDF1,f
      comf PRODH,w
      andwf INDF2,f
    End ASM
    Delay_uS(3)
    If PRODL.0 = 1 Then
      ASM                ' OW_HIZ
        movf PRODH,w
        iorwf INDF1,f
      End ASM
    End If
    ASM
      rrncf PRODL,f
    End ASM
    Delay_uS(60)
    ASM                    ' OW_HIZ
      movf PRODH,w
      iorwf INDF1,f
    End ASM
    Delay_uS(2)
    Inc(i)
  Wend
  PRODH = Save_PRODH
  PRODL = Save_PRODL
  INTCON = INTCON Or Save_INTCON
End Sub

Sub Procedure Ow_Write_PullUp_(Dim Byref pp_port as Byte, Dim pin, data as Byte)
Dim i, Save_INTCON, Save_PRODH, Save_PRODL as Byte
  Save_INTCON = INTCON And $C0
  INTCON = INTCON and $3F
  Save_PRODH = PRODH
  Save_PRODL = PRODL
  FSR2Ptr = @pp_port
  FSR1Ptr = @pp_port + 18
  PRODH = 1 << pin
  PRODL = data
  i = 0
  While i < 8
    ASM                    ' OW_LO
      comf PRODH,w
      andwf INDF1,f
      comf PRODH,w
      andwf INDF2,f
    End ASM
    Delay_uS(3)
    If PRODL.0 = 1 Then
      ASM                ' OW_HIZ
        movf PRODH,w
        iorwf INDF1,f
      End ASM
    End If
    ASM
      rrncf PRODL,f
    End ASM
    Delay_uS(60)
    ASM                    ' OW_HIZ
      movf PRODH,w
      iorwf INDF1,f
    End ASM
    Delay_uS(2)
    Inc(i)
  Wend
  ASM                    ' OW_HI and output, Strong PullUp
    movf PRODH,w
    iorwf INDF2,f
    comf PRODH,w
    andwf INDF1,f
  End ASM
  PRODH = Save_PRODH
  PRODL = Save_PRODL
  INTCON = INTCON Or Save_INTCON
End Sub

Sub Function Ow_Read_(Dim Byref pp_port as Byte, Dim pin as Byte) as Byte
Dim i, Save_INTCON, Save_PRODH, Save_PRODL as Byte
  Save_INTCON = INTCON And $C0
  INTCON = INTCON and $3F
  Save_PRODH = PRODH
  Save_PRODL = PRODL
  FSR2Ptr = @pp_port
  FSR1Ptr = @pp_port + 18
  PRODH = 1 << pin
  PRODL = 0
  i = 0
  While i < 8
    ASM                    ' OW_LO
      comf PRODH,w
      andwf INDF1,f
      comf PRODH,w
      andwf INDF2,f
    End ASM
    Delay_uS(2)
    ASM                    ' OW_HIZ
      movf PRODH,w
      iorwf INDF1,f
    End ASM
    Delay_uS(5)
    If (INDF2 And PRODH) <> 0 Then PRODL.0 = 1 End If
    ASM
      rrncf PRODL,f
    End ASM
    Delay_uS(60)
    Inc(i)
  Wend
  result = PRODL
  PRODH = Save_PRODH
  PRODL = Save_PRODL
  INTCON = INTCON Or Save_INTCON
End Sub

end.
I don't have time to translate this for AVR.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

volcane
Posts: 5
Joined: 13 Jul 2008 19:47

#5 Post by volcane » 13 Jul 2008 21:16

Hi!

thanks for the information, I see that you used assembler.

Best regards

Post Reply

Return to “mikroBasic for AVR General”