|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#3
|
||||
|
||||
|
Re: BEI Gyro Accuracy
I guess the part I am really interested in is this, because this is what I am having troubles with:
Code:
/*************************************************
Timer ISR to grag Gyro value at rate
determined in SetuoTimer2
**************************************************/
ISR(TIMER2_OVF_vect)
{
//Toggle the IO pin to the other state.
//digitalWrite(TOGGLE_IO,!digitalRead(TOGGLE_IO));
sample_accum += analogRead(GyroPin);
sample_counter ++;
if (sample_counter == SAMPLES_PER_UPDATE)
{
val = (sample_accum/SAMPLES_PER_UPDATE)-gyroBias;
if (val < -DEADBAND || val > DEADBAND)
{
gyro_angle += (long)val;
}
sample_accum = 0;
sample_counter = 0;
}
//Capture the current timer value. This is how much error we
//have due to interrupt latency and the work in this function
latency=TCNT2;
//Reload the timer and correct for latency.
TCNT2=(latency + timerLoadValue);
}
What why are you toggling a pin? The latency part is just accounting for the time spent processing? Other then those 2 things my ISR is basically the same. I cant really post the code now because I am at work, but I can give a brief pseudo coding of it. Code:
get adc reading
if it is less then dead band
then subtract from position
if it is greater then dead band
then add to position
else do nothing
send position over USART
Thanks, John Gutmann EDIT: I think when I get home I will try to eliminate the dead band, and see if that will help any. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| BEI Gyro | John Gutmann | Electrical | 3 | 18-06-2008 17:36 |
| Weapon Accuracy? | scitobor 617 | Programming | 15 | 12-02-2006 22:16 |
| servo output accuracy | NextPerception | Programming | 9 | 07-02-2006 11:23 |
| BEI GyroChip Problems | Andrew Blair | Programming | 12 | 07-12-2005 18:02 |
| BEI Gyrochip | CyberWolf_22 | Electrical | 3 | 15-01-2005 16:27 |