Coder Error Light

Now that our encoders count, we have other problems. PWM’s one and two have enabled encoders. Sometimes when i run those motors they suddenly stop responding and the code error light starts blinking on the OI:yikes: . could this be caused by faulty encoders? Or is it an infinite interrupt loop? The code compiles fine, with not even a warning (Using MPLab). What could be causing the problem?:confused: Thanks in advance

There are a number of possible causes for this. One possibility is that your encoders are generating too many interrupts per second, which is keeping the rest of the code from completing its task in a timely manner. Can you give us more information about what encoders you’re using, where they’re attached to your drivetrain, and when the problem occurs (only when you’re driving fast, or sporadically)?

the generate 128 clicks per revolution, at about 400 RPM (i think) we have an encoder divider board, do you suggest we implement that? generally it happens when i drive fast, but not always. i have it rigged right now so that it prints 1 when the first encoder fires, and 2 when the second one fires. the last line it prints is, “----2------------”

…Are you printing out those inside the interrupts? If so, that’s most likely your problem. printf takes too long to execute inside an interrupt.

Actually, i just realized: when it hits the violation, the motors were running, and the print statements were activated. What i mean is that we have a function , PrintData():

	printf("\r------------------------- USER INPUTS -------------------------------\r");
	printf("Joystick 1 Y-axis: %d	 Joystick 1 Trigger: %d\r", left_joy, p1_sw_trig);
	printf("Joystick 2 Y-axis: %d	 Joystick 2 Trigger: %d\r", right_joy, p2_sw_trig);
	printf("\r------------------------- PWM OUTPUTS -------------------------------\r");
 	printf("Left Motor: %d	 Right Motor: %d\r",  (int)left_motor, (int)right_motor);
 	printf("Relay 1 Forward: %d	 Relay 1 Reverse: %d\r", relay1_fwd, relay1_rev);
 	printf("Relay 2 Forward: %d	 Relay 2 Reverse: %d\r", relay2_fwd, relay2_rev);

/*	printf("\r------------------------- SENSORS -------------------------------\r");
	printf("\r------------------------- VARIABLES -------------------------------\r");
	printf("Alt Left Encoder: %dl	 Alt Right Encoder: %dl\r", Encoder_1_Counter, Encoder_2_Counter);

i think maybe the encoders fired during the print statement, which would explain the hyphens. Do you think that could cause problems

i’m actually using puts(“1”); which my dad said would work… could that be the problem?

That’s a lot of clicks. I can’t promise you that your problem is oversaturating the interrupts, but it’s the first thing I would investigate. Plug in your divider board, and use the highest divider you can. If that eliminates the problem, you can go to finer resolution as long as it’s still working. I’m sure there are other possible causes for this problem, but they would be impossible to find without seeing your code, and maybe still impossible then. In any case, try that first.

EDIT: Now that I see your latest post, you definitely shouldn’t be doing anything in your interrupt handler other than incrementing a variable or something. That would be the first thing I would fix, if you are indeed doing a puts or something in there.

YAY that fixed it. thanks! I only had them cuz the encoders weren’t working before, so we put prints on everything that had anything to do with it