Quote:
|
Originally Posted by Astronouth7303
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.
|
Did you read the
readme.txt file. No? Well, here's a paragraph that might interest you:
This software makes the assumption that when it's running, it
solely controls the analog to digital conversion hardware and
that only the gyro, on analog input one, is being sampled.
Calling Disable_Gyro() will disable the gyro software and allow
you to use the ADC for other purposes.
One way around this is to double the timer 2 interrupt rate and then interleave your ADC measurements within the timer 2 ISR. If there's interest, I can modify the code to include accelerometer measurements too.
-Kevin