WD pin up/down for toggling off a led
gio_rome
Posts: 48
Hello,
I'm working on this machine consisting in a LCD screen a buzzer and additional working LEDs. I've learned to control the backlight, the power-on (blue) led and the "careful" (yellow) led. Maintenance (red) led turns on all the time during run-time. It doesn't influence anything but it is annoying to the view, and I want to find a way to untoggle it.
Being without any documentaion I have to rely on an old code (not done by me) that seems to do the job. I 'm trying to understand a little of it so to be able to drive the unit to do my things.
It all seems to come down to this:
So the Main cogsnews this "WD" method that, among other things done in the repeat cycle, launches a 3000-time cycle that changes the status of the 6th pin (that I don't know what it is connected to).
Now, is somebody familiar with this kind of programming/electronic behaviour?
Please note that I'm not trying to disassemble anything, just to make the hardware work in absence of documentation.
Thank you
Giovanni
I'm working on this machine consisting in a LCD screen a buzzer and additional working LEDs. I've learned to control the backlight, the power-on (blue) led and the "careful" (yellow) led. Maintenance (red) led turns on all the time during run-time. It doesn't influence anything but it is annoying to the view, and I want to find a way to untoggle it.
Being without any documentaion I have to rely on an old code (not done by me) that seems to do the job. I 'm trying to understand a little of it so to be able to drive the unit to do my things.
It all seems to come down to this:
.... CON .... PinWD = 6 ' Pin Watchdog hardware .... PUB Main .... cognew(WD, @Stack5) .... PUD WD ... dira[PinWD]~~ .... repeat .... repeat 3000 !outa[pinWD] .... ....
So the Main cogsnews this "WD" method that, among other things done in the repeat cycle, launches a 3000-time cycle that changes the status of the 6th pin (that I don't know what it is connected to).
Now, is somebody familiar with this kind of programming/electronic behaviour?
Please note that I'm not trying to disassemble anything, just to make the hardware work in absence of documentation.
Thank you
Giovanni
Comments
I would imagine pinWD is connected to some hardware that is expecting to see the pin change in a certain way at certain time. If that does not happen then that hardware will reset the Propeller. Or perhaps just halt it permanently.
That is what is normally meant by "watchdog". A simple hardware function that is checking to see that your software is running OK or not.
If this thing were controlling a machine it might be important to halt everything if the software goes wrong before any damage happens.
Here's a simple approach I used on a system.
This allows you to pass a pin number and the address of a timer variable (this allows you to re-use the code in multiple cogs). For the pin you want to use with a watchdog timeout, you need to define a timer variable (long). Start the timeout cog like this:
The key to using this is to reload the timer with some value when a user-event takes place. In my app I have buttons for an LCD (my watchdog pin controls the LCD backlight). When a button is pressed I have this line of code:
...which resets the timer to 10s. What this means is that the LED will stay lit for 10s after the last button press. If it's out, another button press will re-light it. Note that pin control is based on the value of the timer; there is no direct manipulation of the pin by the foreground code.
Now, I don't know exactly what a watchdog is nor have I ever used one. The code it's just like this and that's it, with this name used. For what I understand I have your very same concerns about the code I've posted.
With this hardware (propeller connected in some way to LCD/led/buzzer/etc.) I've managed to do several other things, all without this Watchdog_pin or whatever I've taken care of excluding lockup possibility. It's just that when I do what I do I get that "disturbing red light" on and I want to understand it.
G.
In the code I showed you, the watchdog is reset by putting time into the ledtimer variable -- this is the software version of what my friend is doing. In this particular case we're just controlling a pin, but you could do anything, including a reboot of the Propeller.
BTW... when you edit code samples like you have, you make it difficult for others to help you. If you don't know what's going on in the code, post a partial version of it for others makes things quite challenging.
I often use an external watchdog chip, which amounts to a timer that is connected to the reset input of the Propeller chip. One pin on the watchdog has to be toggled from time to time, say once per second, and that resets the timer. It is like the 555 circuit Jon mentioned, but there are many watchdog chips as such. If the watchdog does not get fed by the program, it causes a reboot. Typically there is a way to disable the watchdog, for example, by leaving the toggle pin as an input, or by not initiaizing it with a first transition.
I imagine yours has some mechanism like that. Why the repeat 3000? Maybe there is a counter mechanism that is advanced like winding up a kitchen timer, and then the mechanism tick tocks back down and turns on the red light at the end. You could experiment with the numbers.
toggling the output fast enough that you don't see that it is turning off.
if you have a oscilloscope, logic analyzer or frequency counter, hook that up to the output pin to see if it is actually toggling.
(hard to see without seeing the code you are using)