PDA

View Full Version : Prop go to sleep? or



Goran (Sweden)
02-18-2007, 05:43 PM
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[16] := 1
·· outa[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·

QuattroRS4
02-18-2007, 09:53 PM
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 Green
02-18-2007, 10:58 PM
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)
02-19-2007, 01:52 AM
Thanks Mike and QuattroRS4 (http://forums.parallax.com/member.php?u=48147)
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 thishttp://forums.parallax.com/images/smilies/rolleyes.gif

Stan671
02-19-2007, 01:39 PM
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 Green
02-19-2007, 01:49 PM
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)
02-19-2007, 02:34 PM
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

Kloss
02-19-2007, 11:11 PM
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 Green
02-19-2007, 11:47 PM
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.