Please help with code for DS18B20


Closed Thread
Results 1 to 40 of 110

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Very informative thread and funny enough something that I was hoping to work on myself as I'm looking at replacing the simple on/off thermostats that control the heating in my reptiles vivariums.

    Can someone (Alain?) post up a schematic for the project. (or settings for the EasyPIC5) - I'm looking at trying to develop this a bit further so the output is pulsed, with the mark / space ratio reducing as the set point is neared. I've used commercial on/off stats, and the temperatures are hard to control. The idea is to keep the hot spot fairly constant and below 35C max, as constant exposure to a surface above this temperature can cause a burn risk to snakes.


    With the thermometer probe placed on the shelf near the logger (it wasn't actually touching the same spot), and with the thermostats sensor in the cool part of the shelf, the thermostat was set so the digital thermometer read a max of 34C. Here's are the results - the bit you are interested in is between 18:00 hrs onwards



    Obviously the heat was conducting through the wood, which cooled slower than if the sensor was measuring air or the surface of the heater. But you can see that there is a large temperature swing between the min and max readings, and that the surface reached over 40C

    To reduce this difference I placed the two probes next to the logger directly above the heater. Here is the results, which still show the same cycling, but with a lower differential (average 5 degree C), but is more stable



    The pulse proportional stat reduces the cycling as it's not switching the heater on/off/on, it maintains a steady temperature by pulsing power to it thus the heater never cools.

    I could purchase a couple of commercial PP stats for around £100 (possibly less via mail order) but then where's the fun in that Now I know there are a lot of you experience programmers that have dabbled with PWM, so wonder if you would like to add your comments here.

  2. #2
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    In the set up below I used a commercial data logger to record the surface temp of the shelf over a 24 hr period.



    Although I had originally posted this in my post above, the forum software said I had more than 4 images ????

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Malcolm,

    Sounds like the perfect job for a PID loop.
    <br>
    DT

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi, Malc

    Do you understand the "why" of the Parallax document, now ... ???

    You'll have to place your Button Key INSIDE the vivarium ( hé,hé ... WITH the snakes !!! ) if you want a true image of your temp.

    The graphs you've shown can't be used to finely trim a regulator ... but are a good example.

    Temp measurement and moreover probes placing is a real art ... to get a nice temp regulation.

    But let's begin by the beginning :

    ALL you have to do already is in ZE Book ... with relevant code.

    We'll see details later ...

    Till then, I'll implement the PID Regulator on my existing " 84 " Thermostat ( not the one shown here, but a nicer one which is pin for pin compatible !! )

    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 " !!!
    *****************************************

  5. #5
    Join Date
    May 2008
    Posts
    33


    Did you find this post helpful? Yes | No

    Default

    Alain

    You were right as always. I hadn't the board configured properly.

    I totally forgot about the row of jumpers to set the pins pull-up or pull-down, I had it set wrong.

    Thank you

  6. #6
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Malc

    You'll have to place your Button Key INSIDE the vivarium ( hé,hé ... WITH the snakes !!! ) if you want a true image of your temp.

    Alain
    Agreed,

    I've just taken a further reading with the probes 2" from the heater, so its sampling the air temperature. Here's the result (the button logger still on the shelf as shown)



    If you ignore the fluctuations in between 10pm and 3am when the snake was out and obviously laying on the sensor, and look at the period 4am to 4pm you'll see it a lot more stable and only has a 0.2C deviation.

    DT, could you elaborate on a PID loop.

    Alain, could you provide a link to that file... I'm frantically searching for a DS1820 so I can start developing this project, but as my PBP programming is so rusty (and basic) may need you guys to offer some assistance if I get stuck (or should that be when I get stuck )

  7. #7
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    DT, could you elaborate on a PID loop.

    OK - google was my friend

    http://en.wikipedia.org/wiki/PID_controller

  8. #8
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default



    Err.... yeah...

    previous_error = 0
    integral = 0
    start:
    error = setpoint - actual_position
    integral = integral + (error*dt)
    derivative = (error - previous_error)/dt
    output = (Kp*error) + (Ki*integral) + (Kd*derivative)
    previous_error = error
    wait(dt)
    goto start
    LOL - £34 for a commercial thermostat looks more promising !

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You've got better friends than that.
    HenrikOlsson for instance ...

    PID-filter routine (2nd try).
    http://www.picbasic.co.uk/forum/showthread.php?t=5874

    I've used it. It works great.
    It's a little tricky to find the correct constants. But trial and error usually works.
    Although there is a purposeful method to tune the loop.
    <br>
    DT

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

Members who have read this thread : 3

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