Shop OBEX P1 Docs P2 Docs Learn Events
Watch dog cog — Parallax Forums

Watch dog cog

Hello All,
I am trying to write code for a watch dog cog for my project.I have tested the code and it runs with no issues. What it does is
it monitors Ina[21] and if it is "0" for more than 5.0 secs - it does try to correct it.

code starts with a "Repeat while Ina[21] == 0 " statement.When I start a new cog - cognew statement,the rest of the project works but
the watch dog cog does not seem to seem work although I have LED attached to pin 21 and is off for more than 5 secs.

I have placed the method in many other parts of the program.When placed in a method with a "Repeat loop" the watch dog method work s
but it will not execute the rest of the loop even if I make Ina{21] == 1.

I cannot figure out the problem and any help is appreciated.

Thank you

Siri

Comments

  • msiriwardenamsiriwardena Posts: 301
    edited 2015-11-19 19:34
    Here is the "Watchdog" method i am using -Hope this will help to trouble shoot.
    Pub WatchDog  |OffTime, Correction
    
       Repeat while(Ina[21] == 0)
    
           
                           
            OffTme := 0
            Correction  := 0
    
            Repeat 5                    ' 5 sec  count down- 
       
                OffTime++
               delay(1)                 '5 sec. count down starts
    
              if OffTime => 5         'if OffTme is => 5.secs
    
                Repeat 2      ' Correct 2 times
                          
                          
                      outa[21]~~          
                      outa[22..23]~
                       pause(500)          'Inspir for 0.5 secs
                       outa[21]~
                      
              
              
                       outa[22..23]~~      ' valves P22 & P23 opens
                        pause(500)         'delay for 0.5 secs
                      outa[22..23]~
                      Correction ++
    
    
                  If( Correction => 2)
                    quit   
    
    Thanks,

    Siri






  • msiriwardenamsiriwardena Posts: 301
    edited 2015-11-19 19:04
    Pub WatchDog  |OffTime, Correction
    
       Repeat while(Ina[21] == 0)
            OffTme := 0
            Correction  := 0
            Repeat 5                    ' 5 sec  count down- 
                OffTime++
               delay(1)                 '5 sec. count down starts
              if OffTime => 5         'if OffTme is => 5.secs
                Repeat 2      ' Correct 2 times
                      outa[21]~~          
                      outa[22..23]~
                       pause(500)          'delay for 0.5 secs
                       outa[21]~
                       outa[22..23]~~      ' valves P22 & P23 opens
                        pause(500)         'delay for 0.5 secs
                      outa[22..23]~
                      Correction ++
                  If( Correction => 2)
                    quit                             
    
    The method I use -using correct way to post code

    Siri

  • I think you should put another

    REPEAT

    in the first line and indent the rest of it.

    Since it is supposed to be a watchdog you do not want to run this just one time, don't you?

    Enjoy!

    Mike
  • msiriwardenamsiriwardena Posts: 301
    edited 2015-11-19 21:27
    Mike,
    No luck and watchdog do not work. Any other idea.

    Siri
  • waitpeq or waitpne are better ways to wait for a pin to change, as the cog doesn't consume
    anything like as much power.
  • kwinnkwinn Posts: 8,697
    It sounds like you want this watchdog code to run in a separate cog to continuously monitor pin 21 and set it high after 5 seconds of being low. Is this so?

    Also, can you describe exactly what you want the code after the "Repeat 2 ' Correct 2 times" statement to do.
  • msiriwardenamsiriwardena Posts: 301
    edited 2015-11-21 14:35
    @kwinn
    You are right,the watchdog cog is suppose to monitor pin21 and set it high if it has been low for more than 5 secs.
    After "Repeat2" statements- the code is suppose to continue as the the problem is corrected.To continue with this
    code running in another cog(Valve timing code)- see below
    Pub ValveControl                           'CONTROL SOLENOID VALVES DURING INTAKE
    
        dira[21..23]~~                         'Set solenoid pins as outputs
        dira[14]~~
        outa[23]~~                             'bypass solinoid is made open to avoid pressure issues from pump relief pressure
                                               'avoid back pressure as there will be NO out let if this solenoid is closed.
        pause(10)
        dira[MotorPin]~~
        pause(10)
        outa[MotorPin]~                       'Start BLDC motor
    
       
    
         Repeat
                                          'Valve CONTROL CODE
            If  Pressure1 < Intake{settable on the fly varible-global} 
              outa[21]~~            'Intake Valves open between HIGH and LOW  pressures( pressure1 =>0 {Pressure1 is a global variable}
              outa[22]~
              outa[23]~
              outa[14]~             'Intake phase - Pump valve open/ and exhaust valves close - pressure relief valveP14 closes
            
            elseif Pressure1 => Exhaust {also a settable on the fly global variable}
               outa[21]~              'Exhaust  Valves open between HIGH and LOW  pressures      
               outa[22]~~                   ' Exhaust phase ---> pump valve closes/exhaust valve opens.
               outa[23]~~
              outa[14]~~                    'BOTH Relief valves @22&23 open
            
            If Pressure1 > 15             'In case of inadvertant pressure rises > 12cm.H2O - pump is bypassed and
                outa[21]~
                 outa[22..23]~~
                outa[14]~~                 ' both pressure relief valves open to AIR
                 pause(1000)       
    

    I hope this helps to solve the issue.

    Thanks for the Help.

    Siri
  • Hello! all,
    The watch dog cog issue still remains unsolved.I am in need of solution so please give it
    a little effort.

    Thanks,

    Siri
  • kwinnkwinn Posts: 8,697
    One problem I can see is a lack of "dira" instructions to set the pins to inputs or outputs as needed. Also edited and added some comments and questions to your code and posted it below. Try it out and reply.
    Pub WatchDog  |OffTime, Correction
    
    repeat                          NEED THIS REPEAT TO KEEP WATCHDOG COG RUNNING
       Repeat while(Ina[21] == 0)
          OffTme := 0
          Correction  := 0
    
          delay(5)                  ' REPLACES THE 4 INSTRUCTIONS COMMENTED OUT BELOW                                                                  }
    '      Repeat 5                 ' 5 sec  count down- 
    '        OffTime++
    '        delay(1)               '5 sec. count down starts
    '        if OffTime => 5        'if OffTme is => 5.secs
    
              Repeat 2              ' Correct 2 times
                outa[21]~~          ' WHY ARE YOU TRYING TO SET PIN 21 HIGH? IT HAS NOT BEEN SET AS AN OUTPUT
                outa[22..23]~       ' HAVE THESE PINS BEEN SET AS OUTPUTS SOMEWHERE?
                pause(500)          ' delay for 0.5 secs
                outa[21]~           ' 
                outa[22..23]~~      ' valves P22 & P23 opens
                pause(500)          'delay for 0.5 secs
                outa[22..23]~
    {           THE 2 INSTRUCTIONS COMMENTED OUT BELOW ARE NOT NEEDED. 
                THE "Repeat 2" STATEMENT WILL ONLY EXECUTE THE STATEMENTS BELOW IT 2 TIMES                                                             }                               
    '            Correction ++
    '           If( Correction => 2)
    {           WHY QUIT AT THIS POINT? TYPICAL WATCHDOG TIMERS WOULD STOP OR SHUT OFF THE EQUIPMENT,
                SET OFF AN ALARM, OR RESET THE SYSTEM AT THIS POINT }
                quit
    
  • msiriwardenamsiriwardena Posts: 301
    edited 2015-11-25 18:45
    @kwinn,
    Thank you helping me. I tried your changes to the code but still it does not work
    The only other cog that sets the P21 is in the following code that runs in a another cog I am using only 4 other cogs
    When put the code in ValveControl loop it works but then VaalveControl stops working - only the watchdog code works
    continuously.
    Itried with and with out the "quit" - still no luck.
    
    
    Pub ValveControl                           'CONTROL SOLENOID VALVES DURING INTAKE & EXHAUST PHASE
    
        dira[21..23]~~                         'Set solenoid pins as outputs
        dira[14]~~
        outa[22..23]~~                             'bypass solinoId is made open to avoid pressure issues from pump relief pressure
                                               'avoid back pressure as there will be NO out let if this solenoid is closed.
        pause(10)
        dira[MotorPin]~~
        pause(10)
        outa[MotorPin]~                       'Start BLDC motor
    
       
    
         Repeat
                                          'Valve CONTROL COD
            If  Pressure1 < Intake
              outa[21]~~            'Intake Valves open between HIGH and LOW  pressures
              outa[22]~
              outa[23]~
              outa[14]~             'Intake phase Pump valve open/bypass valve closed and exhaust valves close 
            
            elseif Pressure1 => Exhaust
               outa[21]~              'Exhaust  Valves open between HIGH and LOW  pressures      
               outa[22]~~                   ' Exhaust phase ---> pump valve closes/bypass valve opens.
               outa[23]~~
              outa[14]~~                    'BOTH Relief valves @22&23 open
            
            elseif Pressure1 > 15             'In case of inadvertant pressure rises > 12cm.H2O - pump is bypassed and
                outa[21]~
                 outa[22..23]~~
                outa[14]~~                 ' both pressure relief valves open to AIR
                 pause(1000)       
     
    

    Thanks kwinn

    Siri



  • kwinnkwinn Posts: 8,697
    Unfortunately without being familiar with the external hardware and how you are trying to control it help is hard to provide. One thing to be aware of is that the outputs to the pins from the individual cogs are all "or'ed" together. That means that if any cog is outputting a high to a pin no other cog can change that pin to a low.
  • @kwinn
    Thanks for the help.

    Siri
Sign In or Register to comment.