Shop OBEX P1 Docs P2 Docs Learn Events
Minimum Time needed for Input on Board of Education? — Parallax Forums

Minimum Time needed for Input on Board of Education?

cljennacljenna Posts: 10
edited 2006-06-28 20:05 in BASIC Stamp
I am using a Board of Education and have an input signal which goes low for 1/500 of a second; this is supposed to trigger a loop in my code, but it doesn't. Does anyone know the minimum amount of time a signal needs to be low for the Board of Education to recognize it as low?

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-26 15:07
    Hello,

    ·· How long it takes to execute each instruction within your loop will determine that for the most part.· Obviously there is a minimum possible time, and the following link will help you calculate that.· If you are unable to meet that timing and catch the pulse you will need to use a 555 timer as a pulse stretcher.· You can find circuits for this using Google.· I hope this helps.

    http://www.emesystems.com/BS2speed.htm

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • cljennacljenna Posts: 10
    edited 2006-06-26 17:21
    I just want to make sure you understand the problem. Even with no content in my loop, the Board of Education doesn't recognize the "Low" of the camera (I attached an oscilloscope to the output; it stays high the whole time). I'm confused as to how this is a code issue. It seems to me the·BASIC Stamp·would have some kind of internal time value which it needs a signal duration to be before it recognizes it. I bought a 555 timer chip and am in the process of wiring it, however, I need to come up with a desired signal duration before I can choose a capacitor and a resistor (per a formula from·the link you posted). It would be helpful to know the minimum accepted signal duration so that I can wire the 555 chip with that in mind. Please correct me if I'm wrong or on the totally wrong path.
  • FranklinFranklin Posts: 4,747
    edited 2006-06-26 17:38
    Could you attach the code and if you can a scope trace of the input you are trying to capture? It might help in the solving of your problem. Looking at the chart in the link it looks like 140 us is what it takes to execute an input.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-06-26 18:10
    A loop like this
    DO : LOOP WHILE in0
    ' stuff

    will always catch a low level of duration of 700 microseconds. What code are you using to detect the level?

    There are other tricks.

    DO : RCTIME 0,1,wx : LOOP UNTIL wx

    Can respond to a very brief pulse, microseconds long, but there is a fintie probablility (<1%) that the pulse will be missed (If it happens at the wrong place in the DO loop.).

    You don't need a 555 necessarily to stretch a pulse. A capacitor or RC on the input in parallel with the switch can be sufficient to stretch the pulse.

    Are you using a BS2? I ask because the BS2p has additional instructions available in the POLLWAIT group.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-26 18:12
    In order for the BASIC Stamp to detect the LOW, it first has to be HIGH.· Do you know if that device holds the line HIGH or do you need to provide a pull-up resistor?· I understand what you're trying to do, but if the BASIC Stamp cannot catch that pulse, you will need to use a pulse stretcher.· As noted, seeing the code would help, since if you have a lot going on in your loop you may never get to the pulse in time even with the pulse stretcher.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • cljennacljenna Posts: 10
    edited 2006-06-26 18:12
    The code is below; it is fairly short (the pauses are all defined seperately because at some point, we wanted to vary them, we have them all at 1/30 s for simplicity). It might help·you to know that the code is controlling a beam shutter for a laser.·Unfortunately, we were using an oscilloscope from the 1950's, so I can't attach a scan. The camera signal is basically cycling·high for 1/30 of a second, and somewhere in that cycle, it drops low for 1/500 of a second. We just want to be able to read that voltage drop. Could you explain to me how this is a code issue; I still don't understand?

    camera·· PIN 0
    shutter· PIN 15

    INPUT camera
    OUTPUT shutter

    pause1· CON 33
    pause2· CON 33
    pause3· CON 33
    pause4· CON 33

    remainder CON 33

    Main:
    · IF (camera=0) THEN
    ··· PAUSE pause1
    ··· HIGH shutter
    ··· PAUSE pause2
    ··· LOW shutter
    ··· PAUSE pause3
    ··· HIGH shutter
    ··· PAUSE pause4
    ··· LOW shutter
    ··· PAUSE remainder
    · ELSE
    ··· LOW shutter
    · ENDIF
    ··· GOTO Main
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-26 18:16
    Your loop may be taking to long to complete.· Try the following code and see if it helps.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    Camera    PIN   2
    Shutter   PIN   10
    pause1    CON   33
    pause2    CON   33
    remainder CON   4000
    Main:
      LOW Shutter
      DO : LOOP UNTIL camera = 0
      PAUSE pause1
      HIGH Shutter
      PAUSE pause2
      LOW shutter
      PAUSE remainder
    GOTO Main
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-26 18:18
    The following code may be slightly faster.· I hope this helps.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    Camera    PIN   2
    Shutter   PIN   10
    pause1    CON   33
    pause2    CON   33
    remainder CON   4000
    Main:
      LOW Shutter
      DO : LOOP WHILE camera = 1
      PAUSE pause1
      HIGH Shutter
      PAUSE pause2
      LOW shutter
      PAUSE remainder
    GOTO Main
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • cljennacljenna Posts: 10
    edited 2006-06-26 18:28
    Yeah, you had suggested that code (do while loop)·to me over the phone. I tried it, and the shutter still didnt't activate; i.e. the board never sensed the low. I just tried the do-until loop...didn't work either.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-26 18:35
    Are you able to verify the HIGH/LOW state coming into the Stamp I/O pin?· Is it normally HIGH then goes LOW?· If that part works properly then you will need a pulse stretcher using a 555 timer to accomplish this.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • cljennacljenna Posts: 10
    edited 2006-06-26 18:39
    Yeah, we attached the oscilloscope to the camera itself, and it was definitely consistently HIGH except for a very small time when it went LOW. Now that I know I need the 555 timer, what duration do you think I should stretch the signal·to be safe and sure it's read? I really don't care if I miss some LOW pulses in the mean time, as long as I can pick up the next pulse.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-26 18:46
    According to our calculations you shouldn't even need the pulse stretcher (555).· You pulse translates to 2 ms which should be okay.· Exactly what voltages are coming in for this signal?· In other words, what is the output you are reading in volts?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • cljennacljenna Posts: 10
    edited 2006-06-26 19:28
    OK, I called the manufacturer and they say the camera goes from +5V to 0V and stays at 0V for only 31 microseconds, which is considerably shorter than the 1/500 s originally reported. Is this fast enough to require a 555 timer?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-26 19:37
    Definately...That is too short...The scope should be able to show you that time.· Anyway, you will need a pulse stretcher.· There are a few ways to do it, but a 555 timer chip is the most common.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-26 19:40
    Here are a few example links of people using the 555 timer as a pulse stretcher...

    http://members.aol.com/rjb0343/Z3801A/Accurate1PPS.htm

    http://www.wiseguysynth.com/larry/users/mark1/trigger.htm

    http://absolutesilence.blogspot.com/2006/06/555-timers.html

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-06-26 20:19
    Try this code:

    result VAR WORD
    DO : RCTIME camera,1,result : LOOP UNTIL result
    



    This loop spends most % of its time looking at the pin, and when the pin goes low, it returns a non-zero value and drops out of the loop. Like I mentioned in an earlier post, there is a small probablility (<1%) that the loop will miss a given pulse, but you indicated that that might be acceptable. You could alternatively use PULSIN instead of RCTIME.

    An alternative is the following pulse stretcher, simpler than a 555:

    attachment.php?attachmentid=42242

    The code must reset the stretcher as follows:

    HIGH camera  ' charge the 100pf
     INPUT camera
    DO : LOOP WHILE camera
    



    The purpose of the 1k resistor is to limit current into the camera switch. The diode is necessary if the level from the camera is 5 volts to zero volts, but the diode is not necessary if the switch is N.O. or a transistor open drain or open collector. The 100pf capacitor will hold its charge and reliably hold the pin high for several seconds, so long as there are no stray current paths.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
    221 x 77 - 2K
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-26 20:46
    Tracy,

    ·· I should've known you'd have something simpler in your bag of tricks!· Thanks for the simpler (hopefully) solution.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • cljennacljenna Posts: 10
    edited 2006-06-28 17:52
    OK, sorry it took so long to reply. I really appreciate all the suggestions, I just didn't have that size capacitor or that type of diode, so I had to go buy them. So I set the circuit up as shown, and I changed my code, too. The problem now is that when I hooked the oscilloscope up in the circuit, the pulse extender is definitely extending the pulse, but instead of being high most of the time and then having a stretched low pulse, the signal is low and has a stretched low pulse, so the code isn't working I don't think because it is looking for when the signal goes low, and it's always low except for the high pulses. Do you think I wired something wrong maybe? What could cause this?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-28 17:57
    Looking at Tracy's circuit again it appears it is designed for a high pulse...Perhaps you could invert the camera signal prior to going into the resistor on the circuit?· Then you could look for a high instead of a low pulse.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • cljennacljenna Posts: 10
    edited 2006-06-28 18:03
    I don't mean to sound ignorant, but I'm a hydraulic engineer, so I need to ask, how do you invert the signal?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-06-28 18:57
    Inverter (see attached)...

    Post Edited (PJ Allen) : 6/28/2006 7:36:24 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-28 19:15
    PJ's method is one way to do it, although that schematic has the inverter facing the wrong direction.· The output of the inverter would need to go into Tracy's circuit, although I would actually be putting it on the other side completely.· But as for inverters, it's one of the most common and simple logic gates in the 74xx series.

    The 7404 is a hex inverter, as is the 7405/7406 (open-collector version) and the 7414 is a Schmitt Trigger inverter.· Many gates such as the 7400 can be an inverter as well by tying the 2 inputs together.· Instant inverter.· Of course these are all for TTL level logic.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-06-28 19:34
    OK -- I thought that P0 was an output, but it's·doing a clever RCTIME-thing (sigh), so I have deleted my previous, because I don't want anyone getting confused (more than I.)


    Post Edited (PJ Allen) : 6/28/2006 7:47:24 PM GMT
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-06-28 19:54
    Your first post indicated that the signal from the camera was normally high, and would go low for 1/500 of a second. The solutions I posted were for that situation.

    However, in a later post you say, "The camera signal is basically cycling high for 1/30 of a second, and somewhere in that cycle, it drops low for 1/500 of a second. We just want to be able to read that voltage drop.". I hadn't read that carefully. So, does that mean that the signal from the camera is normally low, and then at some point it goes high (for 1/30 second), and sometime during the 1/30 of a second, it blips low again for 1/500 second? And you have to sync your laser sequence with that 1/500 second blip? Is that a correct reading of what is going on.

    That is a different situation, and harder to deal with, as there are a couple of independent events that have to be detected. When you say "somewhere in that cycle", can you pin it down more? For example, 1/30 second is 33 milliseconds. Within that frame of 33 milliseconds could you say for sure that the 1/500 second blip would not occur within the first 3 milliseconds?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • cljennacljenna Posts: 10
    edited 2006-06-28 20:05
    The signal coming out of the camera is normally high and goes low for 31 microseconds somewhere within every 1/30 s cycle (I don't know off the top of my head where because I really can't use an oscilloscope correctly, I just know it's going low; I can call the manufacturer of the camera, though). That low is being used to sync with a beam shutter which is chopping the laser beam. This is to prevent the pictures from being "streaky" which occurs when there is too much light. However, the whole system *seems* to be working OK now. With the code you gave me and the pulse extender wired in. The whole thing has been kind of erratic, but I just tested it 10 times and each time once I plugged in the camera to the Board, the chopper began chopping, so I think the problem is solved. I'm sure I'll come into work tomorrow and something will be wrong, but for now...thank you all·so much for all the help!
Sign In or Register to comment.