Menu

DS18B20 give wrong reading every so often

mmotte
2022-07-26
2022-07-27
  • mmotte

    mmotte - 2022-07-26

    I have been working on a PID control solution using an old 16F886. It will control the temperature chamber where my amplifiers and receivers for radio astronomy are located. They drift a lot because of heat and cool. On /off control can only keep them within 0.8C. The HI measurement has a definite washboard ripple in it. Tried adding mass and location of the probe, But PID next.
    Had some DS18B20's laying around and a protoboard with a 16F886 soldered on. Tried the DS18B20 Library and the simple demo and it worked fine.

    I am enjoying working with the GCStudio. i haven't coded for a couple months. Started pasting in sections of code for the things I needed: PWM, Timer to adjust the sample time and PID execution time, Input dialogs to change parameter through Blutooth interface RS232, Read up on PID in Microchips which was a little disappointing. But I have worked around PID for 40+ years (still tune by SOP).

    As I was adding code i did not notice the input from the DS18B20 was messing up every now and again. and it was getting worse. I started to focus on that when I would put the PID into "Auto" the output would slam around and not even try to work. I worked on this for 2 days, trying to just get the input to read steady. commented out pieces of code, Put lots of HSerPrints everywhere, looked at the DS18B20.h code. Why does it mess up in my program but not in the demo??

    Tonite I commented out the timer/RTC interrupt( I had overlooked it because it was not in my main code) and it straightened out. Aha! The interrupt was messing with the "readtemp12" routine. The fix was to shut off interrupts when reading temperature and restart them after. IntOff IntOn ..... so that is what you use those commands for!? See attached files.

    BR
    Mike

     
  • Anobium

    Anobium - 2022-07-27

    A really good story that explains how pieces of the solution code interact with each other.

    Interrupts handling is key to any solution. As you know. :-)

    Thank you for the post.


    Good to hear you are enjoying GCStudio.

     
  • kent_twt4

    kent_twt4 - 2022-07-27

    Never argue with a result that works!

    Another thought is (if you want to go there), is to do the work inside the RTC interrupt. I have done this with a DS1307 RTC in combo with the DS18b20. Used the 1 sec square wave output for the interrupt, start the ds18b20 conversion, then comeback a second later to read the conversion results, start the next conversion, and so on.

    The conversion complete flag could also be polled in Main: to read the results, if there was reason to do so, just guessing here.

    Would take deconstructing the .h file to say two different subs.

     

Log in to post a comment.