I'm going through the interupt routine in gyro.c to figure it out, and I believe I found a major issue with it. Kevin: Please check!
In the interupt routine, it does the following things (in order):
- Initialize i and accum if calculating bias
- Set old_calc_gyro_bias to calc_gyro_bias
- Reads ADC value
- Adds it to the accumulator
- Begins another ADC conversion
- Adds to accumulator.
- Does biasing code
The problem with this is if you try to read an analog channel (and clear the ADC) outside of the interupt. For this to work correctly,
the gyro must be the only sensor connected to your analog inputs.
The Details:
The ADC converter works asyncronously from the controller. To use it, you have to:
- Set the channel or open it and wait for it to settle
- Tell it to begin a conversion
- Wait until it finishes
- Read the value
- Close it (?)
If anything is changed during a conversion, you have to start over from #2. The interrupt assumes that the conversion finnished successfully, and that the value in the registers is the one from the gyro. If you read a value, it will likely read the value from the last sensor you used.
Is there any fix to this? This seems to be a large blocker, since the gyro code is dependent on it.
And yes, I did update my code.