November 23, 2024, 01:58:21 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Prop-1 Fan & Servo Control

Started by jssherrard, October 12, 2008, 02:29:55 PM

Previous topic - Next topic

jssherrard


After my disasterous experience trying to use a Prop-1 to control a Wiper Motor (Haunted Rocking Chair), which still does not work (and I am left wondering if I received a bad HB-25 or Prop-1), I decided to try a new approach for my next prop project... Asking for help up front!

;D

I want to control a Parallax Standard Servo and a small computer fan (12VDC, 0.11A) from a Prop-1. Here is a basic outline:

- - -

Main:

Move servo to a random position (anywhere from 60 - 240)

Turn fan on (HIGH)

Random PAUSE (8 - 16 seconds)

Turn fan off (LOW)

Random PAUSE (10 - 30 seconds)

GOTO MAIN

- - -

The servo is currently connected to P0 and the fan is connected to OUT1; however, feel free to change these as you see fit. In fact, I am wondering if the fan could be ran from a TTL I/O instead of the Vin? Is 12VDC, 0.11A considered high current?

menehune

The TTL outputs are 5vdc if I recall.  They are really designed to only interface to switches for contact closures or small unloaded servos for testing.  Have you tested your 12VDC fan to see if it can run at 5vdc?  I think most 12vdc fans will not reliably start at 5vdc-from what I remember many require 7vdc to start.  Your air volume (CFM, airspeed) will be reduced by at least half if you can get your fan running at 5v.

I really recommend you connect the fan to an OUTx screw terminal so you get the full speed and you don't internally damage the prop chip by overloading the output pin.

The servo may work correctly unloaded while you are testing on the bench, but when the servo is loaded (connected via linkage to your show) the current required can increase dramatically.  What kind of load are you going to place on the servo?  Rotating a five pound skull, rocking a rocking chair, moving a shaker wire to move curtains?

JonnyMac

You didn't get a bad Prop-1 from us; we test them before we send them.

On your fan... NEVER connect an inductive device directly to a TTL I/O pin, no matter what the voltage or current rating.  Why? Inductors cause reverse voltage spikes that can kill the processor; the ULN provides protection from these spikes.  And... our specs clearly state that the MAX current from a TTL I/O pin is (when high) is 20 mA -- this is less that 1/5th what the motor wants.  Please, be careful; you seem to be making unsafe assumptions and we don't want another controller issue.

So, use OUT1 for the fan (positive side is V+); this will provide 12 volts at up to 500 mA which is plenty for the fan.  I also added a feature to the program that forces it to at least center so that it never gets "stuck" on one side the other.

' =========================================================================
'
'   File...... Servo_Fan.BS1
'   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... 12 OCT 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Fan             = PIN1                  ' use V+/OUT1
SYMBOL  Servo           = 0                     ' use P0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  side            = BIT0

SYMBOL  pos             = B2

SYMBOL  delay           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000011                              ' set outputs

  lottery = 1031


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

Main:
  side = 1 - side                               ' toggle side control

New_Pos:
  RANDOM lottery                                ' stir random #
  pos = lottery // 181 + 60                     ' 60 to 240

  IF side = 1 THEN Side_1

Side_0:
  IF pos > 150 THEN New_Pos                     ' force to other side
    GOTO Set_Fan_Delay

Side_1:
  IF pos < 150 THEN New_Pos

Set_Fan_Delay:
  RANDOM lottery                                ' re-stir
  delay = lottery // 8001 + 8000                ' 8 to 16 seconds
  delay = delay / 20                            ' convert to servo pulses
  Fan = IsOn
  GOSUB Servo_Pause

Set_Off_Delay:
  RANDOM lottery
  delay = lottery // 20001 + 10000              ' 10 to 30 seconds
  delay = delay / 20
  Fan = IsOff
  GOSUB Servo_Pause

  GOTO Main


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

' Refreshes servo (at "pos") and delays in ~20 ms units

Servo_Pause:
  IF delay = 0 THEN Servo_Exit
    PULSOUT Servo, pos
    PAUSE 18
    delay = delay - 1
    GOTO Servo_Pause

Servo_Exit:
  RETURN

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


Jon McPhalen
EFX-TEK Hollywood Office

jssherrard

!!!THANK YOU JONNYMAC!!!

"You didn't get a bad Prop-1 from us; we test them before we send them."

Excellent, that is good to know!

"On your fan... NEVER connect an inductive device directly to a TTL I/O pin... use OUT1 for the fan (positive side is V+)"

Okey-dokey. I have had it hooked up correctly from the start, but I am glad to know that inductive + TTL = BAD! Sorry for making any bonehead assumptions, I am still quite lost in all this...

"I also added a feature to the program that forces it to at least center so that it never gets "stuck" on one side the other."

Brilliant. Love it!

I was surprised to see how much more involved your program was than I expected. I guess I thought it would be just a couple HIGH/LOW commands, a few PAUSE commands and a RANDOM or two. It works perfectly, although I will most likely need to adjust the on/off fan times a bit for aesthetic purposes. Also, I am happy to have this opportunity to deconstruct what you have done in order to learn better P-BASIC technique.

I am truly grateful for your speedy (and educational!) assistance.

THANKS AGAIN!!!

;D

jssherrard

HAH!

I just realized...

"LOTTERY = 1031"

;)

JonnyMac

October 12, 2008, 05:49:23 PM #5 Last Edit: October 12, 2008, 05:54:13 PM by JonnyMac
Yep, programs that deal with servos are always harder than we want them to be -- the reason is we have to refresh the servo every 20 milliseconds (unless you want to cough up major $$$ for a digital servo).

  lottery = 1031

Yes, I am a clever monkey!   ;D  Of course, in December it becomes:

  lottery = 1225
Jon McPhalen
EFX-TEK Hollywood Office

jssherrard

I am finding that the quick movement of the servo imparts a slight wobble to the prop. Is it possible to slow down the servo movement? If so, how?


JonnyMac

Try this version.  It slows the servo (there are some tricks used in the code, so be careful about modifying) and it takes care of the servo move while the fan is off -- this seems to match your original intent (move-on-delay-off-delay).

' =========================================================================
'
'   File...... Servo_Fan-v2.BS1
'   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... 12 OCT 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Fan             = PIN1                  ' use V+/OUT1
SYMBOL  Servo           = 0                     ' use P0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  side            = BIT0

SYMBOL  pos             = B2                    ' present position
SYMBOL  target          = B3                    ' destination

SYMBOL  delay           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000011                              ' set outputs

  lottery = 1031

  pos = 150
  target = 150


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

Main:
  side = 1 - side                               ' toggle side control

New_Target:
  RANDOM lottery                                ' stir random #
  target = lottery // 181 + 60                  ' 60 to 240
  target = target & %11111110                   ' make divisible by 2

  IF side = 1 THEN Side_1

Side_0:
  IF target > 150 THEN New_Target               ' force to other side
    GOTO Fan_Off

Side_1:
  IF target < 150 THEN New_Target

Fan_Off:
  Fan = IsOff
  RANDOM lottery
  delay = lottery // 20001 + 10000              ' 10 to 30 seconds
  delay = delay / 20
  GOSUB Servo_Pause

Fan_On:
  Fan = IsOn
  RANDOM lottery                                ' re-stir
  delay = lottery // 8001 + 8000                ' 8 to 16 seconds
  delay = delay / 20                            ' convert to servo pulses
  GOSUB Servo_Pause

  GOTO Main


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

' Refreshes servo (at "pos") and delays in ~20 ms units
' -- moves "pos" to "target"

Servo_Pause:
  IF delay = 0 THEN Servo_Exit
  IF pos = target THEN Update_Servo
  IF pos > target THEN Move_Fro

Move_To:
  pos = pos + 2
  GOTO Update_Servo

Move_Fro:
  pos = pos - 2

Update_Servo:
  PULSOUT Servo, pos
  PAUSE 18
  delay = delay - 1
  GOTO Servo_Pause

Servo_Exit:
  RETURN

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

BigRez

Quotelottery = 1031

Yes, I am a clever monkey!     Of course, in December it becomes:

  lottery = 1225

But that's the reason programmers always get Christmas and Halloween confused...

DEC 25 = OCT 31

:D

JonnyMac

I'll be there's only a few of us (old timers) who get that joke!
Jon McPhalen
EFX-TEK Hollywood Office

jssherrard

January 30, 2009, 10:49:32 PM #10 Last Edit: February 03, 2009, 05:17:14 PM by jssherrard
Hey Jonny!

Thanks for the extremely(!) helpful Servo_Fan.BS1 code. I used it last Halloween with pretty good success. I have finally wrangled-up enough free time to sit down with my Floating Candelabra prop and fine-tune the code and the prop to achieve the best effect. My version of the code follows this message. It is quite different from the original, but without the original this version would not exist. This particular prop requires a fair amount of fine-tuning, both in the programming (especially the on & off timings!) and in the many adjustable physical setting on the prop itself (balance, attachment points, tension lines, springs, etc...) and I am happy to report we have found nearly optimum adjustments for all of these. I have a how-to in the works and will share the URL once the page is complete.

Thanks again!!!

;D


' {$STAMP BS1}
' {$PBASIC 1.0}

' -----[ Program Description ]-----
'
' This PBASIC 1.0 program code is used in conjunction with an EFX-TEK Prop-1
' Controller, a Parallax (Futaba) Standard Servo and a small (12VDC, 0.11A)
' computer fan pushing approximately 14cfm to impart a ghostly, floating
' animation to the Prop Floater/Floating Candelabra. The Prop-1 controls the
' direction of the airflow as well as the duration of the on/off cycles.
'
' File Name... Prop_Floater.BS1
' Author...... Jeffrey Sherrard
'              Copyright (c) 2009
' Web......... http://www.ghost-songs.com/props/PropFloater.html
' EFX-TEK..... http://www.efx-tek.com
'
' Thanks to Jon Williams @ EFX-TEK for a tremendous amount of assistance!

' -----[ Revision History ]-----
'
' February 3, 2009: Timing & Structure Revision
' February 2, 2009: Timing Debug
' January 30, 2009: Principal Programming - Total Revision
' October 12, 2008: Timing Adjustments to Jon Williams' Servo_Fan.BS1

' -----[ Physical Setup ]-----
'
' Parallax Standard Servo connected to P0
' Fan connected to V+(Red Wire)/OUT1(Black Wire)
' Setup P6 = DN
' Setup P7 = DN
' Power Switch = 2

' -----[ I/O DEFINITIONS ]-----

SYMBOL  Fan             = PIN1                  ' Fan connected to V+/OUT1
SYMBOL  Servo           = 0                     ' Servo connected to P0


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

SYMBOL  On              = 1                     ' for active-high in/out
SYMBOL  Off             = 0

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

SYMBOL  Cycle           = B0                    ' for-next variable
SYMBOL  Chance          = B1                    ' random chance variable

SYMBOL  Here            = B2                    ' servo position
SYMBOL  There           = B3                    ' servo destination

SYMBOL  Delay           = W2                    ' pause variable
SYMBOL  Lottery         = W3


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

Reset:

  PINS = %00000000                              ' clear all
  DIRS = %00000011                              ' set outputs

  Lottery = 1031                                ' Halloween Lottery!
  There = 150                                   ' reset destination to center position

  FOR Cycle = 1 TO 30                           ' reset servo to center position
    PULSOUT Servo, 150
    PAUSE 18
  NEXT

  PAUSE 3000

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

Main:

  Here = There                                  ' update current servo position

  Fan = On
  PAUSE 1000                                    ' fan warm-up

  RANDOM LOTTERY                                ' stir random
  Chance = Lottery // 8 + 1                     ' 1 to 8

  IF Chance = 1 THEN Alt_A                      ' 1 in 8 chance for alternate "A" animation
  IF Chance = 2 THEN Alt_B                      ' 1 in 8 chance for alternate "B" animation

  New_There:

    RANDOM Lottery                              ' stir random
    There = Lottery // 181 + 60                 ' 60 to 240 (new servo destination)

    IF Here < There THEN Forward
    IF Here > There THEN Backward

  GOTO New_There                                ' IF Here = There THEN choose new destination

Forward:

  FOR Cycle = Here TO There STEP 1              ' cycle to new servo position (Here to There)
    PULSOUT Servo, Cycle
    PAUSE 18
  NEXT

  GOTO Hold_On

Backward:

  FOR Cycle = Here TO There STEP -1             ' cycle to new servo position (Here to There)
    PULSOUT Servo, Cycle
    PAUSE 18
  NEXT

Hold_On:

  RANDOM Lottery                                ' stir random
  Delay = Lottery // 8001                       ' 0 to 8 seconds (Fan On)
  PAUSE Delay

Hold_Off:

  Fan = Off

  RANDOM Lottery                                ' stir random
  Delay = Lottery // 48001                      ' 0 to 48 seconds (Fan Off)
  PAUSE Delay

  IF Chance = 1 AND Delay < 8000 THEN Hold_Off  ' guarantee Alt_A minimum pause
  IF Chance = 2 AND Delay < 8000 THEN Hold_Off  ' guarantee Alt_B minimum pause

  GOTO Main

' -----[ Alternate Animations ] -----

Alt_A:                                          ' alternate animation "A" (forward-backward)

  FOR Cycle = Here TO 240 STEP 1                ' slow cycle from "Here" to 240
    PULSOUT Servo, Cycle
    PAUSE 18
    PULSOUT Servo, Cycle
    PAUSE 18
  NEXT

  PAUSE 1000

  FOR Cycle = 240 TO 60 STEP -1                 ' slow cycle from 240 to 60
    PULSOUT Servo, Cycle
    PAUSE 18
    PULSOUT Servo, Cycle
    PAUSE 18
  NEXT

  There = 60                                    ' update "There" variable value

  GOTO Hold_Off

Alt_B:                                          ' alternate animation "B" (backward-forward)

  FOR Cycle = Here TO 60 STEP -1                ' slow cycle from Here to 60
    PULSOUT Servo, Cycle
    PAUSE 18
    PULSOUT Servo, Cycle
    PAUSE 18
  NEXT

  PAUSE 1000

  FOR Cycle = 60 TO 240 STEP 1                  ' slow cycle from 60 to 240
    PULSOUT Servo, Cycle
    PAUSE 18
    PULSOUT Servo, Cycle
    PAUSE 18
  NEXT

  There = 240                                   ' update "There" variable value

  GOTO Hold_Off

' -----[ END ]-----

jssherrard

Quote from: bigrez on January 10, 2009, 05:44:32 AM
But that's the reason programmers always get Christmas and Halloween confused...

DEC 25 = OCT 31

:D

As for me, I have decided to celebrate this years birthday in HEX. That means I am only 28!

;D