November 22, 2024, 10:20:57 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Programming help request

Started by CoffinBound, August 06, 2007, 11:02:10 AM

Previous topic - Next topic

CoffinBound

OK, it has been quite a while since I played around with the code for one of these, so I am a bit rusty.  Can someone please point me in the right direction?

Preliminary:
I have 5 devices attached to out0 thru out4.  These devices require nothing more than a contact closure to activate.  I will also have a EFX-TEK PIR sensor on pin6.

End Goal:
What I want is that when the PIR goes HIGH, it kicks off the routine.  The routine will simply turn on then off each OUT pin, with about a 2 second delay in between each one.  I also want the picking of the OUT pin to be random, but not repeated within within that set. I would also like to run thru the set out OUT pins, let's say 3 times before it resets.

For example:
When triggered, it might go like this... 4,2,1,3,0  :  1,4,0,3,2  :  2,0,1,4,3  then Pause for 20 seconds before it can be re-triggered. Make sense?

At this time, I don't have any code to post, but I will be working on it while I wait for someone to help me out.

Thanks in advance for any help you can give!!

CoffinBound

JonnyMac

August 06, 2007, 12:38:41 PM #1 Last Edit: August 06, 2007, 12:41:09 PM by JonnyMac
As you can see by the program below, your's is actually a moderately-sophisticated request.  The program does as you ask, and neither repeats within a cycle or between cycles.

' =========================================================================
'
'   File...... CoffinBound.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 06 AUG 2007
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  pirTimer        = B2                    ' for PIR debouncing
SYMBOL  cycles          = B3                    ' # of sequence cycles
SYMBOL  idx             = B4                    ' loop control
SYMBOL  select          = B5                    ' pin selection
SYMBOL  mask            = B6                    ' for testing play list
SYMBOL  playList        = B7                    ' marks pins "played"
SYMBOL  result          = B8                    ' test result
SYMBOL  last            = B9                    ' last output "played"
SYMBOL  lottery         = W5                    ' random value


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

Reset:
  PAUSE 20000                                   ' PIR warmup / delay
  pirTimer = 0

  last = 99                                     ' allow any pin at start


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

Main:
  RANDOM lottery                                ' stir random value
  pirTimer = pirTimer + 10 * PIR                ' update PIR timer
  PAUSE 10
  IF pirTimer < 250 THEN Main                   ' wait for valid signal

  cycles = 0                                    ' reset cycles count

Show_Time:
  FOR idx = 1 TO 3
    RANDOM lottery
  NEXT
  select = lottery // 5                         ' select 0 TO 4
  READ select, mask                             ' create test mask
  result = playList & mask                      ' check played list
  IF result <> 0 THEN Show_Time                 ' if played, try again
    IF select = last THEN Show_Time             ' no repeats between cycles
      playList = playList | mask                ' mark played list
      last = select

  HIGH select                                   ' output on
  PAUSE 2000
  LOW select                                    ' output off

  IF playList <> %00011111 THEN Show_Time       ' all five played?
    playList = %00000000                        ' yes, clear play list
    cycles = cycles + 1                         ' update sequence cycles
    IF cycles < 3 THEN Show_Time                ' show over?
      GOTO Reset                                ' yes, reset and wait


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


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


' -----[ EEPROM Data ]-----------------------------------------------------

Bit_Masks:
  EEPROM (%00000001)
  EEPROM (%00000010)
  EEPROM (%00000100)
  EEPROM (%00001000)
  EEPROM (%00010000)
  EEPROM (%00100000)
  EEPROM (%01000000)
  EEPROM (%10000000)
Jon McPhalen
EFX-TEK Hollywood Office

CoffinBound

John,
First, let me say "Thank you" for your super quick response!  I knew that the code wouldn't be cut and dry, but Wow, I am definitely glad I asked for help!

Second, would you mind if I asked a couple questions about your code?  I get most of it, but there are a couple things I don't understand.

1.) What does the Symbol Sio =7 do, used for, etc...?
2.) I vaguely remember needing to "seed" a random number. Something like the following...

SYMBOL lottery = W4
lottery = 1027
RANDOM lottery


Is that not the case any longer?

Thanks again,
CoffinBound

JonnyMac

August 06, 2007, 04:09:07 PM #3 Last Edit: August 06, 2007, 04:10:42 PM by JonnyMac
Have you seen this document?
-- http://www.efx-tek.com/downloads/prop-1_programming_basics.pdf

It explains a lot of things you're asking. 

1) Briefly, SYMBOL is used to rename a pin number (e.g., 0), pin register (e.g., PIN0), variable (e.g. B2) or constant (e.g, 100) to something more useful when we read the bulk of the program.  This:

Main:
  IF PIN6 = 0 THEN Main


does the same as:

Main:
  IF Trigger = IsOff THEN Main


but the second version is easier to understand with one read.

2) Seeding the random number is optional; I don't do it in programs like this where it will be constantly changing and the value used is based on an external random event.
Jon McPhalen
EFX-TEK Hollywood Office

livinlowe

I am not sure it will help with your random application, but check out the library and look into the vixen stuff. It really can't be easier to make a sequence than that!!
Shawn
Scaring someone with a prop you built -- priceless!

CoffinBound

John,
I think I might not have asked my first question clearly enough.  I understand why and how a Symbol is used.  For example the idx and cycles symbols make complete sense, but I don't see any reference to the Sio symbol other than being declared.  I am sure you wouldn't have just put it in there for the hell of it. I was hoping you could explain the purpose of the Sio symbol.

As for the seed question, I should have looked at the help file before I asked.  I felt completely stupid for asking after I read it.  My bad.  :-[

Thanks again.
CoffinBound

JonnyMac

Whoops... it's in my default template and I didn't take it out.   You can use it for the AP-8 (Sio = Serial I/O) when you add that to your project.
Jon McPhalen
EFX-TEK Hollywood Office

CoffinBound

OK.  That makes sense.  I was beginning to wonder if I was in left field with that one.

I have glanced at the Vixen stuff.  It looks too neat, I just don't have the time to devote to it right now.  I'm thinking next year I will try to tackle a Vixen project.

CoffinBound

Alright, before I go any further and do something stupid like fry my ULN, can you let me know if I am doing something wrong?

I took the code you created and tested it with the Trainer board.  Worked like a champ, so I proceeded to set it up for the real deal.  Swapped out the ULN and connected my homemade strobe light boxes to the OUT0 -> OUT4 pins. I guess it would help if you knew what I meant by "strobe light boxes".  Click HERE to see what I'm talking about.

OK, so what I have is 5 wires (one of the two wires from each of the boxes) twisted together and connected to the GND terminal, and the other wire from each box going to OUT0 -> OUT4.

I inserted the AA batteries into the strobe boxes and right away, the LED next to the V+ started to glow.  I remember reading about this in a different post, but I dont really understand what the problem is.  Since I wasn't going to be using the Porp1 with the power switch in the 2 position, I didn't think it would be a problem, so I  continued on.

I put the power switch into position 1, waited and waited some more.  It never set off my strobe boxes.  I know that it is running the code because I put some debug statements in to see the pins go high and low.  It looks good from here.

I then disconnected the wires from the prop1, touched them together to create a short, sure enough, the strobes fired as they should.

Since I didn't want to destroy my prop1, I used my volt meter to see what kind of voltage might be on the wires coming from the strobe boxes to the prop1.  I was kinda surprised to see 230VDC (the big cap on the circuit board is rated at 330VDC).  Concerned about the amps, I set my meter to 4mA DC and got a reading of .075.  I will be the first to admit that I'm not really sure if I am using the meter correctly, but I believe this info is correct.

Long story short, do you see any reason why this configuration wouldn't work?  Is this too much for the prop1 to handle.  Should I maybe think about connecting these boxes to relays instead of directly to the prop1?

Speaking of relays, that brings up another question.  If I have 5 volt relays, can I control them using the TTL pins, or is it better to connect them to the screw terminals?

OK, I think that is it. I will post again if I forgot anything.

JonnyMac

August 08, 2007, 05:05:38 PM #9 Last Edit: August 08, 2007, 05:08:28 PM by JonnyMac
Let me make it abundantly clear that hacking into flash circuits like that could get you hurt; the strobe requires a very high voltage and a DC-to-DC generator in the flash provides that and it gets stored in big cap until it's dumped through the flash tube.

Let me suggest that you hack your strobe such that it can be fired with a normally-open push-button; once you get to that stage a small relay can be added to the circuit -- the Prop-1 fires the relay, the relay contacts close and fire the strobe (power for the strobe comes from batteries).  I'd leave the button on the strobe box for testing (wire the button and relay contacts in parallel).  The point is that the electrical system of the Prop-1 should be isolated from the strobe through the relay.  DO NOT attempt to power the strobe circuit from the Prop-1.
Jon McPhalen
EFX-TEK Hollywood Office

livinlowe

I've been bitten by these things! Hurts like the dickens! Puts you in a pretty foul mood, too, so be careful!(Not to mention when you do it in front of some friends, then you feel stupid!)  :o
Shawn
Scaring someone with a prop you built -- priceless!

CoffinBound

John,
Thanks once again for all the vital info.  I had a strong feeling that that would be the answer. Unless you tell me otherwise, I am going to put your words of caution on my How To page.  Just to make it clear to anyone who might decide they want to try this themselves.

Fortunately, I had someone A LOT more experienced with electronics warn me of the exact same thing both of you have.  Therefore, I have been very careful while working with these suckers.  Any time I put the battery in to test, I made sure to discharge the cap right after I removed the battery.  Even then, I let them sit for a  while before I continued to work.

So back to my final question, can I run the relays from the pins, or should I always use the screw blocks for controlling relays?

Thanks guys!

JonnyMac

Sorry if I missed the question -- I was concerned with your health and wellbeing.  Relays are always controlled from the OUTx terminals; one side of the relay goes to V+ (this is common), the other side to an OUTx terminal.
Jon McPhalen
EFX-TEK Hollywood Office

CoffinBound

Finally getting a chance to work on this prop again, and I have yet another question.

Taking Jon's advice, I purchased some 12 volt relays from All Electonics.  They are a 12Volt, 5 Amp type Jon recommended in another thread.  Anyway, my question... I know that I should use a diode across the coil to squash the disconnect surge, but what type of diode should I use?  I have a bunch of 1N914 type in my spare parts bin.  Will these work, or should I go buy something else instead?

Thanks for the help!

CoffinBound

JonnyMac

No, you need something beefier; use a 1N4001.
Jon McPhalen
EFX-TEK Hollywood Office