Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Stay here and do this until... — Parallax Forums

BS2 Stay here and do this until...

Donny23Donny23 Posts: 8
edited 2013-07-21 19:36 in BASIC Stamp
I'm fairly new to the BS2 and in desperate need of some help with my current project.

Here's the basic idea..

If pin 3 goes high(momentary)
then pin 4 goes high(momentary)
activate clock and count time it takes until
pin 4 goes low
then pin 3 goes low.

example: car passes 3 then 4, sits there for how long before backing out passing 4 then 3.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-06-21 18:53
    What is the clock you're activating? I didn't understand your example.
  • W9GFOW9GFO Posts: 4,010
    edited 2013-06-22 16:27
    Donny23 wrote: »
    I'm fairly new to the BS2 and in desperate need of some help with my current project.

    Here's the basic idea..

    If pin 3 goes high(momentary)
    then pin 4 goes high(momentary)
    activate clock and count time it takes until
    pin 4 goes low
    then pin 3 goes low.

    example: car passes 3 then 4, sits there for how long before backing out passing 4 then 3.

    It sounds like you want to count how long pin 4 stays high then count how long pin 3 stays high after pin 4 goes low.

    This is a start, no guarantees that the syntax is correct;
    x  VAR BYTE
    Time1 VAR Word
    Time2 VAR Word
    
    Main:
    Do
    if pin 4 = high then GOSUB CountTime
    Loop
    
    
    CountTIme:
    Time1 = 0
    Time2 = 0
    
    Do
    Time1 = Time1 + 1
    Pause 100
    Loop Until pin 4 = low
    
    Do
    Time2 = Time2 + 1
    Pause 100
    Loop Until pin 3 = low
    
    Debug Time1
    Debug Time2
    
    END
    
  • Donny23Donny23 Posts: 8
    edited 2013-06-25 18:27
    This may work however, I am not counting how long a pin stays high. What I'm looking for is basically....I have two air switches-both with a rubber hose across a drive in parallel. One is Pin 3 and the other Pin 4. A car drives in over Pin 3 then Pin 4. After passing over both the time will start counting how long it takes before the car backs back out passing over Pin 4 then Pin 3. In that order. I need to be able to see on debug hopefully, how long the car is sitting before backing back out. The car will driving over the hose not staying on them. So, the switches are only high momentarily. Hope this is a little clearer. Thanks
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-06-25 19:56
    I am by no means an expert but I am thinking a DO WHILE loop would work. If I have time over the next couple days I will try to come up with something.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-06-25 21:16
    Okay, well if I were doing this project I would probably use a DS1302 (or some other RTC) which would give you 1 second resolution for time and once you have the RTC it's a simple state-machine. The benefit of having the RTC is you could also very easily account for situations where one of the switches wasn't registered, for example, if the car didn't pull all the way in or out.
  • Donny23Donny23 Posts: 8
    edited 2013-06-26 18:13
    Thank you all. I've been considering the DS1302 but, I haven't figured out how to activate it(by switch) just to count some time and stop, without having to reset/update every time. Or, if I even have to. I only need the seconds, minutes and hours. Any ideas for this problem would be greatly appreciated.
  • SapphireSapphire Posts: 496
    edited 2013-06-26 22:24
    You can write zeros to the seconds, minutes and hours registers on the DS1302 when the first event occurs, which will reset the clock. Then when the second event occurs, read back the seconds, minutes and hours registers to see how much time has elapsed. If you really don't want to reset the chip each time, and are going to keep track of the time in your program, then you can just read the registers at the first and second events and subtract to find the difference. But doing it this way means you have to take into account possible rollover from 23:59:59 to 00:00:00 during the event. It's also possible to stop the clock by writing a 1 to the highest bit in the seconds register (the clock halt flag).
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-06-27 09:35
  • Donny23Donny23 Posts: 8
    edited 2013-07-21 19:28
    The demo ds1302 counter program works great modified. Simplified it by doubling up gosubs if both events occur. The only problems I'm having now is how to keep the times that were elapsed in the debug. So, I can come back to the computer and see for example: 3 different counts for 3 different events. In debug still show the times elapsed for each event without deleting them. And, is there a way to simply push the reset button to run the program and the debug automatically starts or run a program that initiates the debug without having to display the program code?
    I'm used to Atmel but, I'm coming to love the bs2 and parallax for many reasons including simplicity and versatility. I just hope there's a way to hide source codes if needed but let user still see the debug screen.
  • SapphireSapphire Posts: 496
    edited 2013-07-21 19:36
    Look at the formatting control characters for the DEBUG command. You can clear the screen, move the cursor, and do all sorts of things to make the display look the way you want it to.

    Pressing reset is a valid way of restarting the program. No one can see your code if you don't share it with them, because once it's downloaded to the BS2 it can't be read back. You don't need to have your source file open in the editor for the DEBUG window to function; you can open a DEBUG window without any code in the editor and still see what the BS2 is doing.
Sign In or Register to comment.