Delay without using pause


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    I discovered what was happening. As I only have one DS18B20 used for testing, the code was running the fore next loop to read the sensors and then printing them to the screen, but as the last three were not fitted it would jump out to the sensor error and display N/C for the for vivs 2, 3 and 4. I also removed the decimal for the temps and humidity simply to make things fit on the display.

    In trying to get the LCD to display the data for viv 1 for a few seconds, then viv 2 etc I tried using case statements, and the Cvar as a counter. The idea being if the counter is between 1 and 10 it jumps to a case statement which displays data for viv 1, if it's between 11 and 20 viv 2 etc. Again that didn't work because it had to be a sub routine in order to jump back and test for sensor error.

    The problem I have in using pause statements is in order to maintain stable temperatures in the vivs, the original code was designed to run through the reading of the sensors, calculating the PID (which was based on real life testing to calibrate the values) and drive the heaters. This works well and I would like to retain that precision, and any pause statements end up delaying the read, display and update process which means the precision is lost.

    The DS18B20 and AM2302 are precise to within 0.5c so the data is stable. As we are only talking + or minus a degree or so being the difference between the PID pulsing correctly or being fully on or completely off, any delay between the read sensor cycle could mean that the heater stays on longer and the temperature overshoots. The result would be that the swing between pulses would be similar to a standard on/off thermostat rather than a pulse proportional one.

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Even basic logic doesn't seem to work !!!

    I have set Cvar as byte and to run from 1 to 40. I then have the following

    Code:
    if Cvar => 1 or Cvar =< 10 then 
        viv=0
        goto showLCD1
    endif
    
    if Cvar =>11 or Cvar =< 20 then 
        viv=1
        goto showLCD2
    Endif
    Then the following for the display

    Code:
    ShowLCD1:
    
        LCDOUT $FE,$C0,"Viv",DEC1 viv +1," "         ; print to LCD
        LCDOUT $fe,$94,dec cVar   
    goto check
        
    ShowLCD2:
    
        LCDOUT $FE,$C0,"Viv",DEC1 viv+1," "         ; print to LCD
        LCDOUT $fe,$94,dec cVar 
    goto check
    So the LCD should in theory display VIV1 and then when Cvar =11 VIV2. It doesn't !!!

    Cvar is counting up at around 1 second intervals, and there is an If Cvar >20 then Cvar =1 so it loops round, which it does. So why the hell does it ignore the IF THEN statement to match the condition and goto the correct LCD display section ! - Sometimes I hate PBP !!!!

    EDIT... seems it likes if Cvar =>11 and Cvar =< 20 then... rather than OR
    Last edited by Scampy; - 3rd May 2015 at 14:29.

  3. #3
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Malcolm,

    Try using () in the tests. Ie. "If (Cvar => 11) And (Cvar <= 20) then"
    Regards,
    TABSoft

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Thanks for the tip.

    I have it working to a degree, and test so far are encouraging

    Here's the main code

    Code:
    ;-----------------------------------------------------------------------------
    ; *****  MAIN PROGRAMMING LOOP *****
    ;-----------------------------------------------------------------------------
     
    Main:
    
    if Cvar >12 then Cvar=0
    
    LCDOUT $fe,$80+5,"Hot",$fe,$80+10,"Cool",$fe,$80+16,"Hum"
    
    Cvar=Cvar+1
    
    SetPoint1 = normtemp1
    SetPoint2 = normtemp2 
    SetPoint3 = normtemp3 
    SetPoint4 = normtemp4 
    
    gosub FlushBuffer:
    
    If SetButton=0 then                             ; jump to programming
    Gosub SetButtonRelease
    goto mainmenu
    endif
    
    If DecButton=0 then
    Gosub SetButtonRelease
    goto lightoveride                               ; manual overide of light
    endif
    
    If IncButton=0 then
    Gosub SetButtonRelease
    goto cancelalarm                                ; manual overide of alarm
    endif
    
    gosub displaytime                               ; update the clock and display the time
    
    FOR pid_Channel = 0 TO 3                        ; cycle thru all sensors
        GOSUB SelectSensor
        GIE = 0                                     ; disable interrupts before 1-wire
        @  DS1820_Convert                           ; start a temperature conversion
        GIE = 1                                     ; enable interrupts after 1-wire
    NEXT pid_Channel
    
    FOR TempWD = 0 TO 1000
        IF RCIF=1 THEN GOSUB coms                   ; Check to see id PC application connected
        PAUSE 1
    NEXT TempWD     
    
    FOR pid_Channel = 0 TO 3                        ; cycle thru all sensors
        GOSUB SelectSensor
        DS1820_Error = 0                            ; clear any previous errors
        DS1820_Flags = 0                            ; clear status flags
        GIE = 0                                     ; disable interrupts before 1-wire
          @ DS1820_Stat                             ; check the sensors status
        GIE = 1                                     ; enable interrupts after 1-wire
        PAUSEUS 20
        IF !DS1820_Done THEN SensorError            ; if it's not done by now, error
        GIE = 0                                     ; disable interrupts before 1-wire
          @ DS1820_Read                             ; get the temperature result
        GIE = 1                                     ; enable interrupts after 1-wire
        GOSUB Check4Zeros
        
        DS1820_Flags = 0
        GIE = 0                                     ; disable interrupts before 1-wire
          @ DS1820_Stat
        GIE = 1                                     ; enable interrupts after 1-wire
        IF (DS1820_Error = 0) AND DS1820_Done THEN  ; if there were no errors
            Temperatures(pid_Channel) = TempC
            pid_Error = SetPoints(pid_Channel) - TempC
            GOSUB PID
             IF pid_Out.15 THEN pid_Out = 0         ; only keep positive values
             IF ChannelPWR(pid_Channel) THEN
                HeaterDrives(pid_Channel) = pid_Out
            ELSE
                HeaterDrives(pid_Channel) = 0
    ENDIF
    IF Temperatures(pid_Channel) >  alarmhigh(pid_Channel) and Alarm = 1 then AlarmPin = 1
    IF Temperatures(pid_Channel) >  alarmhigh(pid_Channel) and Alarm = 0 then AlarmPin = 0
    IF Temperatures(pid_Channel) <=  alarmhigh(pid_Channel) then AlarmPin = 0
    IF Temperatures(pid_Channel) <=  alarmlow(pid_Channel) then AlarmPin = 0
    if Temperatures(pid_Channel) < alarmlow(pid_Channel)  and Alarm = 1 then AlarmPin = 1
    if Temperatures(pid_Channel) < alarmlow(pid_Channel)  and Alarm = 0 then AlarmPin = 0
    
     
    ELSE
        SensorError:
               HeaterDrives(pid_Channel) = 0            ; turn off heater if sensor's bad
               SensorActive(pid_Channel) = 0
            ENDIF 
    NEXT pid_Channel        
            
    If Cvar >=1 and Cvar <=3 then GOto  ShowLCD1
    If Cvar >=4 and Cvar <=6 then GOto  ShowLCD2                                      ; display info on LCD
    If Cvar >=7 and Cvar <=9 then GOto  ShowLCD3
    If Cvar >=10 and Cvar <=12 then GOto  ShowLCD4
    
    check:  
    
    
    ;   ---------------------------------------------------------------------------
    ;   check lighting periods and turn lights on or off accordingly
    ;   ---------------------------------------------------------------------------
    
        fn = 0                                                      ; select the first Lights
        if lightover = 0 then GOSUB CheckTimes                      ; if manual override set to off then go compare the programed period
        if lightover = 1 then progON=1                              ; if manual override flag set to on then lights on flag set to 1
        IF ProgON THEN                                              ; If in the program period
           IF Lights1 = 0 THEN Lights1 = 1
        ELSE
           IF Lights1 = 1 THEN Lights1 = 0 
        ENDIF
    
        fn = 1                                                      ; select the second Lights
        if lightover = 0 then GOSUB CheckTimes                      ; compare the programed period
        IF ProgON THEN
            IF Lights2 = 0 THEN Lights2 = 1
        ELSE
            IF Lights2 = 1 THEN Lights2 = 0
        ENDIF
         
    ;   ---------------------------------------------------------------------------
    ;   Check for night time drops - if condition matched, drop temp
    ;   ---------------------------------------------------------------------------
    
        fn = 0                                      ; select the first setting
        GOSUB CheckTimes2                           ; compare the programed period
        IF ProgON2 THEN
        SetPoints[0]=Droptemp[0]                    ; change the corresponding set point to the drop temperature
        ELSE
        SetPoints[0]= normtemp[0]                   ; change the corresponding drop temperature to set point
        ENDIF    
      
        fn = 1                                      ; select the second setting
        GOSUB CheckTimes2                           ; compare the programed period
        IF ProgON2 THEN
        SetPoints[1]=Droptemp[1]                    ; change the corresponding set point to the drop temperature
        ELSE
        SetPoints[1]= normtemp[1]                   ; change the corresponding drop temperature to set point
        ENDIF  
         
        fn = 2                                      ; select the third setting
        GOSUB CheckTimes2                           ; compare the programed period
        IF ProgON2 THEN
        SetPoints[2]=Droptemp[2]                    ; change the corresponding set point to the drop temperature
        ELSE
        SetPoints[2]= normtemp[2]                   ; change the corresponding drop temperature to set point
        ENDIF  
         
        fn = 3                                      ; select the fouth setting
        GOSUB CheckTimes2                           ; compare the programed period
        IF ProgON2 THEN
        SetPoints[3]=Droptemp[3]                    ; change the corresponding set point to the drop temperature
        ELSE
        Setpoints[3]= normtemp[3]                   ; change the corresponding drop temperature to set point
        ENDIF   
    
    ;-----------------------------------------------------------------------------
    ; *****  MAIN PROGRAMMING LOOP END *****
    
    GOTO Main                                
    ;-----------------------------------------------------------------------------
    And here are the four LDC routines

    Code:
    ShowLCD1:
       Pid_channel=0
        LCDOUT $FE,$C0,"Viv",DEC1 Pid_channel+1," "         ; print to LCD
        TempC = Temperatures(pid_Channel)
        gosub read_dht 
        LCDOUT $FE,$C0+5 
        TempWD = TempC : GOSUB TempToLCD                ; display TempC
        LCDOUT $DF
        if SensorActive(pid_Channel) = 0 then lcdout $FE,$C0+5,"N/C"
        LCDOUT $fe,$94,dec Cvar 
    goto check
        
    ShowLCD2:
        Pid_channel=1
        LCDOUT $FE,$C0,"Viv",DEC1 Pid_channel+1," "         ; print to LCD
        TempC = Temperatures(pid_Channel)
        gosub read_dht 
        LCDOUT $FE,$C0+5 
        TempWD = TempC : GOSUB TempToLCD                ; display TempC
        LCDOUT $DF
        if SensorActive(pid_Channel) = 0 then lcdout $FE,$C0+5,"N/C"
        LCDOUT $fe,$94,dec Cvar
    goto check
        
    ShowLCD3:
        Pid_channel=2
        LCDOUT $FE,$C0,"Viv",DEC1 Pid_channel+1," "         ; print to LCD
        TempC = Temperatures(pid_Channel)
        gosub read_dht 
        LCDOUT $FE,$C0+5 
        TempWD = TempC : GOSUB TempToLCD                ; display TempC
        LCDOUT $DF
        if SensorActive(pid_Channel) = 0 then lcdout $FE,$C0+5,"N/C"
        LCDOUT $fe,$94,dec Cvar
    goto check
        
    ShowLCD4:
        Pid_channel=3
        LCDOUT $FE,$C0,"Viv",DEC1 Pid_channel+1," "         ; print to LCD
        TempC = Temperatures(pid_Channel)
        gosub read_dht 
        LCDOUT $FE,$C0+5 
        TempWD = TempC : GOSUB TempToLCD                ; display TempC
        LCDOUT $DF
        if SensorActive(pid_Channel) = 0 then lcdout $FE,$C0+5,"N/C"
        LCDOUT $fe,$94,dec Cvar
    goto check
    OK it may be crude, have lots of duplication but it achieves the result I'm after. The good news is that whilst it's cycling around the loop and displaying values for say viv3, the PID still works fine for Viv1. I might then tidy the layout up a bit so I can get the decimals in for the temperatures, but I'm not that bothered about the decimal points - I mean I'm sure my pythons and boa don't care if it's 32.9 or 33.0 C

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    Hi,
    Even basic logic doesn't seem to work !!!
    Code:
    if Cvar => 1 or Cvar =< 10 then
    Can you tell me when the above is NOT evalutated true?
    When CVar is 0? When CVar is 8? When CVar is 11? When CVar is 25?

    EDIT... seems it likes if Cvar =>11 and Cvar =< 20 then... rather than OR
    I think YOU like it better with AND rather than OR. The compiler and the PIC likes either one equally well - and it works as expected, just not the way YOU want it to.....

    /Henrik.

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    You realise a zero value skips that whole block right?
    Speed probably is no issue here, but you’re making it work hard!
    It would matter if you’re watching a tilt sensor on a moving part or something like that.

    Code:
    If Cvar < 13 then
    If Cvar > 9 then ShowLCD4
    If Cvar > 6 then ShowLCD3
    If Cvar > 3 then ShowLCD2
    If Cvar != 0 then ShowLCD1
    endif // Cvar < 13

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Delay without using pause

    The only difference between the ShowLCDx commands is x constant?
    Code:
    Pid_channel=x
    I had a play with every consideration for the micro, and no consideration for the Human

    Code:
    i var byte; bonus loop counter
    x var byte; initial value to subtract 3 from
    
    
    x = 9
    If Cvar < 13 then
    for i = 3 to 0 step -1
    If Cvar > x then
    Pid_channel=i
    LCDOUT $FE,$C0,"Viv",DEC1 Pid_channel+1," "
    TempC = Temperatures(pid_Channel)
    gosub read_dht 
    LCDOUT $FE,$C0+5 
    TempWD = TempC
    GOSUB TempToLCD
    ; if nothing else calls TempToLCD it can go straight in here
    LCDOUT $DF
    if SensorActive(pid_Channel) = 0 then lcdout $FE,$C0+5,"N/C"
    LCDOUT $fe,$94,dec Cvar
    goto check
    ; I don’t see check in what you’ve posted
    ; but you can drop it straight here if nothing else goes there
    endif
    x = x - 3
    next i
    endif;

Similar Threads

  1. Replies: 6
    Last Post: - 28th October 2014, 06:08
  2. Do I need a pause?
    By tazntex in forum Serial
    Replies: 21
    Last Post: - 29th August 2008, 04:32
  3. 1 us delay
    By Pedro in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th February 2006, 17:28
  4. Pause
    By blue in forum General
    Replies: 7
    Last Post: - 29th December 2005, 14:24
  5. pause 0.5
    By detail in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th June 2005, 11:32

Members who have read this thread : 2

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