In SX Microcontrollers, SX/B Compiler and SX-Key Tool, bean wrote: Here are some of the problems with the code: [code] 'Directives DEVICE SX28, OSCHS3, TURBO, STACKX, OPTIONX IRC_CAL IRC_FAST FREQ 50000000 'Pins [b][i]***pins must be declared with PIN instead of VAR[/i] [/b]StepperCoil1 var RB.0 OUTPUT StepperCoil2 var RB.1 OUTPUT StepperCoil3 var RB.2 OUTPUT StepperCoil4 var RB.3 OUTPUT FIDLEPulse var RB.5 INPUT 'y SleepSense Var RB.6 INPUT 'Always high, unless powered down. 'Variables DutyCycle Var byte 'range from 1 to 50 PrevStepPos var word 'range from 1 to 250 StepBank Var word Bank1 Var byte Bank2 Var byte Bank3 Var byte Bank4 Var byte ContinueBank Var byte HysteresisVar Var byte RelStepVar Var byte 'Constants [i][b]***You cannot declare a constant based on a variable[/b] [/i]StepCon Con 5*DutyCycle 'x Hysteresis Con ABS Hysteresis2 ' [i][b]*** SX/B doesn't have ABS[/b][/i] Hysteresis2 Con StepBank-PrevStepPos RelStep Con (StepBank-PrevStepPos) ContinueAddr Con 5 PrevStepAddr Con 6 Bank1Addr Con 1 Bank2Addr Con 2 Bank3Addr Con 3 Bank4Addr Con 4 [b][i]'*** You need to declare you subroutines here[/i][/b] [b][i]ClearCoils SUB 0[/i][/b] [b][i]InitMove SUB 0[/i][/b] [b][i]HysteresisDet SUB 0[/i][/b] [b][i]ForwardStep SUB 0[/i][/b] 'Main Protocol PROGRAM Main Main: 'IF SleepSense=LOW THEN GOSUB ClearCoils 'Resets stepper motor 'Pause 500 'Pause 500us 'GOTO Main GOSUB ClearCoils PULSIN RB.5,1,DutyCycle GET ContinueAddr,ContinueBank [i][b]'*** You can just use "ContinueBank = ContinueAddr"[/b][/i] IF ContinueBank=0 THEN GOSUB InitMove ELSE GOSUB HysteresisDet ENDIF GOTO Main 'Subroutines InitMove: PUT ContinueAddr,1 [b][i]' *** You can just use "ContinueAddr = 1"[/i][/b] FOR StepBank = 0 to StepCon GOSUB ForwardStep NEXT PUT PrevStepAddr,StepBank GOTO Main HysteresisDet: GET PrevStepAddr,PrevStepPos LET HysteresisVar = Hysteresis IF HysteresisVar < 10 THEN GOSUB Pause1 'Hysteresis statement ELSE GOSUB MoveDet ENDIF MoveDet: PUT Bank1Addr,0 PUT Bank2Addr,0 PUT Bank3Addr,0 PUT Bank4Addr,0 LET RelStepVar = RelStep IF RelStepVar > 0 THEN 'RelStep GOSUB FwdMov ELSE GOSUB RvsMov ENDIF FwdMov: FOR StepBank = 0 to Hysteresis GOSUB ForwardStep NEXT GOSUB HoldCoils PUT PrevStepAddr,StepCon 'Will this overwrite? RvsMov: FOR StepBank = 0 to Hysteresis GOSUB ReverseStep NEXT GOSUB HoldCoils PUT PrevStepAddr,StepCon Pause1: PAUSE 250 GOTO Main ForwardStep: GET Bank1Addr, Bank1 IF Bank1=0 THEN HIGH StepperCoil1 PUT Bank1Addr,1 RETURN ENDIF GET Bank2Addr, Bank2 IF Bank2=0 THEN HIGH StepperCoil2 PUT Bank2Addr,1 RETURN ENDIF GET Bank3Addr, Bank3 IF Bank3=0 THEN HIGH StepperCoil3 PUT Bank3Addr,1 RETURN ENDIF HIGH StepperCoil4 PUT Bank1Addr,0 PUT Bank2Addr,0 PUT Bank3Addr,0 RETURN ReverseStep: GET Bank4Addr, Bank4 IF Bank4 = 0 THEN HIGH StepperCoil4 PUT Bank4Addr,1 RETURN ENDIF GET Bank3Addr, Bank3 IF Bank3 = 0 THEN HIGH StepperCoil3 PUT Bank3Addr,1 RETURN ENDIF GET Bank2Addr, Bank2 IF Bank2 = 0 THEN HIGH StepperCoil2 PUT Bank2Addr,1 RETURN ENDIF HIGH StepperCoil1 PUT Bank1Addr,0 PUT Bank2Addr,0 PUT Bank3Addr,0 RETURN HoldCoils: HIGH StepperCoil1 HIGH StepperCoil2 HIGH StepperCoil3 HIGH StepperCoil4 RETURN ClearCoils: 'Shutdown routine LOW StepperCoil1 LOW StepperCoil2 LOW StepperCoil3 LOW StepperCoil4 PUT ContinueAddr,0 RETURN [/code] I would suggest studying the example programs in the help file. Bean. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=155208#m155222 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)