' ' Program: FOX Stepper Motor Program v3.0 ' Author: (c) 2007 by A Fox Consulting & Design ' http://www.afox-consulting.com ' Date: 10/03/2007 ' ' Interface with VFD2041 display @ 9600 ' Interface with Little Step-U unipolar stepper motor controller @ 2400 ' (We're no longer driving the coils ourselves!) ' ' I/O pin 15 = VFD Rx ' I/O pin 14 = VFD Tx ' I/O pin 13 = Little Step-U Rx ' I/O pin 12 = Little Step-U Tx ' I/O pin 11 = Little Step-U BUSY ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ---------- I/O Definitions ---------- _VFDTx PIN 15 _VFDRx PIN 14 _STEPTx PIN 13 _STEPRx PIN 12 _STEPBUSY PIN 11 ' ---------- Variables ---------- ' Stuff for the stepper motoe stpCount VAR Word stpSpeed VAR Word stpAccel VAR Byte stpDir VAR Bit stpDelay VAR Word RSeed VAR Word ' Stuff for the stepper motoe DBaud CON 32 ' 19200,8,N,1 for display SBaud CON 396 ' 2400,n,8,1 for Little Step-U CTRL CON $FE CLRSCR CON $58 CRSRPOS CON $47 ' Position Cursor NOWRAP CON $44 ' Turn auto line-wrap off INITHBAR CON $68 DRAWHBAR CON $7C ' ---------- Main Code ---------- Setup: OUTPUT _VFDTx INPUT _VFDRx OUTPUT _STEPTx INPUT _STEPRx INPUT _STEPBUSY PAUSE 500 ' Wait for display to become ready GOSUB Init_Display Rseed = $F438 ' Just a random seed to start with Main: GOSUB Display_Loading RANDOM Rseed ' Make a speed of 25 - 175 steps/sec in 50 step/sec intervals 'stpSpeed = 2 stpSpeed = ((Rseed // 12) * 25) + 25 stpAccel = 0 ' Make a step count of 10 - 250 steps in 10 step inctements stpCount = ((Rseed // 25) * 10) + 10 ' Make adjustments for higher speeds IF stpSpeed > 199 THEN stpAccel = 25 ' 2.5 second ramp up/down on speed stpCount = stpCount + 300 ' Add an extra 300 steps ELSE IF stpSpeed > 99 THEN stpAccel = 15 ' 1.5 second ramp up/down on speed stpCount = stpCount + 100 ' Add an extra 100 steps ENDIF ENDIF ' Make random direction RANDOM Rseed stpDir = Rseed // 2 ' Make the motor move! GOSUB Set_Motor_Params GOSUB Display_Values GOSUB Wait_For_Motor GOSUB Display_Paused ' Make random pause between 0 and 1 second in .1 second intervals RANDOM Rseed stpDelay = (Rseed // 10) * 100 PAUSE stpDelay GOTO Main ' ---------- Stepper Motor Functions ---------- Set_Motor_Params: SEROUT _STEPTx, SBaud, ["{A", DEC stpSpeed, "}"] SEROUT _STEPTx, SBaud, ["{B", DEC stpAccel, "}"] SEROUT _STEPTx, SBaud, ["{C0}"] ' Full Step Mode SEROUT _STEPTx, SBaud, ["{P1}"] ' Power to coils when idle IF stpDir = 0 THEN SEROUT _STEPTx, SBaud, ["{E", DEC stpCount, "}"] ELSE SEROUT _STEPTx, SBaud, ["{E-", DEC stpCount, "}"] ENDIF RETURN Wait_For_Motor: PAUSE 10 WaitLoop: IF _STEPBUSY = 1 THEN Waitloop 'Wait till not busy PAUSE 1 RETURN ' ---------- VFD Functions ---------- Init_Display: SEROUT _VFDTx, DBaud, [CTRL, CLRSCR] SEROUT _VFDTx, DBaud, [CTRL, NOWRAP] SEROUT _VFDTx, DBaud, [CTRL, INITHBAR] SEROUT _VFDTx, DBaud, ["--FoxMotor3.bs2--"] RETURN Display_Values: SEROUT _VFDTx, DBaud, [CTRL, CRSRPOS, 1, 2] SEROUT _VFDTx, DBaud, ["Steps: ", DEC3 stpCount, " Dir: ", DEC stpDir, CR, LF, "Speed: ", DEC3 stpSpeed, " Accel "] SEROUT _VFDTx, DBaud, [CTRL, CRSRPOS, 18, 3, (stpAccel DIG 1)+48, ".", (stpAccel DIG 0)+48] 'SEROUT _VFDTx, DBaud, [CTRL, DRAWHBAR, 12, 4, 0, 30 - (stpDelay*5)] SEROUT _VFDTx, DBaud, [CTRL, CRSRPOS, 1, 4, "RUNNING "] RETURN Display_Loading: SEROUT _VFDTx, DBaud, [CTRL, CRSRPOS, 1, 2, "LOADING... ", CR, LF, " ", CR, LF, " "] RETURN Display_Paused: SEROUT _VFDTx, DBaud, [CTRL, CRSRPOS, 1, 4, "OFF "] RETURN