• AVR Freaks

DS18B20 temperature correct reading only in debug mode, not with production firmware

Author
mascalzone
New Member
  • Total Posts : 25
  • Reward points : 0
  • Status: offline
2015/01/15 19:24:40 (permalink)
0

DS18B20 temperature correct reading only in debug mode, not with production firmware

Hello, I am experiencing a weird behavior with temperature readings from a DS18B20 Dallas temperature sensor. I am using a dsPIC33, ICD3 for debugging/downloading the firmware, XC16 compiler and I display the temperature on the console through serial port.
The problem is that I perfectly read the temperature in debug mode, while, in production mode, I read Teamperature LSB and Teamperature MSB of the scratchpad always equal to zero  sad: sad sad

I am in big trouble because I have to deliver the firmware for the production next Tuesday. Could anyone please help me to fix this issue?  question:   [?]

Thanks a lot in advance
post edited by mascalzone - 2015/01/15 19:50:32
#1

15 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23525
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/15 19:34:07 (permalink)
    3 (1)
    Is the programmer still connected or not when you run the production firmware?
    Possibly you have a grounding problem, so it only works with the programmer/debugger connected.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    mascalzone
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/15 19:57:38 (permalink)
    0
    Thanks a lot for your quick reply ric. I tried - and I have to try in order to read the temperature during this debugging step - with the programmer cable always connected, because I transmit the temperature to the console via the serial line of the ICSP port. I tried with the ICD3 both disconnected and connected, but the result is the same.
     
    Thanks again
    #3
    Aussie Susan
    Super Member
    • Total Posts : 3612
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/15 22:28:57 (permalink)
    4 (1)
    Are the I/O lines you are using still set to 'analog'?
    When you download your code to the device in debug mode, the IDE also downloads a small 'debug kernel' that is used to actually perform the communication with the IDE. One thing that the kernel does is to set the I/O lines to digital by default, overriding the normal power-on reset state of being analog.
    Therefore, if something works correctly on a pin that has analog capability in debug mode but not in release mode (of course the debug kernel is not loaded in that situation) the you can almost bet that you are not setting the lines to digital.
    Susan
    #4
    mascalzone
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/16 11:49:07 (permalink)
    0
    Thanks Susan for your post and your good suggestion. The pin from which the dsPIC33 reads the temperature from the Dallas DS18B20 is explicitly configured as digital in my code during the system init (AD1PCFGLbits.PCFG5 = 1;), so, unfortunately, this is not the reason of that  sad: sad
    #5
    mascalzone
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/16 11:57:33 (permalink)
    0
    And, to be sure 1000%, I also set AD1PCFGLbits.PCFG5 = 1; right before running the DS18B20 routine which reads the temperature. I got the same result... sad: sad sad sad
    Does anyone have other suggestion? Thanks in advance
     
    #6
    MBedder
    Circuit breaker
    • Total Posts : 6779
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/16 12:08:28 (permalink)
    5 (1)
    What particular dsPIC are you torturing?
    #7
    ric
    Super Member
    • Total Posts : 23525
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/16 13:15:59 (permalink)
    3 (1)
    You've probably got as far as we can go by guesswork, i.e. without actually seeing the code that is failing.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    MBedder
    Circuit breaker
    • Total Posts : 6779
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/16 13:30:08 (permalink)
    4.5 (2)
    No, I expect to get a bit further. Desperately waiting for the OP's reply LoL
    #9
    mascalzone
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/16 13:40:30 (permalink)
    0
    I'm working with a dsPIC33FJ128GP706A.
    Sorry ric, I haven't well understood what you meant.
    The weird thing is that all the other printf function calls I use to write on the console are perfectly working. This means that, in production mode (but not in debug mode), the dsPIC is NOT able to read the temperature values from the DS18B20. It's like RB5 pin is configured as analog. Same effect. But I initialize it as digital in the way I reported above, and I also tried rewriting AD1PCFGLbits.PCFG5 = 1 right before running the DS18B20 routine.   question: [?]
    Any guess?
     
    Thanks so much for your help, I really appreciate that
    #10
    MBedder
    Circuit breaker
    • Total Posts : 6779
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/16 13:56:57 (permalink)
    4.67 (3)
    Bingo! Now an ultimate leading question: how many ADCs it has? LoL
    #11
    mascalzone
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/16 14:52:59 (permalink)
    3 (1)
    dsPIC33FJ128GP706A has two analog modules and 18 input channels. Thanks a lot MBedder!! wink: wink
    #12
    MBedder
    Circuit breaker
    • Total Posts : 6779
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/16 15:08:58 (permalink)
    4.5 (2)
    Then finally the award goes to... goes to... AD2PCFGLbits.PCFG5 = 1; Congrats and applauses!!! LoL
    #13
    mascalzone
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/16 15:24:38 (permalink)
    0
    ...MBedder!!!...you are greeeeaaaaaaaat!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  LoL: LoLmr green: mr greenLoL: LoLmr green: mr green
    thank you soooooooo much, you have helped me tremendously!!! you literally made my day!!! Smile: Smile
     
    But I feel embarrassed, I don't understand why it's related to ADC2. In the sense that, in the code I inherited, pin 11 (AN5/IC8/CN7/RB5) was configured and treated as ADC1 (in fact, in the ADC1 init, there was AD1PCFGLbits.PCFG5 = 0). It was an analog input because the previous temperature sensor was analog. Therefore I changed it as AD1PCFGLbits.PCFG5 = 1. Could you give me, please please please, a brief explanation?
    But wait a second! Maybe the software engineer who wrote the code I'm working on made a mistake (he doesn't work here anymore) but, since the analog pins are, by default, configured as analog, the code worked correctly. Right?
     
    thanks again MBedder!!!
     
    #14
    MBedder
    Circuit breaker
    • Total Posts : 6779
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/16 15:37:08 (permalink)
    4.5 (2)
    Both ADC1 and ADC2 share the same AN0..AN15 pins, so to make any of them digital one must set to 1 the appropriate AD1PCFGL and AD2PCFGL bits. Since your ex-sensor was analog, your ex-engineer made everything correctly, i.e. left both corresponding AD1PCFGL and AD2PCFGL bits reset to 0 (default state after RESET). Frankly speaking, most probably he just didn't touch these bits and left'em default 1s only by luck.
     
    That's the complete story for all dsPIC/PIC24 MCUs with dual ADC module.
    post edited by MBedder - 2015/01/16 16:43:35
    #15
    mascalzone
    New Member
    • Total Posts : 25
    • Reward points : 0
    • Status: offline
    Re: DS18B20 temperature correct reading only in debug mode, not with production firmware 2015/01/16 16:01:00 (permalink)
    3 (1)
    Thanks a lot for your reply MBedder. Ok I got it, so, even if I do not use ADC2, in order to have AN5/IC8/CN7/RB5 pin as digital I must set both AD1PCFGLbits.PCFG5 and AD2PCFGLbits.PCFG5 bits.
     
    thanks another time, I learned new helpful things today LoL: LoL
    #16
    Jump to:
    © 2019 APG vNext Commercial Version 4.5