Hysteresis.. How to do it??


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    [QUOTE=hoopstar;34279]
    Code:
            if temp >= 80 then gosub fan1on         ' fan ON at 80 
            If temp <> 70 then gosub fan1off        ' fan OFF at 70
    Look at your original code...it doesn't make any sense.
    If the temp is above 80, the fan kicks on...BUT...
    if the temp is anything EXCEPT 70, the fan kicks off...

    Change it to:
    if temp => 80 then gosub fan1on
    if temp <= 70 then gosub fan1off

    Which is basically what you had in the first place. But I think you are sampling far too often. And I'd also throw a counter in there somewhere...something like if the temp is below 70 and you've checked XX number of times, then turn the fan off. (same thing with fan on). That way it'll keep from clicking on and off too often when the temp is right at the switch point.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I think the answer to you problem would be to make fan1on a loop not a return.

    Stay in that loop until the temp drops below the set point.

    Move the ADC commands to a GOSUB and then you can sample from anywhere and have less code.

    This example is using two probes on a 18F4320.

    CHECK:
    T1 = temp1*2
    T2 = temp2*2
    LCDOUT $FE,1,"INSIDE ",#T1
    lcdout $FE,$C0,"OUTSIDE ",#T2
    gosub getT1
    gosub getT2
    if T1 > T2 + 10 then BLINK
    goto CHECK

    BLINK:
    LCDOUT $FE,1,"INSIDE ",#T1
    lcdout $FE,$C0,"OUTSIDE ",#T2
    high PORTD.0
    LOW PORTD.1
    pause 100
    low PORTD.0
    HIGH PORTD.1
    pause 100
    if T1 = T2 THEN DARK
    gosub getT1
    gosub getT2
    goto BLINK

    DARK:
    low PORTD.0
    LOW PORTD.1
    goto CHECK
    getT1:
    ADCON0=$1 '%00000001 AN0
    gosub getAD
    temp1 = ADRESH
    return

    getT2:
    ADCON0=$5 '%00000101 AN1
    gosub getAD
    temp2 = ADRESH
    return

    getAD:
    pause 50
    ADCON0.1 = 1
    pause 50
    return

    end

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,143


    Did you find this post helpful? Yes | No

    Default

    Also you could use a variable as a hysterisis.

    hyst_high var byte
    hyst_low var byte

    hyst_low=0
    hyst_high=0

    ....
    ....

    if temp >= 80+hyst_high then gosub fan1on ' fan ON at 80
    if temp <= 70+hyst_low then gosub fan1off


    fan1on:
    hyst_high=5
    hyst_low=0
    ...
    ...
    return

    fan10ff:
    hyst_low=5
    hyst_high=0
    ...
    ...
    return

    Ioannis

  4. #4
    Join Date
    Mar 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Thumbs up

    Quote Originally Posted by mackrackit View Post
    I think the answer to you problem would be to make fan1on a loop not a return.

    Stay in that loop until the temp drops below the set point.

    Move the ADC commands to a GOSUB and then you can sample from anywhere and have less code.
    I do plan on using GOSUB's but at the moment I am using the demo version of PicBasic and can't really afford to step up to Pro (poor student) so am just qualifying my code/ideas within the line limit of the demo version.

    I *really* appreciate all the help and input on this - thanks guys.


    Hoops

Similar Threads

  1. hysteresis control
    By hyeniyurt in forum Off Topic
    Replies: 0
    Last Post: - 25th February 2009, 22:37
  2. Replies: 14
    Last Post: - 26th September 2007, 05:41
  3. ADC on 12f675?
    By peu in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 16th March 2005, 17:44

Members who have read this thread : 0

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