ABS operator and "Adress not within lower half of memory page" errors.
Hi all,
You'll have to bare with me, as I'm new to both programming and the SX chip. I'm currently running into a few problems while trying to compile my code, and I'd sure appreciate it if someone with more experience could give me a hand.
So, here's the gist of what's going on. I'm trying to write a program that translates the duty cycle of an incoming PWM signal into movement of a bipolar stepper motor. This stepper motor has a range of 0 to X steps, and basically, a 0%DC means the stepper is at position 0, while 100%DC means the stepper is at position X. The relationship is linear, so the rest is easy for the chip to figure out.
Now, the whole thing is coded in SX/B, and I've managed to get rid of all SX/B syntax errors. The only errors I'm encountering are while trying to compile in the converted assembly. It's giving me error codes for "Address not within lower half of memory page" for several of the subroutine labels. I did a little research, but due to my unfamiliarity with the SX assembly language, I couldn't even begin to figure out why it's giving me these errors.
Also, I'm trying to use an absolute value operator, but I don't really know how to implement this. I thought "ABS" could be used in PBASIC, so I assumed it could also be used in SX/B, but the SX-Key software is giving me problems when I try to convert to assembly.
I'm attaching a text file of the SX/B code, and assembly code for anyone who can help to look through. I'm also attaching an "algorithm" of pseudo-code that I wrote to help me make the actual code. It may help you understand what I was aiming for in case my programming is a little convoluted.
Again, I really appreciate any insight you can share with me. I'm new to programming, but I'm really very eager to learn, so your advice will not be wasted. Thanks again!
You'll have to bare with me, as I'm new to both programming and the SX chip. I'm currently running into a few problems while trying to compile my code, and I'd sure appreciate it if someone with more experience could give me a hand.
So, here's the gist of what's going on. I'm trying to write a program that translates the duty cycle of an incoming PWM signal into movement of a bipolar stepper motor. This stepper motor has a range of 0 to X steps, and basically, a 0%DC means the stepper is at position 0, while 100%DC means the stepper is at position X. The relationship is linear, so the rest is easy for the chip to figure out.
Now, the whole thing is coded in SX/B, and I've managed to get rid of all SX/B syntax errors. The only errors I'm encountering are while trying to compile in the converted assembly. It's giving me error codes for "Address not within lower half of memory page" for several of the subroutine labels. I did a little research, but due to my unfamiliarity with the SX assembly language, I couldn't even begin to figure out why it's giving me these errors.
Also, I'm trying to use an absolute value operator, but I don't really know how to implement this. I thought "ABS" could be used in PBASIC, so I assumed it could also be used in SX/B, but the SX-Key software is giving me problems when I try to convert to assembly.
I'm attaching a text file of the SX/B code, and assembly code for anyone who can help to look through. I'm also attaching an "algorithm" of pseudo-code that I wrote to help me make the actual code. It may help you understand what I was aiming for in case my programming is a little convoluted.
Again, I really appreciate any insight you can share with me. I'm new to programming, but I'm really very eager to learn, so your advice will not be wasted. Thanks again!


Comments
'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·I would suggest studying the example programs in the help file.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
·
I really appreciate your help.