Shop OBEX P1 Docs P2 Docs Learn Events
Prop go to sleep? or — Parallax Forums

Prop go to sleep? or

Goran (Sweden)Goran (Sweden) Posts: 68
edited 2007-02-19 15:47 in Propeller 1
I have not yet figured out what happens when this program i.e the code in the PUB come to its end.
I thought the pin output should remain high!
By adding a repeat I can hold high, but then I stucked in that object.
This is the whole I compile

PUB Main
·· dira[noparse][[/noparse]16] := 1
·· outa[noparse][[/noparse]16] :=1

What I want to do is as in a "normal" MPU like the AVR I have a code which via interupt toggles a pin with a LED.
The main purpose is you can se that the program is running.

Also how to implement a watchdog routine, any ideas?

Goran·

Comments

  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-02-18 13:53
    Look at the 'Repeat While {condition}'

    then within the repeat loop have an 'IF' condition to call a different Pub etc....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Necessity is the mother of invention'
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-18 14:58
    When any method (routine) reaches its end, it returns to the caller. The main routine in a program is called by the Spin interpreter and, when it returns, the interpreter stops the cog that is running. That resets all the I/O registers for the cog.

    A watchdog routine can be done by starting another cog with COGNEW which waits for some period of time using WAITCNT, then checks whatever you want, then waits again.
  • Goran (Sweden)Goran (Sweden) Posts: 68
    edited 2007-02-18 17:52
    Thanks Mike and QuattroRS4
    It start to make sense now.

    So compared with a MPU which has interupt and built in watchdog, I need to use one cog for the purpose of a watchdog.
    I have to dig in to thisrolleyes.gif
  • Stan671Stan671 Posts: 103
    edited 2007-02-19 05:39
    The Propeller does not have interrupts and it has 8 separate processors, with each being able to do it's own independent thing.· So, you will need to think of the idea of a watchdog timer/interrupt in a completely different way than you are used to with previous processors, like the AVR.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Stan Dobrowski
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-19 05:49
    Goran,
    It depends on why you want a watchdog timer. For example, a "true" watchdog timer requires the use of a cog because the timer has to run independently from anything else running. On the other hand, sometimes you just want a timeout. Since the system clock is running independently, you can easily test to see if a future time is exceeded like in this code fragment:
    t := cnt  ' save starting time
    repeat until ina  ' wait until I/O pin 1 is high
       if cnt - t > clkfreq / 10  ' use a 100ms timeout
          abort true  ' exit up call chain to marked point
    
    


    If you look in the Propeller manual under abort, you'll see that this works like "catch"/"throw" or other similar mechanisms in other languages.
  • Goran (Sweden)Goran (Sweden) Posts: 68
    edited 2007-02-19 06:34
    Thanks Mike,
    I made a small code based on your input.
    Used a new cog· with a small asm where a got both the watchdog and the LED blinking (so you can see that the program runs).
    Now I have to refine the code and test it with my main program.(debugging is sometime timeconsuming)
    Regards, Goran
  • KlossKloss Posts: 43
    edited 2007-02-19 15:11
    A watchdog that runs from the master clock?
    I'm shure that is not what you want.
    What if the clocks fails or varies in frequency?
    A watchdog should always use an independent clock.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-19 15:47
    Kloss,
    Ideally that's true. Practically, it may not be necessary. It depends on what you're protecting against. It may be that if the clock fails or varies in frequency enough to affect the "watchdog" timer, then your system has deteriorated to the point where there's nothing functioning to respond to a watchdog interrupt. There's nothing like a "fail-safe" interrupt that is never responded to.

    In the case of the Propeller, the clock circuitry is robust and unlikely to fail. It's possible for a crystal to fail under very high mechanical shock loads, but you can buy crystals designed to resist that if that's a problem. The most likely problem is a programming failure when the clock mode is changed either deliberately (to reduce power consumption) or accidently (when a program "scribbles" all over itself and the Spin interpreter essentially executes garbage). If that's a concern, I think you would need a more extensive "fail-safe" design than just an independent watchdog timer.
Sign In or Register to comment.