November 23, 2024, 05:34:26 PM

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.


Model tramcar controller with an HB25 ?

Started by Eric, October 13, 2010, 11:08:51 PM

Previous topic - Next topic

Eric

Hey Jon .... I am thinking of using a prop1 and hb25 for a model in a window display. The display is a small cable car that travels about 5 feet back and forth between 2 mountain peaks. It will be running about 15 hours a day for two months in a Christmas display and needs to be as reliable as possible. My current thoughts are as follows:

1) 12 dc gear motor driven with a HB 25  ( Pin 3 output )    * motor drives a capstan forward and reverse pulling and unraveling cable moving tramcar
2) non contact opto sensor mountain 2    ( Pin 2 input )      * opto sensor sinks pin 2 low when tramcar is at the destination mountain
3) non contact opto sensor mountain 1    ( Pin 1 input )      * opto sensor sinks pin 1 low when tramcar is at the home mountain

So.....

On startup the tramcar travels to the destination mountain (forward)
When the  opto sensor 2 detects the car ( input 2 sinks to gnd ) , the motor stops , delays 5 seconds , reverses direction, Tramcar travels back to the home mountain.
When the opto sensor 1 detects the car ( input 1 sinks to gnd ) , the motor stops , delays 5 seconds  and the sequence starts all over again.......

I am sure this type of thing has been done before ....  any refinements you might suggest ?/do you have any example code for this ?

JonnyMac

In fact, I just wrote similar program for a company that specializes in high-end window displays.

First things first: Please don't call me or John B out as this has a tendency to dis-invite others to give you feedback.  This is a community (operated by EFX-TEK) and we want to encourage participation by all (see #11 in our forum guidelines).
-- http://www.efx-tek.com/php/smf/index.php?topic=266.0

Okay, here's an idea for you to work with.  Instead of simply starting and stopping it accelerates from and decelerates to end points.  You'll need to adjust the speeds in the table and the loop timing.

Note: I moved your sensor pins to 6 and 7 so that you can clip the ULN pins and move the SETUP jumpers to UP.  If your sensor has an internal pull-up then you can leave the SETUP jumper out.  Either way, you need to clip the associated ULN pins as they inputs on the ULN have pull-downs.  See this post regarding the ULN:
-- http://www.efx-tek.com/php/smf/index.php?topic=130.0


' =========================================================================
'
'   File...... HB-25_Train.BS1
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 14 OCT 2010
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  FStop           = PIN7                  ' no ULN; SETUP = UP
SYMBOL  RStop           = PIN6                  ' no ULN; SETUP = UP

SYMBOL  HB25Chk         = PIN5                  ' P5 input; no ULN
SYMBOL  HB25            = 5                     ' P5 control

SYMBOL  Trigger         = PIN0                  ' active-high input


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

SYMBOL  YES             = 0                     ' for active-low inputs
SYMBOL  NO              = 1

SYMBOL  FWD_SPEED       = 0                     ' base address of table
SYMBOL  REV_SPEED       = 6


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

SYMBOL  timer           = B2                    ' for trigger debounce
SYMBOL  idx             = B3                    ' for loops
SYMBOL  pntr            = B4                    ' EE pntr
SYMBOL  speed           = B5                    ' 100 to 200


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

Check_Motor:
  PAUSE 5
  IF HB25Chk = 0 THEN Check_Motor               ' allow HB25 to initialize
  LOW HB25                                      ' set for PULSOUT
  GOSUB Stop_Motor


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 50 THEN Check_Trigger              ' wait for 0.05 sec input


Train_Fwd:
  FOR idx = 1 TO 5                              ' accellerate forward
    pntr = FWD_SPEED + idx                      ' create pointer
    READ pntr, speed                            ' get speed
    GOSUB Set_Motor_Speed                       ' update motor
    PAUSE 250                                   ' fixed -- could use table
  NEXT

Check_Fwd_Stop:                                 ' watch for stop sensor
  IF FStop = NO THEN Check_Fwd_Stop

Train_Stop_Fwd:
  FOR idx = 4 TO 0 STEP -1                      ' decellarte to forward stop
    pntr = FWD_SPEED + idx
    READ pntr, speed
    GOSUB Set_Motor_Speed
    PAUSE 150
  NEXT

  PAUSE 5000                                    ' hold at full foward position


Train_Rev:
  FOR idx = 1 TO 5                              ' accellerate reverse
    pntr = REV_SPEED + idx
    READ pntr, speed
    GOSUB Set_Motor_Speed
    PAUSE 250
  NEXT

Check_Rev_Stop:                                 ' watch for stop sensor
  IF RStop = NO THEN Check_Rev_Stop

Train_Stop_Rev:
  FOR idx = 4 TO 0 STEP -1                      ' decelerate to starting point
    pntr = REV_SPEED + idx
    READ pntr, speed
    GOSUB Set_Motor_Speed
    PAUSE 150
  NEXT

  PAUSE 5000                                    ' hold at start point
  GOTO Main                                     ' look for next trigger


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

Stop_Motor:
  PAUSE 6                                       ' command hold-off
  PULSOUT HB25, 150                             ' center = stop
  PAUSE 6                                       ' command hold-off
  PULSOUT HB25, 150                             ' insurance command
  RETURN

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

Set_Motor_Speed:
  PAUSE 6                                       ' command hold-off
  PULSOUT HB25, speed                           ' set speed/direction
  RETURN

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


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


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

Forward_Speeds:                                 ' table at 0-5
  EEPROM (150, 160, 170, 180, 190, 200)


Reverse_Speeds:                                 ' table at 6-11
  EEPROM (150, 140, 130, 120, 110, 100)


Jon McPhalen
EFX-TEK Hollywood Office

Eric

Thank You .... It worked pretty well ...  ( the HB25 seems to have a spazing issue sometimes on startup for some reason )

JonnyMac

You will probably need to change the ramp tables to smooth things out.
Jon McPhalen
EFX-TEK Hollywood Office