View Single Post
  #12   Spotlight this post!  
Unread 11-04-2005, 10:50
WizardOfAz's Avatar
WizardOfAz WizardOfAz is offline
Lead Mentor
AKA: Bill Bennett
FRC #1011 (CRUSH)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Tucson, AZ
Posts: 101
WizardOfAz will become famous soon enough
Send a message via AIM to WizardOfAz
Re: Using gyro.c with other analog sensors no go

Quote:
Originally Posted by Kevin Watson
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
I realize I'm a little late coming to this thread.... but I wanted to put in a comment about sampling multiple analog sensors, either to add value to the discussion or to get feedback.

We needed to sample several analog inputs and wanted to use the same sample rate for them all (250 Hz), and ran into the problem with using Get_Analog_Value() more than once in an ISR. The "fix" we used was to have the ISR increment a counter of 4ms tics but not do any analog sampling. Code running in the "fast" routine would then read all the inputs when it saw the non-zero 4ms counter, and decrement the counter. This does cause sample jitter but no lost samples, so the average sample rate remains correct. Our "main loop" code used about 6ms, so about 1 sample every 4 or 5 would be delayed.

The problem with this method is if the main loop code is big compared to the sample rate, many samples will be delayed and the jitter will become a significant problem. For us this seemed to work. Then again, there are lots of reasons why integrated sensor values get "wrong" after a while, and this technique probably contributed to the causes.

Bill