What could be causing one wheel of my robot to not move?

  • Thread starter Thread starter DrDanger
  • Start date Start date
  • Tags Tags
    Motor
Click For Summary
SUMMARY

The issue with the robot's right wheel not moving is due to the use of two infinite while loops in the main function, which prevents the program from executing the second loop for the right wheel. The left wheel operates correctly because its loop runs indefinitely, while the right wheel's loop is never reached. To resolve this, the infinite while loops should be removed, allowing the program to cycle through both the left and right wheel functions sequentially.

PREREQUISITES
  • Understanding of C programming language
  • Familiarity with microcontroller programming, specifically the PIC16F690
  • Basic knowledge of motor control using GPIO pins
  • Experience with debugging simple embedded systems
NEXT STEPS
  • Learn about control flow in C programming, specifically the use of loops
  • Research how to implement state machines for motor control
  • Explore debugging techniques for embedded systems
  • Study the functionality of the PIC16F690 microcontroller and its GPIO configuration
USEFUL FOR

Beginner programmers, hobbyists working on robotics, and anyone interested in embedded systems development.

DrDanger
Messages
44
Reaction score
0
// 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 that's 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 I am working on and can't get the right wheel to move. The left one works fine. thanks for any help
 
Technology news on Phys.org
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.
 
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 religious affliation. Other than that it looks good.
 

Similar threads

Replies
1
Views
2K
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
Replies
2
Views
3K
Replies
3
Views
6K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 49 ·
2
Replies
49
Views
5K