Quote Originally Posted by DrDreas View Post
yes, it compiles at 1800 now because I commented out the sections that deal with servo control. So the best method of reducing the size is to create subroutines for repeated code blocks?
Just had a look, how about some of this:

Combine math in this chunk of code if possible:
Alpha=Ratio*51 + 532*10
Alpha=Alpha/10

Instead of /2, use >> 1 (shift right by one bit = divide by 2), example:
if Alpha < (ServoArc/2) then.......becomes:
if Alpha < ( ServoArc >> 1 ) then

Same thing with any multiply or divide by a power of two, use a shift << for multiply, shift >> for divide

Like Ace said, combine your subroutines a bit:

SectionA:
RawCompass=(UpLimit - A_Curve) * Scale: gosub FIXCOMPASS
Compass=((RawCompass/10) << 2) /10
Heading=Compass
if Heading > ActuateOn and Heading < ActuateOff then
GOSUB SUBSECTION1
else
GOSUB SUBSECTION2
endif
GoTO Mainloop ' Do it indefinitely

SectionB:
RawCompass=(B_Curve - LowLimit) * Scale : gosub FIXCOMPASS
CrossZero=Compass + 2700
if CrossZero >= 3600 then SectionBA
Heading=CrossZero
if Heading > ActuateOn and Heading < ActuateOff then
GOSUB SUBSECTION1
else
GOSUB SUBSECTION2 (and so on, but the rest aren't boldfaced for emphasis)
endif
GoTO Mainloop ' Do it indefinitely

SectionBA: ZeroCross=CrossZero -3600 :Heading=ZeroCross
if Heading > ActuateOn and Heading < ActuateOff then
GOSUB SUBSECTION1
else
GOSUB SUBSECTION2
endif
GoTO Mainloop ' Do it indefinitely

SectionC:
RawCompass=0:RawCompass=(UpLimit - B_Curve) * Scale
gosub FIXCOMPASS : Heading=Compass + 900
if Heading > ActuateOn and Heading < ActuateOff then
GOSUB SUBSECTION1
else
GOSUB SUBSECTION2
endif
GoTO Mainloop ' Do it indefinitely

SectionD:
RawCompass=(A_Curve - LowLimit) * Scale : gosub FIXCOMPASS
Heading=Compass + 1800
if Heading > ActuateOn and Heading < ActuateOff then
GOSUB SUBSECTION1
else
GOSUB SUBSECTION2
endif
GoTO Mainloop ' Do it indefinitely

Calibrate: IF A_Curve > 2048 THEN UpLimit=A_Curve ' Establish the actual upper limit
If A_Curve < 2048 THEN LowLimit=A_Curve ' Establish the actual lower limit
Spread=9000 / (UpLimit - LowLimit):Scale=(Spread * 10) >> 2:Return


SUBSECTION1:
high PortB.4: pulseWidth=2000:lowTime=20000 - pulsewidth:Low Servo
Pulsout Servo, pulseWidth/10:Pauseus lowTime
return

SUBSECTION2:
LOW PortB.4: pulseWidth=1500:lowTime=20000 - pulsewidth:Low Servo
Pulsout Servo, pulseWidth/10:Pauseus lowTime
return

FIXCOMPASS:
Compass=((RawCompass/10) << 2) /10
return


That might get your program on the chip. There's a couple of other optimizations relating to Bank'ing your variables, but that's a bit of an advanced subject. If the program still doesn't fit, re-post what you've got...maybe more optimizations will get 'er in there.