Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
void movestraight(void);void moveright(void);void moveleft(void);void movebrake(void);void main(){ TRISB = 0x00; //Port B as output TRISD = 0xFF; //Port D as input PORTB = 0xFF; PORTD = 0xFF; while (1) { if (PORTD.F0 == 0) { movestraight (); } else if (PORTD.F1 == 0) { moveright (); } else if (PORTD.F2 == 0) { moveleft (); } else if (PORTD.F3 == 0 ) { movebrake (); } }}void movestraight(void){ //Move forward PORTB.F4 = 1; //I1 high PORTB.F5 = 0; //I2 low PORTB.F6 = 0; //I3 low PORTB.F7 = 1; //I4 high}void moveright(void){ //Move right PORTB.F4 = 1; PORTB.F5 = 0; PORTB.F6 = 1; PORTB.F7 = 0;}void moveleft(void){ //Move left PORTB.F4 = 0; PORTB.F5 = 1; PORTB.F6 = 0; PORTB.F7 = 1;}void movebrake(void){ //Brake PORTB.F4 = 0; PORTB.F5 = 0; PORTB.F6 = 0; PORTB.F7 = 0;}
ur using pwm right l293d works with pwm dont use normal on and off procedure
put else { movebrake (); }
Have you used pull up resistors on your inputs? Otherwise they will all have high impedance when not grounded and this can lead to strange results.Also, if this doesn't fix your problem, can you post what compiler you are using and what PIC you are using. Thanks
What happens when you turn the robot on? Do the motors always go the same way? Which way is it if they do? Do you have access to debug features? (ie are you using an ICD2 or a PICkit?)Who makes the compiler?
Right, i can't see any problems with your code. You need to use the debugging facilities on your programmer/software so step through each command step by step. Use a multimeter to check that the pins are actually turning on and off. Thats all i can recommend.
void movestraight(void);void moveright(void);void moveleft(void);void movebrake(void);void main(){ TRISB = 0x00; //Port B as output TRISD = 0xFF; //Port D as input PORTB = 0xFF; PORTD = 0xFF; while (1) { /* if (PORTD.F0 == 0) { movestraight (); } else if (PORTD.F1 == 0) { moveright (); } else */ if (PORTD.F2 == 0) { moveleft (); } /* else if (PORTD.F3 == 0 ) { movebrake (); } */ }}/* void movestraight(void){ //Move forward PORTB.F4 = 1; //I1 high PORTB.F5 = 0; //I2 low PORTB.F6 = 0; //I3 low PORTB.F7 = 1; //I4 high} */void moveright(void){ //Move right PORTB.F4 = 1; PORTB.F5 = 0; PORTB.F6 = 1; PORTB.F7 = 0;}void moveleft(void){ //Move left PORTB.F4 = 0; PORTB.F5 = 1; PORTB.F6 = 0; PORTB.F7 = 1;}void movebrake(void){ //Brake PORTB.F4 = 0; PORTB.F5 = 0; PORTB.F6 = 0; PORTB.F7 = 0;}
void main(){ TRISB = 0x00; //Port B as output TRISD = 0xFF; //Port D as input PORTB = 0xFF; PORTD = 0xFF; PORTB.F4 = 1; //I1 high PORTB.F5 = 0; //I2 low PORTB.F6 = 0; //I3 low PORTB.F7 = 1; //I4 high while(1);}
hmmm this is tricky....try making some really simple code, then build it up, and you should see where the bug comes into play.like this - Code: [Select]void main(){ TRISB = 0x00; //Port B as output TRISD = 0xFF; //Port D as input PORTB = 0xFF; PORTD = 0xFF; PORTB.F4 = 1; //I1 high PORTB.F5 = 0; //I2 low PORTB.F6 = 0; //I3 low PORTB.F7 = 1; //I4 high while(1);}Do that and see if it goes forward.If it does, change it to 1010 and see if it moves right.
Please verify with an oscilloscope that the pins are in fact going high or low when they should. Sometimes functionality on a pin or two on microcontrollers just dies unexpectedly. Usually related to static electricity.
And get out a multimeter to voltage test the other pins, too.
int threshold=8;//the larger this number, the more likely your robot will drive straight
if(sensor_left > sensor_right && (sensor_left - sensor_right) > threshold)