I am unable to test this due to not having motors, though based on what you have said, I would think that this would work:
DEVICE P8X32A, XTAL1, PLL16X
XIN 5_000_000
Ma PIN 20 OUTPUT
Mb PIN 19 OUTPUT
CHa PIN 0 INPUT
X VAR Long
MOTOR2 TASK
PROGRAM Start
Start:
LOW MA
LOW MB
PULSIN CHa, 1, X
IF X < 1400 THEN M1R
IF X > 1600 THEN M1F
GOTO START
M1F:
LOW MA
HIGH MB
PAUSE 18
GOTO START
M1R:
LOW MB
HIGH MA
PAUSE 18
GOTO START
TASK MOTOR2
Mc PIN 17 OUTPUT
Md PIN 16 OUTPUT
CHb PIN 1 INPUT
MOTOR2CODE:
Y VAR Long
LOW MC
LOW MD
PULSIN CHb, 1, Y
IF Y > 1625 THEN M2F
IF Y < 1375 THEN M2R
GOTO MOTOR2CODE
M2F:
LOW MC
HIGH MD
GOTO MOTOR2CODE
M2R:
LOW MD
HIGH MC
GOTO MOTOR2CODE
ENDTASK
Hi
Glad you got your program running.It should not be necessary to have a seperate task for motor 1.If you comment out the following lines
MOTOR1 TASK AUTO
TASK MOTOR1
ENDTASK
program should still run.One downside to using two tasks is that 3 cogs are required. The function of the first cog is simply to start up the other two.I notice in your final program that you have inserted another "IF" condition and perhaps that is why you were having problems.
Comments
DEVICE P8X32A, XTAL1, PLL16X
XIN 5_000_000
MOTOR1 TASK AUTO
MOTOR2 TASK AUTO
PROGRAM Start
Start:
TASK MOTOR1
Ma PIN 20 OUTPUT
Mb PIN 19 OUTPUT
CHa PIN 0 INPUT
X VAR Long
MOTOR1C:
LOW MA
LOW MB
PULSIN CHa, 1, X
IF X < 1400 THEN M1R
IF X > 1600 THEN M1F
IF X > 1400 THEN MOTOR1C
M1F:
LOW MA
HIGH MB
PAUSE 18
GOTO MOTOR1C
M1R:
LOW MB
HIGH MA
PAUSE 18
GOTO MOTOR1C
ENDTASK
TASK MOTOR2
Mc PIN 17 OUTPUT
Md PIN 16 OUTPUT
CHb PIN 1 INPUT
Y VAR Long
MOTOR2C:
LOW Mc
LOW Md
PULSIN CHb, 1, Y
IF Y < 1375 THEN M2R
IF Y > 1625 THEN M2F
IF Y > 1375 THEN MOTOR2C
M2F:
LOW MC
HIGH MD
PAUSE 18
GOTO MOTOR2C
M2R:
LOW MD
HIGH MC
PAUSE 18
GOTO MOTOR2C
GOTO MOTOR2C
ENDTASK
this code works perfect..project complete
Glad you got your program running.It should not be necessary to have a seperate task for motor 1.If you comment out the following lines
MOTOR1 TASK AUTO
TASK MOTOR1
ENDTASK
program should still run.One downside to using two tasks is that 3 cogs are required. The function of the first cog is simply to start up the other two.I notice in your final program that you have inserted another "IF" condition and perhaps that is why you were having problems.
regards
Gerry