danielwi11iams
New Member
Sorry for a long Thread...
I have some code, but would like to add one more part to the program, but I running out of chip space.
I'm using it to control three servos, and slow them down on a model RC helicopter. I need the servo for the front doors to reverse after the wheels have come down and visa versa when they go up. But when I add it to the code/program it makes it to long to fit in the chip memory. I'm new to this and have a very small knowledge of PIC programming. is their a way of making the program smaller.
i.e. trying to make it do what I want it to do but maybe using different commands.
Any help would be appreciated.
Here is my code: there maybe some mistakes, but I can correct them if there is away of making it smaller...
'*** Memory Lables ***
Symbol Delay=B1 'Name the Delay Factor
Symbol Skip=B2 'Name the Counter For Skipping "Delay" Times
Symbol Pulsein=B3 'Name the Input Pulse Width
Symbol PulseB4=B4 'Name the Width Of the prior Input Pulse Width
Symbol FrtDoor=B5 'Name the Output Pulse Width for Front Doors
Symbol BothDoor=B6 'Name the Output Pulse Width for Back Doors
Symbol PulWheel=B7 'Name the Output Pulse Width for Wheels
Symbol ErrFrtDrs=B8 'Name the Difference between Input and Output Pulse Width
Symbol ErrBckDrs=B9 'Name the Difference between Input and Output Pulse Width
Symbol ErrWheels=B10 'Name the Difference between Input and Output Pulse Width
Init:
Servo 0,135 'Front Door Servo
Servo 1,135 'Back Door Servo
Pause 1000
Servo 2,135 'Wheels Servo
Main:
Skip=0
Low 0,1,2 'Stop the Servo command if valid input detected
Readadc 4,Delay 'Read the voltage from the delay potentiometer
Pause 1000
Pulsin 3,1,Pulsein 'Measure the input pulse width initially
If Pulsein<75 or Pulsein>225 then Main 'Go back if no valid input detected
PulseB4=Pulsein 'Initially set the prior pulse width to current pulse width
If Delay<5 then StraightThru 'If delay pot set near zero skip slowdown routines
Delay=Delay/21 'Set delay to 0 (1.5s stop-to-stop) to 12 (20s stop-to-stop)
FrtDoor=Pulsein 'Set output pulse to input pulse initially
PulseWheel=Pulsein
Submain: 'Routine
PulseB4=Pulsein 'Reset the prior pulse width
Pulsin 3,1,Pulsein 'Measure the input pulse
If Pulsein<75 or Pulsein>225 then Main 'Go back if no valid input detected
MoveUp1: 'Routine = To Open the Doors to allow the wheel to go up into the body
ErrFrtDrs=Pulsein-FrtDoor
If ErrFrtDrs=0 or ErrFrtDrs>254 then StayPut
If FrtDoor>Pulsein then FrtDrsOpen
MoveUp2: 'Routine = To allow Wheels to go into the body
ErrWheels=Pulsein-PulseWheel
If ErrWheels=0 or ErrWheels>254 then StayPut
If PulseWheel<Pulsein then WheelsUp
MoveUp3: 'Routine = To close both Doors after the Wheels have gone into the body
ErrDoors=Pulsein-BothDoor
If ErrDoors=0 or ErrDoors>254 then StayPut
If BothDoor<Pulsein then DoorUp
MoveDown1: 'Routine = To Open both Doors before the Wheels come out of the body
ErrDoors=BothDoor-Pulsein
If ErrDoors=0 or ErrDoors>254 then StayPut
If BothDoor>Pulsein then DoorsOpen
MoveDown2: 'Routine = To allow Wheels to come out of the body
ErrWheels=PulseWheel-Pulsein
If ErrWheels=0 or ErrWheels>254 then StayPut
If PulseWheel>Pulsein then WheelDown
MoveDown3: 'Routine = To Close the Doors after the wheels have came out of the body
ErrFrtDrs=ErrFrtDrs-Pulsein
If ErrFrtDrs=0 or ErrFrtDrs>254 then StayPut
If FrtDoor<Pulsein then FrtDrsClose
'***Servo Change For Wheels To Come Up ***
FrtDrsOpen: 'Routine = To Open the Doors to allow the wheel to go up into the body
ErrFrtDrs=Pulsein-FrtDoor
If Skip>=Delay then FrtDrsOpen1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto FrtDrsOpen2
FrtDrsOpen1:
Skip=0
FrtDoor=FrtDoor+1
FrtDrsOpen2:
Pulsout 2,FrtDoor 'Send the output pulse to the servo
If PulseWheel=Pulsein then DoorUp1
Goto MoveUp1
WheelsUp: 'Routine = To allow Wheels to go into the body
ErrWheels=Pulsein-PulseWheel
If Skip>=Delay then WheelUp1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto WheelUp2
WheelUp1:
Skip=0
PulseWheel=PulseWheel+1
WheelUp2:
Pulsout 2,PulseWheel 'Send the output pulse to the servo
If PulseWheel=Pulsein then DoorUp1
Goto MoveUp2
DoorUp: 'Routine = To close both Doors after the Wheels have gone into the body
ErrDoors=Pulsein-BothDoor
If Skip>=Delay then DoorUp1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto DoorUp2
DoorUp1:
Skip=0
BothDoor=BothDoor+1
DoorUp2:
Pulsout 0,BothDoor 'Send the output pulse to the servo
Pulsout 1,BothDoor 'Send the output pulse to the servo
Goto MoveUp3 'Return to re-measure the input pulse
'***Servo Change For Wheels To Come Down ***
DoorsOpen: 'Routine = To Open both Doors before the Wheels come out of the body
ErrDoors=BothDoor-Pulsein
If Skip>=Delay then DoorsOpen1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto DoorsOpen2
DoorsOpen1:
Skip=0
BothDoor=BothDoor-1
DoorsOpen2:
Pulsout 0,BothDoor 'Send the output pulse to the servo
Pulsout 1,BothDoor 'Send the output pulse to the servo
If BothDoor=Pulsein then WheelDown1
Goto MoveDown1
WheelDown: 'Routine = To allow Wheels to come out of the body
ErrWheels=PulseWheel-Pulsein
If Skip>=Delay then WheelDown1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto WheelDown2
WheelDown1:
Skip=0
PulseWheel=PulseWheel-1
WheelDown2:
Pulsout 2,PulseWheel 'Send the output pulse to the servo
Goto MoveDown2 'Return to re-measure the input pulse
FrtDrsClose: 'Routine = To Close the Doors after the wheels have came out of the body
ErrWheels=FrtDoor-Pulsein
If Skip>=Delay then FrtDrsClose1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto FrtDrsClose2
FrtDrsClose1:
Skip=0
FrtDoor=FrtDoor-1
FrtDrsClose2:
Pulsout 2,FrtDoor 'Send the output pulse to the servo
Goto MoveDown2 'Return to re-measure the input pulse
StayPut: 'Routine = To send the same output pulse
Pulsout 0,FrtDoor
Pulsout 1,BothDoor
Pulsout 2,PulseWheel
Goto Submain 'Return to re-measure the input pulse
StraightThru:
Pulsin 3,1,Pulsein
If Pulsein<75 or Pulsein>225 then Main 'Go back if no valid input detected
Goto StraightThru
I have some code, but would like to add one more part to the program, but I running out of chip space.
I'm using it to control three servos, and slow them down on a model RC helicopter. I need the servo for the front doors to reverse after the wheels have come down and visa versa when they go up. But when I add it to the code/program it makes it to long to fit in the chip memory. I'm new to this and have a very small knowledge of PIC programming. is their a way of making the program smaller.
i.e. trying to make it do what I want it to do but maybe using different commands.
Any help would be appreciated.
Here is my code: there maybe some mistakes, but I can correct them if there is away of making it smaller...
'*** Memory Lables ***
Symbol Delay=B1 'Name the Delay Factor
Symbol Skip=B2 'Name the Counter For Skipping "Delay" Times
Symbol Pulsein=B3 'Name the Input Pulse Width
Symbol PulseB4=B4 'Name the Width Of the prior Input Pulse Width
Symbol FrtDoor=B5 'Name the Output Pulse Width for Front Doors
Symbol BothDoor=B6 'Name the Output Pulse Width for Back Doors
Symbol PulWheel=B7 'Name the Output Pulse Width for Wheels
Symbol ErrFrtDrs=B8 'Name the Difference between Input and Output Pulse Width
Symbol ErrBckDrs=B9 'Name the Difference between Input and Output Pulse Width
Symbol ErrWheels=B10 'Name the Difference between Input and Output Pulse Width
Init:
Servo 0,135 'Front Door Servo
Servo 1,135 'Back Door Servo
Pause 1000
Servo 2,135 'Wheels Servo
Main:
Skip=0
Low 0,1,2 'Stop the Servo command if valid input detected
Readadc 4,Delay 'Read the voltage from the delay potentiometer
Pause 1000
Pulsin 3,1,Pulsein 'Measure the input pulse width initially
If Pulsein<75 or Pulsein>225 then Main 'Go back if no valid input detected
PulseB4=Pulsein 'Initially set the prior pulse width to current pulse width
If Delay<5 then StraightThru 'If delay pot set near zero skip slowdown routines
Delay=Delay/21 'Set delay to 0 (1.5s stop-to-stop) to 12 (20s stop-to-stop)
FrtDoor=Pulsein 'Set output pulse to input pulse initially
PulseWheel=Pulsein
Submain: 'Routine
PulseB4=Pulsein 'Reset the prior pulse width
Pulsin 3,1,Pulsein 'Measure the input pulse
If Pulsein<75 or Pulsein>225 then Main 'Go back if no valid input detected
MoveUp1: 'Routine = To Open the Doors to allow the wheel to go up into the body
ErrFrtDrs=Pulsein-FrtDoor
If ErrFrtDrs=0 or ErrFrtDrs>254 then StayPut
If FrtDoor>Pulsein then FrtDrsOpen
MoveUp2: 'Routine = To allow Wheels to go into the body
ErrWheels=Pulsein-PulseWheel
If ErrWheels=0 or ErrWheels>254 then StayPut
If PulseWheel<Pulsein then WheelsUp
MoveUp3: 'Routine = To close both Doors after the Wheels have gone into the body
ErrDoors=Pulsein-BothDoor
If ErrDoors=0 or ErrDoors>254 then StayPut
If BothDoor<Pulsein then DoorUp
MoveDown1: 'Routine = To Open both Doors before the Wheels come out of the body
ErrDoors=BothDoor-Pulsein
If ErrDoors=0 or ErrDoors>254 then StayPut
If BothDoor>Pulsein then DoorsOpen
MoveDown2: 'Routine = To allow Wheels to come out of the body
ErrWheels=PulseWheel-Pulsein
If ErrWheels=0 or ErrWheels>254 then StayPut
If PulseWheel>Pulsein then WheelDown
MoveDown3: 'Routine = To Close the Doors after the wheels have came out of the body
ErrFrtDrs=ErrFrtDrs-Pulsein
If ErrFrtDrs=0 or ErrFrtDrs>254 then StayPut
If FrtDoor<Pulsein then FrtDrsClose
'***Servo Change For Wheels To Come Up ***
FrtDrsOpen: 'Routine = To Open the Doors to allow the wheel to go up into the body
ErrFrtDrs=Pulsein-FrtDoor
If Skip>=Delay then FrtDrsOpen1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto FrtDrsOpen2
FrtDrsOpen1:
Skip=0
FrtDoor=FrtDoor+1
FrtDrsOpen2:
Pulsout 2,FrtDoor 'Send the output pulse to the servo
If PulseWheel=Pulsein then DoorUp1
Goto MoveUp1
WheelsUp: 'Routine = To allow Wheels to go into the body
ErrWheels=Pulsein-PulseWheel
If Skip>=Delay then WheelUp1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto WheelUp2
WheelUp1:
Skip=0
PulseWheel=PulseWheel+1
WheelUp2:
Pulsout 2,PulseWheel 'Send the output pulse to the servo
If PulseWheel=Pulsein then DoorUp1
Goto MoveUp2
DoorUp: 'Routine = To close both Doors after the Wheels have gone into the body
ErrDoors=Pulsein-BothDoor
If Skip>=Delay then DoorUp1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto DoorUp2
DoorUp1:
Skip=0
BothDoor=BothDoor+1
DoorUp2:
Pulsout 0,BothDoor 'Send the output pulse to the servo
Pulsout 1,BothDoor 'Send the output pulse to the servo
Goto MoveUp3 'Return to re-measure the input pulse
'***Servo Change For Wheels To Come Down ***
DoorsOpen: 'Routine = To Open both Doors before the Wheels come out of the body
ErrDoors=BothDoor-Pulsein
If Skip>=Delay then DoorsOpen1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto DoorsOpen2
DoorsOpen1:
Skip=0
BothDoor=BothDoor-1
DoorsOpen2:
Pulsout 0,BothDoor 'Send the output pulse to the servo
Pulsout 1,BothDoor 'Send the output pulse to the servo
If BothDoor=Pulsein then WheelDown1
Goto MoveDown1
WheelDown: 'Routine = To allow Wheels to come out of the body
ErrWheels=PulseWheel-Pulsein
If Skip>=Delay then WheelDown1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto WheelDown2
WheelDown1:
Skip=0
PulseWheel=PulseWheel-1
WheelDown2:
Pulsout 2,PulseWheel 'Send the output pulse to the servo
Goto MoveDown2 'Return to re-measure the input pulse
FrtDrsClose: 'Routine = To Close the Doors after the wheels have came out of the body
ErrWheels=FrtDoor-Pulsein
If Skip>=Delay then FrtDrsClose1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto FrtDrsClose2
FrtDrsClose1:
Skip=0
FrtDoor=FrtDoor-1
FrtDrsClose2:
Pulsout 2,FrtDoor 'Send the output pulse to the servo
Goto MoveDown2 'Return to re-measure the input pulse
StayPut: 'Routine = To send the same output pulse
Pulsout 0,FrtDoor
Pulsout 1,BothDoor
Pulsout 2,PulseWheel
Goto Submain 'Return to re-measure the input pulse
StraightThru:
Pulsin 3,1,Pulsein
If Pulsein<75 or Pulsein>225 then Main 'Go back if no valid input detected
Goto StraightThru