Shop OBEX P1 Docs P2 Docs Learn Events
Debounce timing — Parallax Forums

Debounce timing

Turnbull2112Turnbull2112 Posts: 65
edited 2009-02-10 09:01 in BASIC Stamp
I am reading an RCTIME and have a threshold set as a trip point. Example below.


DO

IF time > 5000 THEN
HIGH 5
LOW 6

ENDIF

IF time < 5000 THEN
LOW 5
HIGH 6
GOSUB flash

ENDIF

flash:

HIGH 7
PAUSE 200
LOW 7
PAUSE 200
HIGH 7
PAUSE 200
LOW 7
LOOP UNTIL time > 5000

RETURN

How would I build in a way to delay the trip point·if the process variable fluctuates under/over the setpoint? While maintaining the flasher? Adding hysteresis? Some deadband? Ideas? So far I just keep flickering on and off.

·

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-02-10 04:15
    Turnbull,
    I assume that is not a complete program, no? Both IF statements end up executing the flash routine, one because it simply drops through, and the second in a syntax warp of a GOSUB. Check the program flow.

    Hysteresis can be arranged with the following kind of statement, which creates a one bit state variable, separate from the measurement itself
    tripped  VAR bit
    time VAR Word
    k VAR Nib
    DO
      ' measurement here
      IF time>5100 THEN 
         tripped=0
      ELSEIF time<4900 THEN
         tripped=1
      ENDIF         
      IF tripped THEN
        FOR k=0 to 3
          TOGGLE 7   ' alternately high and low
        NEXT
      ENDIF
    LOOP
    



    In the space between 4900 and 5100, the value of tripped retains a value that can be either 0 or 1, depending on the direction of trend.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • metron9metron9 Posts: 1,100
    edited 2009-02-10 09:01
    You could store the values you receive in a maximum and Minimum variable. Then you would know your parameters. Once you see what you are getting for input you will know what to do.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
Sign In or Register to comment.