Help with PIC microcontroller and "jerky" wheel

I’ve had a PIC microcontroller for a vexbot for the past ~2 years. Recently though one of the four wheels has been ‘jerking’. It will go through about 3/4’s of a rotation and suddenly stop for about .5 seconds before continuing. I suspected a bad motor, so I replaced it. But it is still happening. Then I switched the motors/ports on the PIC (i.e., Motor1-> Motor Port #2 and Motor2 ->Motor Port #1) and found out that whichever motor was plugged into port 1 would jerk.

Also, I’ve coded a custom controller for the robot to use. I’ve noticed that if I use a very simple program (like having only motor[motor1]=50;) the jerking seems to go away. But it is there in my custom code, even though no other motors seem to be effected (and each motor has identical code).

Anybody run into any similar problems and/or have any suggestions?


There is an error in line 42 of the custom code you have not yet posted.

I didn’t post the code because I don’t think it’s relevant.

The code is identical for all 4 motors, but only one is messing up. And which one messes up depends on which motor is plugged into port #1. So I don’t think it’s a ode problem.

Oh, and before this problem arose, all four wheels and my custom controller worked just fine. It’s just that one motor stopped behaving properly for some reason.

Yet you ask for help because you don’t know what is wrong; if you don’t want advice different that what you can think of yourself, why post here? Sometimes it helps to talk it out, but you’ll have to write a lot more than you have before you can think of your own answer (in my own experience, anyway).

Scientific method often helps, make a hypothesis and test it.

H0: bad motor,
test: you swapped motors, but problem follows the port, not motor, this is evidence against H0. Thats an excellent start.

H1: since it follows the port, not the motor, I suspect ‘custom code’
test: other wheels don’t jerk, but code is same. Code hasn’t changed in 2 years.
test: we cant tell by inspection until you post it or attach it.

H2: “Wheel” vs motor? Jerking at the same place in 3/4 rotation sounds like a gear problem, do you have gears between the motors and the wheels?
test: inspect, or describe in more detail (picture) your robot.

H3: internal PIC power PTC tripping
test: do other motors jerk at same time, doesn’t seem likely…

Based on what you have described then the first conclusion would be a bad port on the PIC, however, you said this in your first post.

So with that additional information it seems more likely it is the code.

We don’t have the advantage of seeing the code, so what to do now.

I would suggest using an oscilloscope to look at the pwm signal going to the motor and verify that, but if you had access to a scope I doubt you would be posting here.

We need more information to be able to help you, pictures of the robot perhaps, and the custom code.

Alright, here’s the code (attached). But I still say it’s irrelevant. The code hasn’t changed for a while, but the jerking problem is recent.

I’ll try to get a few pics tomorrow.
customeCode.c (8.07 KB)

When did you last update the firmware on the robot. If you have changed laptop (and thus version of software) and not updated firmware to be the same as that on laptp you can see this sort of problem

I see from the code that you have a quad encoder associated with each motor and motor speed is based on encoder position, have you checked the encoder is working correctly? It looks like you may have swapped motors 1 and 3 as part of debugging. did you also swap encoders ?