Shop OBEX P1 Docs P2 Docs Learn Events
Retriggerable One Shot....... — Parallax Forums

Retriggerable One Shot.......

Jeff2Jeff2 Posts: 46
edited 2010-04-11 23:33 in Propeller 1
Is there A way I can program, A Retriggerable One Shot, on the Propeller Chip? So I can adjust the RC Time. To turn on A Led, for A given time, and if the input pin is
still pressed (on and off) the led will stay on.

Comments

  • kwinnkwinn Posts: 8,697
    edited 2010-04-05 04:30
    Loop:
    Read push button input pin
    if button pressed turn led on
    else turn led off
    wait retrigger_time
  • Jeff2Jeff2 Posts: 46
    edited 2010-04-05 21:18
    So something like this.


    repeat

    dira[noparse][[/noparse]6] := 1
    dira[noparse][[/noparse]21] := 0

    outa[noparse][[/noparse]6] := ina[noparse][[/noparse]21]
    waitcnt(clkfreq/4 + cnt)
  • Jeff2Jeff2 Posts: 46
    edited 2010-04-06 03:32
    If you can help me get started
    with the program
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-04-06 03:37
    A "retriggerable" one-shot is not just a simple trigger then delay as the contributed examples shows, it must restart the one-shot on a trigger even if it is already triggered, hence retriggerable. Is this the type of action you want?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    *Peter*
  • Jeff2Jeff2 Posts: 46
    edited 2010-04-06 09:27
    So how do I make the program for
    the hence retriggerable?
  • Jeff2Jeff2 Posts: 46
    edited 2010-04-07 02:16
    Here I A circuit, is there A way that it could be programed into the Propeller Chip. So when the input is toggling, the output would be on?

    I have A Attachment on the circuit.....
    720 x 543 - 22K
  • Jeff2Jeff2 Posts: 46
    edited 2010-04-08 01:18
    I guess this can't be programed on the Propeller Chip..........A Retriggerable One Shot
  • kwinnkwinn Posts: 8,697
    edited 2010-04-08 01:43
    Jeff2, sorry, lost track of this post. The prop certainly can do this. Slight change required.

    Loop:
    Read push button input pin
    if button pressed timeout = retrigger_time + cnt
    led = on
    if cnt > timeout
    led = off

    All you need to do is translate that to spin or pasm.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-04-08 02:47
    Yes, back to your post Jeff, being a forum threads do get pushed down the list and sometimes it's just not convenient to answer although you have to admit you had already received some help anyway.

    The problem I have with your question is that on the one hand it is very simple yet on the other it depends how you want it to integrate into your program, there are so many ways and we don't have any details of your program.
    I personally would not have a program stop just to handle a button but with so many cogs that might be ok for some.

    What I normally do for these types of inputs and timing functions is simply to have a Spin/PASM function running in it's own cog that does nothing else but maintain some software timers, both countdown to zero and countup, The function usually handles specials as well as such things as button inputs and so on. Implementing a one-shot here is nothing more than reloading a countdown timer on a condition, while the counter is non-zero the output is true.

    A code snippet for detecting that the button "is" pressed and retriggering the "one-shot" (the functions repeat loop cycles through the soft timers and decrements those that are non-zero)
    ifnot ina[noparse][[/noparse]button]      ' is button input low? (same as saying "if ina[noparse][[/noparse]button] == 0")
        timer[noparse][[/noparse]0] := 500            ' reload timer 0 for 500ms
    
    



    and a snippet as to how the led would work in the timer function so that it would light while the "one-shot" was active.
    outa[noparse][[/noparse]led] := !timer[noparse][[/noparse]0]      ' turn on active-low led if timer 0 is non-zero
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    *Peter*
  • Jeff2Jeff2 Posts: 46
    edited 2010-04-08 22:26
    It has been A long time, that I have made A easy Program. So would I write it like this?

    I want to use (Pin23, as the Input switch) and (pin15 of the led)





    PUB Led Retriggerabel One Shot


    ifnot ina[noparse][[/noparse]23] ' is button input low? (same as saying "if ina[noparse][[/noparse]button] == 0")
    timer[noparse][[/noparse]0] := 500 ' reload timer 0 for 500ms

    repeat
    outa[noparse][[/noparse]15] := !timer[noparse][[/noparse]0] ' turn on active-low led if timer 0 is non-zero






    I am bad, I CANT' REMEMBER HOW TO WRITE A EASY PROGRAM........
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-04-08 23:25
    Since these timing functions are fairly common I have written a small demonstration object that you can incorporate into your program. Include a reference to this in your OBJ section and in your initialization just say:

    OBJ
    timing : "background"

    pub main
    background.start ' startup background timing functions

    So with this object you should never have to stop and wait for any events as long as you use the various timers all you need to do is load them up with an appropriate delay and then poll them for when they are zero, much like the example in the user processes section of the object itself.

    If this looks a bit daunting then maybe you should post your code so I can show you how to incorporate it.

    {  background.spin
    
              **************************************
                         BACKGROUND TICK
              **************************************
                        Peter Jakacki 2010
              **************************************
    
    Purpose:
    Implement an "interrupt style" background tick which maintains soft-timers and handles
    other low priority events so as to take the load off the main program from having to time
    events such as button presses or led blinking etc.
    
    Implementation:
    In this semi-purpose object soft-timers are decremented the equivalent of every 1ms until
    they are zero. The main program can load these timers and check when they are zero to take
    appropriate action. User routines may also be added to suit.
    
    Resources:
    cogs:           1
    variable:       36 longs
    program:        29
    
    Limitations:
    As a high-level function this Spin object cannot be called too fast so the minimum is probably around 1ms.
    A consequence of trying to go too fast will cause waitcnt to miss the cnt until it cycles around again (~65secs)
    }
    
    con
    
    ' these clock constants are normally part of the main program
    ' but are included here for testing
      _CLKMODE = XTAL1 + PLL16X
      _XINFREQ = 5_000_000
      clockfreq = ((_CLKMODE - XTAL1) >> 6) * _XINFREQ
    
    
    ' object constants
      _1mS          = clockfreq/1000                        'Divisor for  1 mS
      prescaler     = 5                                     'prescaler from 1ms tick (5ms)
      timers        = 4                                     'number of soft-timers to support
    
    ' user constants
      button        = 0                                     ' demo button input - active low
      led           = 1                                     ' demo led output - active low
      status        = 2                                     ' demo blinking status led
    
    var
      long  bgstack[noparse][[/noparse] 32 ]
      long  timer[noparse][[/noparse] timers ]
    
    pub start
       cognew(Background,@bgstack)
    
    
    pri BackGround  | i,intv
    ' user inits
      outa[noparse][[/noparse] led ]~                    ' led off
      dira[noparse][[/noparse] led ]~~                   ' led output
      ina[noparse][[/noparse] button ]~                  ' button input
    
      dira[noparse][[/noparse] status ]~~                ' using status led
    '
      longfill(@timer,0,timers)
      intv := cnt
      repeat
        ' synchronized interval wait
        waitcnt(intv += _1ms*prescaler)
    
        ' update soft-timers
        repeat i from 0 to timers-1
          if timer[noparse][[/noparse] i ]
             timer[noparse][[/noparse] i ] -= prescaler
    
        ' user processes etc
    
        ifnot ina[noparse][[/noparse] button ]           ' is button input low? (same as saying "if ina[noparse][[/noparse] button ] == 0")
          timer[noparse][[/noparse] 0 ] := 500           ' reload timer 0 for 500ms
    
        outa[noparse][[/noparse] led ] := !timer[noparse][[/noparse] 0 ]      ' activate led while timer0 is active
    
        ifnot timer[noparse][[/noparse] 1 ]         ' status led
          !outa[noparse][[/noparse]status]
          timer[noparse][[/noparse] 1 ] := 200           ' this timer could be loaded from the main program instead
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    *Peter*
  • hover1hover1 Posts: 1,929
    edited 2010-04-08 23:43
    Link to easy programs:
    http://forums.parallax.com/showthread.php?p=617192
    PS..Stop with the capital "A", it's annoying.
    PPS..If you keep the thread in one place it might get answered more often.
    Jeff2 said...




    I am bad, I CANT' REMEMBER HOW TO WRITE A EASY PROGRAM........
  • Jeff2Jeff2 Posts: 46
    edited 2010-04-11 23:33
    I have two input's, (22 and 23) I want one as, One Retriggerable One Shot, the other one as A on off switch. How do I go about adding the Retriggerable One Shot,
    to the Program, so I can adjust the Time.




    
    
    
    con 
    
     _clkmode = xtal1 + pll16x
     _xinfreq = 0_500_000
     
    pub Kid
    'dira[noparse][[/noparse]0..19]~~
    
    repeat
    
        if ina [noparse][[/noparse]22] ((((the input one pin22, need's to be  Retriggerabel One Shot, how does the progarm have to look?))))))
          right
        if ina [noparse][[/noparse]23]
             left
      
      
              
    pub right
            dira[noparse][[/noparse]0..19] := %11111111111111111111
            outa[noparse][[/noparse]0..19] := %00000000000000000000
            waitcnt(clkfreq/4 + cnt)
            outa[noparse][[/noparse]0..19] := %00000000000000000000
            waitcnt(clkfreq/4 + cnt)
            outa[noparse][[/noparse]0..19] := %00000000010000000000
            waitcnt(clkfreq/4 + cnt)
            outa[noparse][[/noparse]0..19] := %00000000110000000000
            waitcnt(clkfreq/4 + cnt)
            outa[noparse][[/noparse]0..19] := %00000001110000000000
            waitcnt(clkfreq/4 + cnt)
            outa[noparse][[/noparse]0..19] := %00000011110000000000
            waitcnt(clkfreq/4 + cnt)
            outa[noparse][[/noparse]0..19] := %00000111110000000000
            waitcnt(clkfreq/4 + cnt)
            outa[noparse][[/noparse]0..19] := %00001111110000000000
            waitcnt(clkfreq/4 + cnt)
    
    pub left
            dira[noparse][[/noparse]0..19] := %11111111111111111111
            outa[noparse][[/noparse]0..19] := %00000000000000000000
            waitcnt(clkfreq/4 + cnt)
            outa[noparse][[/noparse]0..19] := %00000000001000000000
            waitcnt(clkfreq/4 + cnt)
            outa[noparse][[/noparse]0..19] := %00000000001100000000
             waitcnt(clkfreq/4 + cnt)
            outa[noparse][[/noparse]0..19] := %00000000001110000000
            waitcnt(clkfreq/4 + cnt)
            outa[noparse][[/noparse]0..19] := %00000000001111000000
             waitcnt(clkfreq/4 + cnt)
            outa[noparse][[/noparse]0..19] := %00000000001111100000
    
    
    
    
Sign In or Register to comment.