November 23, 2024, 08:57:10 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.


I think I have a problem

Started by dflowers, October 25, 2009, 01:19:45 PM

Previous topic - Next topic

dflowers

Jon,

I am programming a ground breaker and everything was working fine. All of a sudden, the air solenoids will no longer activate. I have tested the solenoids with a simple 9 volt battery and they work fine. I have also tried the following code:

'======================================================================
' {$STAMP BS2}  ' Use the proper directive for your controller
' {$PBASIC 2.5}      ' Use the proper directive for your controller

Main:
Test    PIN 0

Yes             CON     1
No              CON     0

Test = Yes


When I tried this, I then tested for 12 volt power between the V+ and OUT) terminal. No dice. Any ideas? Any trouble shooting help would be appreciated.

dflowers

Ok, that was not the code I was using. The code I was using is:

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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


Test         PIN     9


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

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



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




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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000111 : DIRL = %00000000           ' set outputs

  PAUSE 5000                                   ' warm-up / delay


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

Main:



Test = IsOn

  GOTO Main                                    ' everything off


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


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


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

But now the pins seem to be working. I brouth everthing inside and hooked it up with the Prop1 Trainer. Not sure what I did that would have caused this. Any ideas?

JonnyMac

If you're going to use code like this:

  Test = Yes

... you need to make sure the pin is set to output mode first -- your second program does this by setting the proper bits in the DIRS register.
Jon McPhalen
EFX-TEK Hollywood Office

dflowers

Jon,

As always, thanks for your help and always being there for your customers. Like I said in my second post, the code I am using is more like what I sent you the second time. I have attached the actual code now that I am finished with it. The problem i was having was strange. The code was working perfectly and then all of a sudden, the out put terminals were no longer getting power. When using the trainer, the servo connectors were working fine. I am not sure if I was trying to send 12 volt power to the solenoids over too long a distance and tripped a safety feature of the board or what. I disconnected everything and brought it inside and re-connected everything and it started working again. (Tested using a multi-meter). Anywho, here is the code (adapted to code you helped me with last year):

    ' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 29 OCT 2008
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Trigger         PIN     14                      ' SETUP = DN

Fog             PIN     11
Zombie1         PIN     10
Zombie2         PIN     9


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

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

FogIsOn         CON     1
FogIsOff        CON     0

IsUp            CON     1
IsDown          CON     0

Yes             CON     1
No              CON     0

t9600    CON  84
open     CON  $8000
baud     CON  open + t9600


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

timer           VAR     Byte
lottery         VAR     Word                    ' random #
delay           VAR     Word


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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000111 : DIRL = %00000000           ' set outputs
  SEROUT 15, baud, ["VST", 13]

  PAUSE 5000                                   ' warm-up / delay


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

Main:
  timer = 0                                     ' reset timer
  DO WHILE (timer < 100)                        ' wait for 0.1 sec input
    RANDOM lottery                              ' stir random #
    PAUSE 5                                     ' loop pad
    timer = (timer + 5) * Trigger               ' update timer
  LOOP


  SEROUT 15, baud, ["VSV $00", 13]          'set volume full (in hex),
                                         ' insert carriage return
  SEROUT 15, baud, ["VPF x.mp3", 13]  'play x.mp3, insert carriage return

  PAUSE 2500

' RANDOM lottery
' delay = lottery // 2001 + 1000                ' 1 to 3 seconds
' PAUSE delay

  'Fog = FogIsOn
  'PAUSE 2000

  Zombie1 = IsUp
  Zombie1 = IsDown
  PAUSE 250
  Zombie2 = IsUp
  Zombie2 = IsDown
  PAUSE 250
  Zombie1 = IsUp
  Zombie1 = IsDown
  PAUSE 250
  Zombie2 = IsUp
  Zombie2 = IsDown
  PAUSE 250
  Zombie1 = IsUp
  Zombie1 = IsDown
  PAUSE 250
  Zombie2 = IsUp
  Zombie2 = IsDown
  PAUSE 250
  Zombie1 = IsUp
  Zombie2 = IsUp
  Zombie1 = IsDown
  Zombie2 = IsDown
  PAUSE 250
  Zombie1 = IsUp
  Zombie1 = IsDown
  PAUSE 250
  Zombie2 = IsUp
  Zombie2 = IsDown
  PAUSE 250
  Zombie1 = IsUp
  Zombie1 = IsDown
  PAUSE 250
  Zombie2 = IsUp
  Zombie2 = IsDown
  PAUSE 250
  Zombie1 = IsUp
  Zombie2 = IsUp
  Zombie1 = IsDown
  Zombie2 = IsDown
  PAUSE 250
  Zombie1 = IsUp
  Zombie1 = IsDown
  PAUSE 250
  Zombie2 = IsUp
  Zombie2 = IsDown
  PAUSE 250
  Zombie1 = IsUp
  Zombie2 = IsUp
  Zombie1 = IsDown
  Zombie2 = IsDown
  PAUSE 250
  Zombie1 = IsUp
  Zombie1 = IsDown
  PAUSE 250
  Zombie2 = IsUp
  Zombie2 = IsDown

  GOTO Reset                                    ' everything off


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


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


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

Please be gentle, I am still learning to program. I attmpted all of this buliding off of the code you helped me with last year. I also got the Vmusic2 working all by myself, although I am not having it return the status to the Prop2.

Thanks again,

Dorian

JonnyMac

October 25, 2009, 08:34:40 PM #4 Last Edit: October 25, 2009, 08:36:43 PM by JonnyMac
First things first: if you modify something I wrote then you must take my name off of it before re-posting.  I won't take credit for anyone's cool work, and I don't want credit for anyone's errors -- I make enough of those on my own!  ;D   Okay?... take my name off that listing, please.

Second.  Is the V+ LED lit (power switch set to P2)?  If yes, have you checked the ULN or a break in the common wire that goes from V+ to the valves?  The trainer is showing that the processor is giving commands, they're just not getting to the valves to you have to look through those areas that could be the cause (I just listed them).

I think, though, the problem is all in your code.  What we want to do is this:

A) Turn something on
B) Wait
C) Turn it off

You have B & C swapped so the outputs are only operating for about 0.0001 seconds (1/10 millisecond, the time required to load up a new instruction) which you might see on the LEDs of the trainer but will never activate a valve.  Then you have a 250ms delay in between.  Look, I've highlighted your code red in the seconds that are, effectively, doing nothing.  All you have is a bunch of strung-together PAUSE statements.

  Zombie1 = IsUp
 Zombie1 = IsDown

 PAUSE 250
 Zombie2 = IsUp
 Zombie2 = IsDown

 PAUSE 250
 Zombie1 = IsUp
 Zombie1 = IsDown

 PAUSE 250
 Zombie2 = IsUp
 Zombie2 = IsDown

 PAUSE 250
 Zombie1 = IsUp
 Zombie1 = IsDown

 PAUSE 250
 Zombie2 = IsUp
 Zombie2 = IsDown

 PAUSE 250
 Zombie1 = IsUp
 Zombie2 = IsUp
 Zombie1 = IsDown
 Zombie2 = IsDown

 PAUSE 250
 Zombie1 = IsUp
 Zombie1 = IsDown

 PAUSE 250
 Zombie2 = IsUp
 Zombie2 = IsDown

 PAUSE 250
 Zombie1 = IsUp
 Zombie1 = IsDown

 PAUSE 250
 Zombie2 = IsUp
 Zombie2 = IsDown

 PAUSE 250
 Zombie1 = IsUp
 Zombie2 = IsUp
 Zombie1 = IsDown
 Zombie2 = IsDown

 PAUSE 250
 Zombie1 = IsUp
 Zombie1 = IsDown

 PAUSE 250
 Zombie2 = IsUp
 Zombie2 = IsDown

 PAUSE 250
 Zombie1 = IsUp
 Zombie2 = IsUp
 Zombie1 = IsDown
 Zombie2 = IsDown

 PAUSE 250
 Zombie1 = IsUp
 Zombie1 = IsDown

 PAUSE 250
 Zombie2 = IsUp
 Zombie2 = IsDown


Finally, your program is very "brute force" which most consider inelegant.  Remember, programming is a mix of art and science.  We don't just bash out props, do we?  No, we carefully craft them so that they look cool.  We should do the same with our code.  Even if nobody sees it but us it will work better in most cases if we design it with the same care we put into the physical aspect of our props.

Have a look at FOR-NEXT in the online docs, it can simplify your code.  If you're unsure, just tell me exactly how you want to the prop to behave and I'll assist.  Or... if you're just in a hurry move the PAUSE statements so that they create a delay after you've turned something on, for example:

  Zombie1 = IsUp
 PAUSE 250
 Zombie1 = IsDown

Jon McPhalen
EFX-TEK Hollywood Office

dflowers

Jon,

Sounds good. I will remove your name, sorry for that. I will make the changes you suggest. Basically, what I am looking for is a random movement for my ground breaker that is controlled by two pneumatic cylinders, one for each arm. Here is my routi9ne in plain english:

PIR Trigger, then
Start audio (Vmusic2, I am not returning the current status to the Prop2)
Arm 1 up, then down,
Arm 2 up, then down,
Continue for 10 or so seconds (I have a 20 second MP3 audio clip)
Reset and wait until next trigger, possibly with a random timer to stop someone from just standing in front of the PIR to re trigger the event.

It would also be nice to activate a 12 volt relay periodically to keep the fog machine puting out fog while the routine is not running, but it would need to run for a couple of seconds and then off for a few minutes.


Thanks for the help and sorry for the aggravation. :)

Dorian

JonnyMac

Ground breakers are popular this year -- there's a big thread in the Prop-1 forum.  I'll write you a Prop-2 version if you start getting specific.  What?  "Periodically" is not something I can code.  What do you mean by periodically?  What is the range of delays between fog events.  And when it's one how long should it be one (fixed value or range)?

As Tom Cruise said in Jerry Maguire, "Help me help you!"
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

October 25, 2009, 11:15:40 PM #7 Last Edit: October 25, 2009, 11:22:36 PM by JonnyMac
Okay, I'm tired so I wrote this and tested it.  Note that I think using the VMUSIC without feedback is a bad idea so I've incorporated that feature into this code.  I'm moved the outputs to the P0-P7 group so you can connect the Trainer there, and use P14 and P15 for the VMUSIC.  Since you have long delays for the "periodic" fog timing I used one of the LEDs on the Trainer as a heartbeat -- shows you that the program is alive (this goes out when the zombie is moving).

This is a serious program -- it's going to take some getting used to, but this is what it takes to do what you requested.

Note, too, that I used my VMUSIC template to start with so I use subroutines instead of just bashing out code.  You could update this to select random files like is being done in the Prop-1 version.


' =========================================================================
'
'   File...... Groundbreaker.BS2
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 25 OCT 2009
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' -- P15 and P14 SETUP jumpers need to be in the UP position
' -- clip pins 1 and 2 from ULN2803, or pin 1 from the ULN2003
' -- use P6 for (active-high) trigger


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


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

RX              PIN     15                      ' no ULN / SETUP = UP
TX              PIN     14                      ' no ULN / SETUP = UP

Trigger         PIN      6                      ' ULN acts as pull-down
Heartbeat       PIN      5

Fogger          PIN      2
Shoulder2       PIN      1
Shoulder1       PIN      0


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

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

Yes             CON     1
No              CON     0

VolMax          CON     $00
VolMin          CON     $FE

T2400           CON     396
T9600           CON     84
T19K2           CON     32
T38K4           CON     6

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open + T9600


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

holdoff         VAR     Word
timer           VAR     Word
lottery         VAR     Word
fogTimer        VAR     Word
delay           VAR     Word
eePntr          VAR     Word

idx             VAR     Byte

mp3             VAR     Byte
mute            VAR     Byte
shoulders       VAR     Byte
last            VAR     Byte
char            VAR     Byte


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

Power_On:
 PAUSE 2500                                    ' let VMUSIC power up

Reset:
 GOSUB VM_Stop                                 ' stop if playing
 GOSUB VM_Wait_Prompt

 mute = VolMax
 GOSUB VM_Mute

 OUTH = %00000000 : OUTL = %00000000           ' clear all
 DIRH = %00000000 : DIRL = %00000111           ' set outputs

 holdoff = 300                                 ' set to 30.0 seconds


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

Main:
 timer = 0                                     ' reset
 FOR idx = 1 TO 20                             ' 100ms debounce (20 x 5)
   RANDOM lottery                              ' stir random #
   PAUSE 5
   timer = (timer + 5) * Trigger               ' scan trigger port
 NEXT
 TOGGLE Heartbeat                              ' show we're waiting


Check_Holdoff:
 IF (holdoff = 0) THEN                         ' in retrigger hold-off?
   IF (timer = 100) THEN                       '   nope, trigger active?
     Heartbeat = IsOff                         '   yes, clear heatbeat
     GOTO Start_Audio                          '   and jump into program
   ENDIF
 ELSE
   holdoff = holdoff - 1                       '   yes, update holdoff
 ENDIF


Periodic_Fog:
 IF (fogTimer > 0) THEN                        ' timer still running?
   fogTimer = fogTimer - 1                     ' yes, decrement
 ELSE
   Fogger = 1 - Fogger                         ' toggle fog output
   IF (Fogger = IsOn) THEN
     fogTimer = lottery // 21 + 10             ' 1 to 3 seconds
   ELSE
     fogTimer = lottery // 1201 + 600          ' 1 to 3 minutes
   ENDIF
 ENDIF
 GOTO Main


Start_Audio:
 mp3 = 0
 GOSUB VM_Play
 PAUSE 2500

 Fogger = IsOn
 fogTimer = 2000                               ' 2s blast


Zombie_Dance:
 RANDOM lottery
 shoulders = lottery & %11                     ' for bits 0 & 1
 IF shoulders = last THEN Zombie_Dance
   last = shoulders
 OUTS = OUTS & %100 | shoulders                ' update shoulders
 RANDOM lottery
 delay = lottery // 201 + 100                  ' 100ms to 300ms
 PAUSE delay


Check_Fogger:
 IF (Fogger = IsOn) THEN
   IF (fogTimer > delay) THEN
     fogTimer = fogTimer - delay
   ELSE
     fogTimer = 0
     Fogger = IsOff
   ENDIF
 ENDIF


Check_Zombie:
 timer = timer + delay
 IF timer < 10000 THEN Zombie_Dance
   GOTO Reset


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

VM_Wait_Prompt:
 SERIN RX, Baud, [WAIT(">")]
 RETURN

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

' Pass file # (index in DATA table) to play in "mp3"

VM_Play:
 SEROUT TX, Baud, ["VPF "]
 GOTO Play_MP3

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

' Pass file # (index in DATA table) to play in "mp3"

VM_Repeat:
SEROUT TX, Baud, ["VRF "]
 GOTO Play_MP3

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

' Pass file # (index in DATA table) to play in "mp3"

Play_MP3:
 eePntr = (8 * mp3) + Song_List

Send_Name:                                      ' send file title
 FOR idx = 1 TO 8                              ' max is 8 characters
   READ eePntr, char                           ' get a character
   IF char = 0 THEN Finish_Cmd                 ' if 0, we're at end
   SEROUT TX, Baud, [char]
   eePntr = eePntr + 1
 NEXT

Finish_Cmd:
 SEROUT TX, Baud, [".MP3", CR]                 ' send extention + CR
 RETURN

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

VM_Wait_Start:
 SERIN RX, Baud, [WAIT("T $")]
 RETURN

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

VM_Stop:
 SEROUT TX, Baud, ["VST", CR]
 RETURN

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

' Pass mute level (0 = loudest, 254 = muted) in "mute"

VM_Mute:
 mute = mute MAX VolMin                        ' limit per spec

 SEROUT TX, Baud, ["VSV ", DEC mute, CR]
 RETURN


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

' File names are stored on 8-byte boundaries -- this is very important for
' correct program operation.  This strategy uses a little more EE space but
' is easier to update and maintain

Song_List       DATA    @$00, "zombie1"          ' mp3 = 0
               DATA    @$08, "file2"            ' mp3 = 1
               DATA    @$10, "file3"
               DATA    @$18, "file4"
               DATA    @$20, "file5"
               DATA    @$28, "file5"
               DATA    @$30, "file6"
               DATA    @$38, "file7"
Jon McPhalen
EFX-TEK Hollywood Office

dflowers

Holy crap! :o If you wrote this while you were tired, I would hate love to see what you write when you are refreshed and full of coffee. All I can say is WOW and thanks. It is help and customer service like this that makes EFX-TEK the best. Jon, as usual, thank you very much. I went the route of not returning the status from the Vmusic2 to the Prop2 simply because this project was a last minute deal and I was happy I even got the thing to play. After reading your code, I understand why getting the feedback from the Vmusic2 is important. I was just afraid to even try to work that out in code before Halloween. I really appreciate you taking the time to help me out with this, I know you are busy writing code all of the time to help people out, but around Halloween, I am sure it gets really crazy.

Thanks,

Dorian