Shop OBEX P1 Docs P2 Docs Learn Events
WD pin up/down for toggling off a led — Parallax Forums

WD pin up/down for toggling off a led

gio_romegio_rome Posts: 48
edited 2014-02-22 05:22 in Propeller 1
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:
....
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

  • Heater.Heater. Posts: 21,230
    edited 2014-02-20 06:08
    No idea. Not enough code and no hardware description, can only guess.

    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.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-02-20 08:10
    As Heater points out, the code you have does not look like a watchdog. It appears to be toggling the LED.

    Here's a simple approach I used on a system.
    pri watchdog(pin, p_timer) | t
    
      outa[pin] := 1
      dira[pin] := 1
    
      t := cnt
      repeat
        waitcnt(t += (clkfreq / 1000))                      ' wait 1ms
        long[p_timer] := long[p_timer] - 1 #> 0             ' decrement, limit to 0
        if (long[p_timer] == 0)                             ' if 0
          outa[pin] := 0                                    '   pin off
        else
          outa[pin] := 1
    


    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:
    cognew(watchdog(ledpin, @ledtimer), @wdstack)
    


    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:
    ledtimer := 10_000
    


    ...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.
  • gio_romegio_rome Posts: 48
    edited 2014-02-20 09:16
    I thank you both.

    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.
  • JonnyMacJonnyMac Posts: 9,107
    edited 2014-02-21 07:34
    A watchdog is intended to guard your system from a possible problem. I have a friend in England that uses the ubiquitous 555 timer in many systems. The timer is setup as a one-shot and his program, so long as it is running normally, constantly re-triggers it so the 555 output stays high. If his program locks up and the 555 is not re-triggered, the 555 output will eventually go low and reset his system.

    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.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2014-02-21 08:03
    Like Jon, I'd ask for more of the code in the PUB WD. I'd guess that the repeat that toggles the WDpin 3000 times is itself part of a higher level repeat loop. How often does that happen? I'd guess that some of the other items in the repeat loop are conditionals based on proper operation of the rest of the program.

    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.
  • MrBi11MrBi11 Posts: 117
    edited 2014-02-22 05:22
    If you just have a LED on the output pin, your code maybe working fine, just faster than your eye can detect.
    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)
Sign In or Register to comment.