18F4420 and 1-Wire


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198

    Default 18F4420 and 1-Wire

    A lack of program space has forced me to upgrade from the 16F677A to the 18F4420. For the most part this has been fairly easy, but I have had an issue that makes me question the entirety of a very tenuous pyramid of knowledge… code that previously worked well with a DS18B20 1-Wire device now locks up –hanging, I believe at the “Waitloop”. The code is microEngineerings 1-Wire example code; other relevant bits also posted.
    Anyone able/ willing to point out what I’ve missed?

    This cut/ pasted from the relevant *.LST:
    Code:
    __CONFIG    _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
    __CONFIG    _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
    __CONFIG    _CONFIG4L,  _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
    Here my registers:

    Code:
    '-----REGISTERS SET------------------------------------------------------------
    CMCON = %00000111                                                                															
    TRISA = %00011111                                                               
    TRISB = %00111111                                                              
    TRISC = %00010000                                                               
    TRISD = %00000000                                                               
    TRISE = %00000000
    ADCON0.0 = 1
    ADCON1 = %00001011   								                           
    ADCON2 = %10110101
    Here Variables:
    '-----THERMOMETER
    Code:
    DQ VAR PORTC.6
    TEMP VAR WORD
    OLD_TEMP VAR WORD
    COUNT_REMAIN VAR BYTE
    COUNT_PER_C VAR BYTE
    MIN_TEMP VAR WORD
    MAX_TEMP VAR WORD
    And last, the actual 1-Wire routine:
    Code:
    '-----THERMOMETER READ
    GET_TEMP:
      OWOUT DQ, 1, [$CC, $44]
      WAITLOOP:
      OWIN DQ, 4, [COUNT_REMAIN] 
      IF COUNT_REMAIN = 0 THEN WAITLOOP  
      OWOUT DQ, 1, [$CC, $BE]
      OWIN DQ,0, [TEMP.LOWBYTE, TEMP.HIGHBYTE, SKIP 4, COUNT_REMAIN, COUNT_PER_C]
      TEMP = (((TEMP>>1) * 100) - 25) + (((COUNT_PER_C - COUNT_REMAIN) * 100) / COUNT_PER_C)
      TEMP = (TEMP */ 461) + 3200
    RETURN
    I RTFM, and looked for some working code and tutorials, but ran into some discussion regarding issues with clock speeds over 4mHz... apparently at some point this issue was resolved by mE. I suspect there must be something in my CONFIG as the code seems pretty straightforward and works well on an '877A

    I'd appreciate any thoughts...

  2. #2
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: 18F4420 and 1-Wire

    Why is it that enlightenment always comes 15 seconds AFTER I post rather than 15 seconds before? Got it, thanks for listening.

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: 18F4420 and 1-Wire

    That's a great statement ! Thanks for sharing it and the post above. For the sake of others in the future would you please post the problem you found?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: 18F4420 and 1-Wire

    Oscillator speed too high?

    Forgot to disable an analog feature?

    Robert
    Last edited by Demon; - 22nd March 2015 at 14:13. Reason: typo

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: 18F4420 and 1-Wire

    Hi, Amoque

    something rings my bell,here ...

    your code is written for DS1820 and you are stating you use a DS18B20 ... ( see the "count_remain" & "count_per_C" use ... )

    Both datasheets have little differences ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: 18F4420 and 1-Wire

    Yes, of course.

    I forgot the pull-up resistor (4K7) when designing the board. I had intended to add it at the "plug" end of the cable, then forgot that as well; without this pull-up the "Waitloop" never exits. Once the hardware was correct, the temperature readings were suspiciously low (I suspect for the reasons Alain suggests). "Room temperature" reading was 62F, but my analog thermometer read closer to 70F; placing the sensor under my arm should have demonstrated somewhere near 98F, but the measured value was only 85F. Bruce's (Reynold's Electronics) conversion routine gives more accurate results:

    Dummy = Raw_Temperature * 1125
    Raw_Temperature = DIV32 100
    Raw_Temperature = Raw_Temperature +3200
    Temp_in_F = Raw_Temperature

    While I cannot verify that this formula yields precise results, room temperature reading of 69.14 was much closer to thermometer reading 0f 70; and under arm reading rose to 97+.
    Last edited by Amoque; - 22nd March 2015 at 12:50.

  7. #7
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: 18F4420 and 1-Wire

    4K7 seems to be a bit on the high side, I have always used 2k2 for my pullups. Maybe a reason?
    Dave Purola,
    N8NTA
    EN82fn

  8. #8
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: 18F4420 and 1-Wire

    The datasheet calls for a "strong" pull-up and recommends 4K7; I searched the internet and saw others having success with this value. I have no knowledge or experience that suggests a better value, so I tried it and it seems to work well.

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: 18F4420 and 1-Wire

    Quote Originally Posted by Dave View Post
    4K7 seems to be a bit on the high side, I have always used 2k2 for my pullups. Maybe a reason?
    a very good reason is the cable length between the probe and the PCB ....

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  10. #10
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: 18F4420 and 1-Wire

    I haven't tested with long wires yet:
    http://www.picbasic.co.uk/forum/showthread.php?t=17282
    but 4K7 worked at 115,200 at 64MHz in preliminary tests.

    (Diagram in post #1 is not updated, only 2 resistors used)

    Robert

  11. #11
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: 18F4420 and 1-Wire

    115,200.... What?
    Dave Purola,
    N8NTA
    EN82fn

  12. #12
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: 18F4420 and 1-Wire

    Actually the main reason for lower value resistors is when there are several devices on the bus. If you are just using one device, 4.7 K is fine and wastes less current.
    Robert, you must have posted on the wrong thread? No RS-232 in this discussion...

  13. #13
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,598


    Did you find this post helpful? Yes | No

    Default Re: 18F4420 and 1-Wire

    Quote Originally Posted by Dave View Post
    115,200.... What?
    Oops. Overly medicated apparently. LOL

Similar Threads

  1. Migrating to 18F4420
    By Amoque in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th February 2015, 14:58
  2. Please help with 1-wire DS1820
    By hatuan291 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th March 2010, 13:51
  3. one wire
    By karenhornby in forum General
    Replies: 7
    Last Post: - 18th June 2008, 20:24
  4. 1-Wire
    By WarPony in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 11th May 2008, 22:14
  5. 1-wire emulator
    By johnyman34 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 10th March 2006, 12:17

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts