November 22, 2024, 06:17:38 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.


Rotating motor forward and backward

Started by wdgoof, May 20, 2014, 12:40:14 PM

Previous topic - Next topic

wdgoof

I am working on a column for my graveyard that will open and close with a "monster" inside.  The requirements are pretty simple.  There is a trigger (will eventually be a PIR, but I will leave that out of it for now.) some LEDs turn on, motor runs forward to open the door, a 45 second delay, motor runs in reverse to close the door, LEDs turn off. I am using a basic prop motor from frightprops.com to open and close the door. I spoke with someone at your booth at Transworld (sorry to long ago to remember who) and he recommended a Prop-1 with an RC-2.   I have been through the documentation and forum looking for a way to flip the current back and forth for the motor but haven't found anything.  Is this done with a program command?  Or do I need to wire the motor to both of the relays on the RC-2, 1 forward and 1 reverse, and trigger them as separate pins?  Here is the code I have so far which uses the latter method.  If the code is good, then how should the motor be wired?  Sorry for all the questions.  Any help would be greatly appreciated.

JonnyMac

May 20, 2014, 03:45:24 PM #1 Last Edit: May 20, 2014, 04:54:06 PM by JonnyMac
It's pretty easy to connect the RC-2 for motor direction control -- here's a diagram:



When P0 is HIGH the motor will go forward; when P1 is HIGH the motor will go reverse. If P0 and P1 are both LOW or both HIGH the motor will stop.

Here's my take on your little table-based program -- it tightens things up and corrects the syntax errors. Note that the EEPROM statement only allows values between 0 and 255, so I use 0.1s (100ms) timing units.

' =========================================================================
'
'   File...... Column_V2.BS1
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Lights          = 2
SYMBOL  DoorClose       = 1                     ' to RC-2
SYMBOL  DoorOpen        = 0                     ' to RC-2


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  EOS             = $FF                   ' end of show marker


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

SYMBOL  timer           = B2                    ' for debounce loop
SYMBOL  addr            = B3                    ' eeprom address

SYMBOL  iopin           = B4                    ' io pin affected
SYMBOL  state           = B5                    ' on or off

SYMBOL  delay           = W5                    ' delay in 100ms units


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

Power_Up:
  ' put code here that only happens at power-up/hard reset

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P5..P0 are outputs


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = IsOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

  addr = 0

Get_Next_Record:
  READ addr, iopin                              ' get pin
  addr = addr + 1

  IF iopin = EOS THEN Reset                     ' done?

  READ addr, state                              ' get pin state
  addr = addr + 1
  READ addr, delay                              ' get state timing (100ms units)
  addr = addr + 1

Run_Record:
  IF state = IsOff THEN Set_Low
    HIGH iopin
    GOTO Run_Delay

Set_Low:
  LOW iopin

Run_Delay:
  delay = delay * 100                           ' convert to ms
  PAUSE delay
  GOTO Get_Next_Record

  GOTO Reset


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


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


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

' There are 3 parameters to this table.
'   1 is the pin number to change
'   2 is the state (IsOn or IsOff)
'   3 is the amount of time (in 10ths of a second) to wait before executing
'     the next command (can't be greater than 255 or 25.5s)

Move_Table:
  EEPROM (Lights,    IsOn,    0)
  EEPROM (DoorOpen,  IsOn,   40)                '  4s
  EEPROM (DoorOpen,  IsOff, 200)                ' 20s
  EEPROM (DoorOpen,  IsOff, 200)                ' 20s
  EEPROM (DoorClose, IsOn,   40)                '  4s
  EEPROM (DoorClose, IsOff,   0)
  EEPROM (Lights,    IsOff,  10)                '  1s
  EEPROM (EOS,       EOS,   EOS)                ' end of show



Nice job jumping in and attempting to write the program. Honestly, there are easier ways to write the program for this prop, but doing is the fun part, and only by writing programs can we become programmers.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

May 20, 2014, 03:54:10 PM #2 Last Edit: May 20, 2014, 08:56:13 PM by JonnyMac
For those new to the Prop-1, here's another way to write that program (but note the changes for the pin constants):

' =========================================================================
'
'   File...... Column_V3.BS1
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Lights          = PIN2
SYMBOL  DoorClose       = PIN1                  ' to RC-2
SYMBOL  DoorOpen        = PIN0                  ' to RC-2


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0


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

SYMBOL  timer           = B2                    ' for debounce loop


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

Power_Up:
  ' put code here that only happens at power-up/hard reset

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P5..P0 are outputs

  PAUSE 30000                                   ' PIR warm-up/re-trigger delay


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = IsOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

Run_Show:
  Lights = IsOn

  DoorOpen = IsOn
  PAUSE 4000                                    ' wait 4s

  DoorOpen = IsOff
  PAUSE 40000                                   ' wait 40s

  DoorClose = IsOn
  PAUSE 4000                                    ' wait 4s

  DoorClose = IsOff

  Lights = IsOff

  GOTO Reset


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


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


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

Jon McPhalen
EFX-TEK Hollywood Office

JackMan

wdgoof,
  I would have written this program exactly as Jon's shorter version, (because I learned from him!). Uses about 1/2 the eeprom space of the original and much less complicated. Also if you're going to use a PIR, be sure to add at least a 45s PAUSE for a warm-up delay in the Power_Up section so the PIR has time to properly calibrate. You could put this delay in the Reset section and use it as a post delay as well as the warm-up.

JonnyMac

Good point on the PIR, Jack -- I've updated the program to reflect the way I typically do things.
Jon McPhalen
EFX-TEK Hollywood Office

wdgoof

Thank you very much for the responses. 

The wiring diagram will be VERY helpful.
I also really appreciate the programing help.  I hope to wire this up and test it out tonight or this weekend at the latest.  I will update with the results.

Thanks again for all the help.

JackMan

Not that this particular program needs to be shortened, but just for reference, you could actually eliminate the last 2 lines before GOTO RESET. The first line in the RESET section will turn off the Lights and the Motor (DoorClose).

JonnyMac

You could, but -- in my opinion -- one should always strive for program clarity when resources are not short. A newcomer might initially miss that the reset section turns everything off.
Jon McPhalen
EFX-TEK Hollywood Office

JackMan

Yep, I agree. Just thought I'd point that out for anyone learning as an FYI.

wdgoof

I wired everything up this evening and tested it out.

Everythng worked great! 

A few minor tweaks on the timing but all is in order.  Now I just need to figure out the PIR. (I know not your problem LOL).

Thanks again for all of the help and support.

Jeff Haas