Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problem with motor for bot

  1. Jul 25, 2009 #1
    // first write the basic functionality for motion
    void left_forward() {
    PORTC.F0 =1;
    PORTC.F1 =0;
    }
    void left_reverse() {
    PORTC.F0 =0;
    PORTC.F1 =1;
    }
    void left_stop() {
    PORTC.F0 =0;
    PORTC.F1 =0;
    }

    void right_forward() {
    PORTC.F5 =1;
    PORTC.F6 =0;
    }
    void right_reverse() {
    PORTC.F5 =0;
    PORTC.F6 =1;
    }
    void right_stop() {
    PORTC.F5 =0;
    PORTC.F6 =0;
    }

    void setup_P16F690() {
    // This is all the stuff thats needed for the chip
    ANSEL=ANSELH=0;
    PORTC=0;
    TRISC=0;
    }

    main() {
    setup_P16F690();
    while(1) { // Do this forever
    left_forward();
    delay_ms(1000); // Wait 1000 ms = 1sec
    left_reverse();
    delay_ms(1000); // Wait 1000 ms = 1sec
    left_stop();
    delay_ms(2000); // Wait 1000 ms = 1sec
    }

    while(1) { // Do this forever
    right_forward();
    delay_ms(1000); // Wait 1000 ms = 1sec
    right_reverse();
    delay_ms(1000); // Wait 1000 ms = 1sec
    right_stop();
    delay_ms(2000); // Wait 1000 ms = 1sec
    }
    }

    I am new to programming just started learning it a few days ago. I wrote this for a robot im working on and can't get the right wheel to move. The left one works fine. thanks for any help
     
  2. jcsd
  3. Jul 25, 2009 #2

    rcgldr

    User Avatar
    Homework Helper

    There is nothing to break out of the first while loop. The program is just going to cycle the left motor through the various modes for as long as the program runs. Perhaps you were thinking that these while loops ran in parallel, but they don't. They are run sequentially, but since the first while loop never exits, the program never gets to the second while loop.

    Remove the while(1){ }'s from the program and it should do one left cycle, then one right cycle.
     
  4. Aug 2, 2009 #3
    Well the Problem appears to be that program was tampered by a rodent, also the the robot seems to represent a christmas tree when it should rellay have no religous affliation. Other than that it looks good.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Problem with motor for bot
  1. Problems with zheev (Replies: 4)

  2. Javascript problem (Replies: 6)

  3. Problem with dgesv (Replies: 5)

Loading...