Shop OBEX P1 Docs P2 Docs Learn Events
delayer of sorts — Parallax Forums

delayer of sorts

VbGuruVbGuru Posts: 35
edited 2011-12-09 05:58 in BASIC Stamp
I am working on coding a time delayer of sorts. I need it to watch a pin and wait for it to change. I then need it to mimic how long the pin is high and apply it to the output pin. I have the code made for my two pots that adjust the delay from when the input goes high till the output get toggled and the delay after the input is toggled till it will be able to be toggled again. I am getting a double hit on some passes with the IR sensor and I want to filter it so I don’t get two back to back. Also while I am at it I coded a delay in the output so I could move the sensor to a better location and still have everything trigger at the correct times. I am using the Basic stamp 2. Any ideas….


Thanks !
Mat

Comments

  • FranklinFranklin Posts: 4,747
    edited 2011-12-07 19:28
    Your code and a schematic would help.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-07 19:30
    It depends on how long the time delays need to be. The Basic Stamps don't have an accessible timer. You can use a PAUSE statement as a pretty good time "tick" and the approximate execution times for some of the Basic statements are described here (follow the "app-notes" link). You can precisely time a single pulse with a PULSIN statement (to a 2us resolution), but there's no general purpose timer. For complex times that are relatively slow, you might use a time "tick" of 100ms, have a loop with an incrementing counter in it, and count the number of PAUSE 100 that get executed while you're waiting for some condition. That will give you the time in 1/10s of a second with a little error due to the execution time of other statements ... you can compensate for some of that by doing some calibration with known width pulses or even a stopwatch.
  • ercoerco Posts: 20,256
    edited 2011-12-07 19:42
    Pots, huh? I was hoping you might be making a Parallax BS2 Knock Box. Lots of other types around. This one's cute:

    http://www.instructables.com/id/Piecax-the-Poltergeist-A-Troublesome-Spirit-in-a/

    Kind of a PJ Allen thing goin' on wit dat Addam's Family theme.

    And this one: http://www.instructables.com/id/Knock-Block/

    and this one is a combination lock of sorts: http://www.youtube.com/watch?v=g4ttdTbqlyA

    Somebody better make one before I do!
  • VbGuruVbGuru Posts: 35
    edited 2011-12-08 19:07
    I was getting blown a lot of smoke over what the sensor is doing. Its and IR sensor and it runs off of 24v dc. I asked to get a copy of the data sheet and it might happen. I hope i have a better desription below of the problem. I am making this as a safety feature for myself. I scrapped the idea of copying the pulse length, after watching it they are all pretty close to the same duration (double kick happens when it flags twice within a half second of each other). I have a storagescope and ill just have to get to it and watch it a few times. I figure i can interface with the IR signal with an optical isolator or a voltage divider depending on what it ends up out putting. being as it runs on 24 dc i can us a small transtistor to output the pulse when i echo in the incoming one. Any feedback would be great!!



    not sure how to do the cool window for the code but here is mine.
    //code
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' in a nut shell i need a filter between an ir sensor and the unit so i can control
    ' the delay after the sensor senses the item till the kicker kicks so that i can
    ' eliminate the current problem of the ir sensor double kicking within a second or so
    ' of the first kick. the shortest time between tiggers should be around 3 seconds
    ' I have two pots setup on pins 12 & 13 as an easy way to vary the delays before and after.
    ' the before delay is so that i cn move the sensor to a better spot to sense at and it will
    'still allow the part to travel down the belt to the kicker before it kicks.

    'variables

    time1 VAR Word
    time2 VAR Word

    'the goods
    Main:
    DO
    HIGH 13 'For RC time on both pots pin 12,13
    PAUSE 2
    RCTIME 13, 1, time1
    HIGH 12
    PAUSE 2
    RCTIME 12, 1, time2
    DEBUG HOME, " time1 = ", DEC time1, " time2 = ", DEC time2," " ,? IN10, CR

    IF (IN10 = 1) THEN 'if a signal is sensed on pin 10 then
    PAUSE time1 'pause for variable time1 this is for
    HIGH 15 'adding a pre-kick delay so the ir sensor
    PAUSE 15 'can be put in an optimal spot before the
    LOW 15 'kicker
    ELSE 'pin 15 is the output pin that is getting
    LOW 15 'filtered. timer2 is a delay so that it will
    ENDIF 'not immediatly try and kick again (which is
    PAUSE time2 'the current ir sensors problem)
    LOOP
    code \\

    Also thanks for all the information and responses. (Im still looking into the pulsin idea, something new to learn about)
  • RiJoRiRiJoRi Posts: 157
    edited 2011-12-09 05:51
    To get the cool CODE box, put [ code ] at the beginning, and [ /code] at the end, removing the spaces between the [ and ]. You also need an endif as shown below...

    --Rich
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' in a nut shell i need a filter between an ir sensor and the unit so i can control
    ' the delay after the sensor senses the item till the kicker kicks so that i can
    ' eliminate the current problem of the ir sensor double kicking within a second or so
    ' of the first kick. the shortest time between tiggers should be around 3 seconds
    ' I have two pots setup on pins 12 & 13 as an easy way to vary the delays before and after.
    ' the before delay is so that i cn move the sensor to a better spot to sense at and it will
    'still allow the part to travel down the belt to the kicker before it kicks.
    
    'variables
    
    time1 VAR Word
    time2 VAR Word
    
    'the goods
    Main:
    DO
    	HIGH 13 'For RC time on both pots pin 12,13
    	PAUSE 2
    	RCTIME 13, 1, time1
    	HIGH 12
    	PAUSE 2
    	RCTIME 12, 1, time2
    	DEBUG HOME, " time1 = ", DEC time1, " time2 = ", DEC time2," " ,? IN10, CR
    
    	IF (IN10 = 1) THEN 'if a signal is sensed on pin 10 then
    		PAUSE time1 'pause for variable time1 this is for
    		HIGH 15 'adding a pre-kick delay so the ir sensor
    		PAUSE 15 'can be put in an optimal spot before the
    		LOW 15 'kicker
    	ELSE 'pin 15 is the output pin that is getting
    		LOW 15 'filtered. timer2 is a delay so that it will
    		ENDIF 'not immediatly try and kick again (which is
    		PAUSE time2 'the current ir sensors problem)
    	[b]ENDIF[/b] ' You need the endif in PBASIC
    LOOP
    
  • VbGuruVbGuru Posts: 35
    edited 2011-12-09 05:58
    Nice! Yeah the end if got lost in the deletion of the useless code when i posted this, it’s where it needs to be in the original though
Sign In or Register to comment.