Urgent issue with encoder interrupts and PID control

Discussion in 'Embedded Systems and Microcontrollers' started by ultrablaze, May 27, 2014.

  1. ultrablaze

    Thread Starter New Member

    May 25, 2014

    We are a group of engineering students very close to a deadline on a robotics projects (roughly 32 hours...)

    We are stuck because of what seems to be a timing issue that is causing us to miss encoder ticks when we try to move the robot at any decent speed. We are using 2048 PPR rotary encoders handled via interrupts, and want to use the data to update a PID control system for the motors.

    We designed to the system on Matlab to handle via an error on position and speed, for now we would be happy enough if just the position part worked properly. We are using an arduino mega 2560 for our robot.

    Originally we had coded the interrupt functions so it got ticks on both A and B of each encoder using 2 digitalReadFast2 for each.
    We called the automatic control functions through an isrt running through flexiTimer at different intervals (we had hoped for every 50ms but even 200ms would be fine).

    We would miss ticks constantly, and would cover about 33cm for the robot to have thought it covered 30. We think this is because somewhere we are missing ticks, possibly due to interference from the flexitimer interrupt...?

    So a few questions :
    1) any idea on our problem?
    2) is flexitimer interrupt going to interfere with the encoder interrupts?
    If we try and call the function every 50ms with milis() that's even worse right since it disables them reactionaries interrupts whenever called? Anyway to do something with interrupt priority to be sure not to miss ticks?
    3) is there a difference between digitalReadFast and digitalReadFast2?

    We are trying to modify the interrupt functions for the encoders based on this article :

    We hope this will maybe make the interrupt routines for the encoders faster and let us miss less ticks. Currently on no access to internet on my phone but I'll get my code up ASAP.

    Thank you for Any help, we are totally stuck! We aren't that familiar with real time operating constraints yet.
    Last edited: May 27, 2014