November 22, 2024, 09:31:21 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Archery Timer

Started by JonnyMac, January 29, 2010, 12:29:17 PM

Previous topic - Next topic

JonnyMac

January 29, 2010, 12:29:17 PM Last Edit: February 01, 2010, 03:29:45 PM by JonnyMac
A potential customer called yesterday and inquired about creating a simple archery timer for his club.  Based on the specs he gave me I cam up with the following program.

' =========================================================================
'
'   File...... archery.bs1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2010 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 01 FEB 2010
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Trigger :: N.O. button input (e.g., push-button, relay, etc.)
'            -- connect N.O. contacts between P6.W and P6.R
'
'
' Program timing is in 0.1-second units -- timing created by input deboucne
' loop.


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  BuzzCtrl        = PIN3                  ' to relays
SYMBOL  RedLight        = PIN2
SYMBOL  YelLight        = PIN1
SYMBOL  GrnLight        = PIN0


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Red             = %00000100
SYMBOL  Yellow          = %00000010
SYMBOL  Green           = %00000001
SYMBOL  Buzzer          = %00001000


' -----[ Variables ]-------------------------------------------------------

SYMBOL  flags           = B0
SYMBOL   TrigIn         =  BIT6

SYMBOL  state           = B1
SYMBOL  debounce        = B2
SYMBOL  idx             = B3

SYMBOL  timer           = W5


' -----[ Initialization ]--------------------------------------------------

Reset:
 PINS = Red | Buzzer                           ' start with red on, short buzz
 DIRS = %00001111                              ' set output pins


' -----[ Program Code ]----------------------------------------------------

Main:
 debounce = 0                                  ' reset debounce timer
 flags = %01000000                             ' assume pressed
 FOR idx = 1 TO 20
   PAUSE 5
   flags = flags & PINS                        ' scan input
 NEXT

 BuzzCtrl = IsOff                              ' kill if running


Check_Timer:
 IF timer = 0 THEN Handle_State                ' timer running?
   timer = timer - 1                           ' yes, update


Handle_State:
 BRANCH state, (Check_Start, Do_Green, Do_Yellow)


Check_Start:
 IF TrigIn = No THEN Main                      ' have trigger?
   state = 1                                   ' yes, set state
   PINS = Green | Buzzer                       ' green on, short buzz
   timer = 900                                 ' 90 seconds

Start_Release:
 IF Trigger = No THEN Main                     ' trigger clear?
   PAUSE 100                                   ' no, wait one tick
   timer = timer - 1                           ' update timer
   GOTO Start_Release                          ' try again


Do_Green:
 IF TrigIn = Yes THEN Do_Red                   ' abort?
   IF timer > 0 THEN Main                      ' still running?
     state = 2                                 ' no new state
     PINS = Yellow                             ' yellow on
     timer = 300                               ' 30 seconds
     GOTO Main


Do_Yellow:
 IF TrigIn = Yes THEN Do_Red                   ' abort?
   IF timer > 0 THEN Main                      ' still running?
                                               ' if no, drop to Red

Do_Red:
 state = 0
 PINS = Red | Buzzer                           ' red on, short buzz
 timer = 0                                     ' clear timer for red

Abort_Release:
 IF Trigger = No THEN Main                     ' trigger clear?
   PAUSE 25                                    ' no, wait a bit
   GOTO Abort_Release                          ' and try again


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

huntmaster

February 01, 2010, 01:29:00 PM #1 Last Edit: February 01, 2010, 02:27:33 PM by huntmaster
Couple of questions - I can get a 110 - 12v converter to run auto accessories.  The starter kit comes with a 1 amp power supply.  Since I have to bring 120 into the box to run the lights, could I use the 12v auto converter to run both the board and the horn, or will the amperage be too high for the board?

Also, could you suggest a good relay for both the 110 lights and the 12v horn?  I'm looking at all electronics, and I'm not sure which ones to look at.

One last item - If startup included a beep and the red light, waiting for the start button, could a reset function be easier to use than polling the start que?  I could use a start button, and a reset button that resets the program to the very beginning.  I have the extra chanel on my remote that I ordered.  It looks like it could simplify the program, but I don't see that the system has a "reset button" so to speak.

Thanks

huntmaster

Bassically, the program would work like this:
At startup:
Red light on
Beep
wait for input

@ input
green light
beep
wait 90 seconds
green off
yellow on
wait 30 seconds
reset (goes back to startup)

Any reset would send it straight back to startup before the program has a chance to complete, which would include the ending buzzer.

Any thoughts on this?

JonnyMac

February 01, 2010, 03:40:53 PM #3 Last Edit: February 01, 2010, 03:42:37 PM by JonnyMac
The program works exactly as you describe -- though I just added the power-up beep.

This program is not easy for beginners; it's not a linear program because you have this requirement of interrupting the normal linear process at any time.  This is called a finite state machine.  The program has three states: red (no timing used), green (with timing), and yellow (with timing).  With this design the program is in a constant loop, decrementing the timer to move the program to the next state. If not in state 0 (red), pressing the trigger input kills the present state and stops the timer.

You can run this program on your demo board (thanks for the order, btw) to see it in operation -- I have.  Just copy-and-paste the code above into the BASIC Stamp editor and download into your Prop-1 with the Trainer attached.  The button on the Trainer acts as the trigger input.

On power-supplies... you don't want over- or under-voltage, or under-current, but there is never a problem having a supply rated for more current than you will use.  The current specification is what the power supply can provide under normal load conditions -- not what it will force.  Now, if you over-load a supply then in an effort to keep up the voltage will fall; this is called brown-out.  We actually have circuitry on our controllers to detect this and if the voltage goes too low, the controller will reset.

Here's a relay that you can get from All Electronics that should work nicely for your project.:
* http://www.allelectronics.com/make-a-store/item/RLY-351/12V-SPDT-30-AMP-AUTOMOTIVE-RELAY/-/1.html

Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Jon McPhalen
EFX-TEK Hollywood Office

huntmaster

Quote from: JonnyMac on February 01, 2010, 03:44:39 PM
There's even a pre-wired socket for that relay:
* http://www.allelectronics.com/make-a-store/item/SRLY-2/SOCKET-FOR-AUTOMOTIVE-RELAY/-/1.html

Thanks!

I take  it that would be the 12v relay.  How about 110v?  Any suggestions?

JonnyMac

That relay will work fine with your lights -- just route the 120 VAC (hot side) through the normally-open contacts.  The coil rating is 12v which we need so that it can be connected to the controller.
Jon McPhalen
EFX-TEK Hollywood Office

huntmaster

Ok, I've got everythign together.  Downloaded the software, now I'm not sure how to get the program to the board.  Any help?

JonnyMac

1) Download the PBASIC editor from Parallax (link on the Prop-1 page)
2) Install the software -- don't plug in USB adapter until installation is done
3) Run the editor
4) Copy the code above into your editor (drag-select, use Ctrl-C to copy, go to editor, use Ctrl-V to paste)
5) Use File\Save As... to save the file
6) Connect Prop-1 to computer (see Prop-1 docs) and download

It's easy once you're setup.  Remember, you WERE going to use PicAXE -- the process is about the same but we're way cooler!  ;D
Jon McPhalen
EFX-TEK Hollywood Office

huntmaster

February 16, 2010, 12:52:55 AM #9 Last Edit: February 16, 2010, 01:09:52 AM by huntmaster
OK, was missing the checked box.  

ran program, then ran on trainer, and the lights don't change at the right times.  Hit button, p3 flashes (buzzer) and p0 comes on (green).  Timing is off.  It runs for about 2 minutes (2:04 to be exact), hits yellow (p1), then runs 41 seconds, then p3 flashes, and p2 (red) comes on.

Is there a reason the timing is so far off?  How can I fix?

Also, there is another chip with the board?  Wondering.

huntmaster

I've changed the timing.  Ran the start_release to 95 (make up for the 5 at main), then ran the check_start to 660, and the do_green to 220.  Now the timing is on again.

Any reason this is so far off?  I was hoping to have it easy to work with, but may have to figure it out the hard way. (7.33 timed seconds per 10 real seconds)

Is there a way to run the buzzer for any longer?  I don't have sound hooked up yet, but the light looks like it might be a bit short, especially since we'll be dealing with an air horn (flash will be faster than the horn reacts).  If horn were a constant, I could change the timing, then the light would change, and the horn would sound for a given time.

JonnyMac

February 16, 2010, 07:26:29 PM #11 Last Edit: February 16, 2010, 07:30:49 PM by JonnyMac
While your process seems simple, programming it is not -- the reason for this is that you don't want just straightline timing, your program needs to do a pseudo-multitask so that it can be interrupted.  Complicating that is one must debounce any input otherwise the program could be influenced by EMI (the Prop-1 is *slow* by modern processor standards, but still runs an instruction in about 0.00015 seconds -- that's really fast in human terms).

When I wrote the first program you hadn't purchased anything so I did no refining, I just whipped up a program structure and tested it for basic function.  Give this version a try; I spent some time with my stopwatch and this gets really close -- as close as one can get, I think, without going to a more advanced (= $$$) processor.

To help with the timing and give the buzzer a little extra time I changed the unit "tick" from 0.1s to 0.2s.  After getting the debounce loop close (I used a 'scope) I then timed the program with a stopwatch and refined it empirically.

My results:
 -- Green: 1:30.27
 -- Yellow: 0.30.22

Remember... this is not a straight linear program and adjusting is not a simple matter of changing a few numbers; the requirement to interrupt any timing cycle means the program architecture must accommodate the interruption. As my friends in the Dallas Personal Robotics Group say... It's harder than it looks!   ;D


' =========================================================================
'
'   File...... archery_v2.bs1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2010 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 16 FEB 2010
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Trigger :: N.O. button input (e.g., push-button, relay, etc.)
'            -- connect N.O. contacts between P6.W and P6.R
'
'
' Program timing is in 0.2-second units -- timing created by input deboucne
' loop.


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  BuzzCtrl        = PIN3                  ' to relays
SYMBOL  RedLight        = PIN2
SYMBOL  YelLight        = PIN1
SYMBOL  GrnLight        = PIN0


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Red             = %00000100
SYMBOL  Yellow          = %00000010
SYMBOL  Green           = %00000001
SYMBOL  Buzzer          = %00001000


' -----[ Variables ]-------------------------------------------------------

SYMBOL  flags           = B0
SYMBOL   TrigIn         =  BIT6

SYMBOL  state           = B1
SYMBOL  debounce        = B2
SYMBOL  idx             = B3

SYMBOL  timer           = W5


' -----[ Initialization ]--------------------------------------------------

Reset:
 PINS = Red | Buzzer                           ' start with red on, short buzz
 DIRS = %00001111                              ' set output pins


' -----[ Program Code ]----------------------------------------------------

Main:
 debounce = 0                                  ' reset debounce timer
 flags = %01000000                             ' assume pressed
 FOR idx = 1 TO 3                              ' * fine-tuning
   PAUSE 64                                    ' *  here only
   flags = flags & PINS                        ' scan input
 NEXT

 BuzzCtrl = IsOff                              ' kill if running


Check_Timer:
 IF timer = 0 THEN Handle_State                ' timer running?
   timer = timer - 1                           ' yes, update


Handle_State:
 BRANCH state, (Check_Start, Do_Green, Do_Yellow)


Check_Start:
 IF TrigIn = No THEN Main                      ' have trigger?
   state = 1                                   ' yes, set state
   PINS = Green | Buzzer                       ' green on, short buzz
   timer = 450                                 ' 450 x 0.2 = 90 seconds

Start_Release:
 IF Trigger = No THEN Main                     ' trigger clear?
   PAUSE 200                                   ' no, wait one tick
   timer = timer - 1                           ' update timer
   GOTO Start_Release                          ' try again


Do_Green:
 IF TrigIn = Yes THEN Do_Red                   ' abort?
   IF timer > 0 THEN Main                      ' still running?
     state = 2                                 ' no new state
     PINS = Yellow                             ' yellow on
     timer = 150                               ' 150 x 0.2 = 30 seconds
     GOTO Main


Do_Yellow:
 IF TrigIn = Yes THEN Do_Red                   ' abort?
   IF timer > 0 THEN Main                      ' still running?
                                               ' if no, drop to Red

Do_Red:
 state = 0
 PINS = Red | Buzzer                           ' red on, short buzz
 timer = 0                                     ' clear timer for red

Abort_Release:
 IF Trigger = No THEN Main                     ' trigger clear?
   PAUSE 25                                    ' no, wait a bit
   GOTO Abort_Release                          ' and try again


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

Jon McPhalen
EFX-TEK Hollywood Office

huntmaster

February 18, 2010, 11:45:59 PM #12 Last Edit: February 19, 2010, 12:39:30 AM by huntmaster
Well, now I have a problem

My remote has been on order for a month now.....no sign of it ever coming. :(

Only thing I have is a garage door opener remote and receiver, but it puts out 30v dc.  Could I run another relay in reverse from the rest to use this?  

Hook up the switching power from the remote to activate the relay, and power from the + of the board to be run by the relay fed back into post 6?  Otherwise, I'm in a bind here.  Any help?

JonnyMac

You'd have to find a relay that will tolerate the 30v from that remove and use the N.O. contacts from the relay to start the program -- seems a bit hokey to me, though, so be very careful.

Jon McPhalen
EFX-TEK Hollywood Office

JackMan

Not exactly sure of what you are remotely switching on/off but you can get a 110v outdoor remote from Menards (and probably most Home Improvement stores) for $10. It will turn on/off your line voltage fixtures and your 12v power supply. Just use 2 of them if you need to independently turn on/off your line voltage fixtures and 12v power supply.