Shop OBEX P1 Docs P2 Docs Learn Events
propb ?: need help adding a cog to make four lines run at same time..totally lost..? - Page 2 — Parallax Forums

propb ?: need help adding a cog to make four lines run at same time..totally lost..?

2»

Comments

  • davidsaundersdavidsaunders Posts: 1,559
    edited 2011-05-17 10:19
    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
    
    
    
    
    
  • davidsaundersdavidsaunders Posts: 1,559
    edited 2011-05-17 10:20
    If this does not help I hope someone else may be better situated to help you.
  • cazman128cazman128 Posts: 25
    edited 2011-05-17 10:27
    If this does not help I hope someone else may be better situated to help you.

    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
  • davidsaundersdavidsaunders Posts: 1,559
    edited 2011-05-17 10:30
    I do hope that this helped you to understand the use of Cogs with PropBASIC. I am glad that your project is now complete.
  • GerryKeelyGerryKeely Posts: 12
    edited 2011-05-17 11:42
    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.

    regards
    Gerry
Sign In or Register to comment.