Go to Post ... it's us against all the bad-grammar-usin', "ya know"-slingin', graciously excepting, "congradulations"-totin', "nu kU ler"-spoutin' linguistic Luddites out there. We'll see who wins! :D - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-02-2005, 15:38
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Exclamation Using gyro.c with other analog sensors no go

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):
  1. Initialize i and accum if calculating bias
  2. Set old_calc_gyro_bias to calc_gyro_bias
  3. Reads ADC value
  4. Adds it to the accumulator
  5. Begins another ADC conversion
  6. Adds to accumulator.
  7. 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:
  1. Set the channel or open it and wait for it to settle
  2. Tell it to begin a conversion
  3. Wait until it finishes
  4. Read the value
  5. 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.
  #2   Spotlight this post!  
Unread 12-02-2005, 16:59
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Using gyro.c with other analog sensors no go

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):
  1. Initialize i and accum if calculating bias
  2. Set old_calc_gyro_bias to calc_gyro_bias
  3. Reads ADC value
  4. Adds it to the accumulator
  5. Begins another ADC conversion
  6. Adds to accumulator.
  7. 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:
  1. Set the channel or open it and wait for it to settle
  2. Tell it to begin a conversion
  3. Wait until it finishes
  4. Read the value
  5. 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
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #3   Spotlight this post!  
Unread 12-02-2005, 18:07
CyberWolf_22's Avatar
CyberWolf_22 CyberWolf_22 is offline
Programming and Electrical Mentor
AKA: Allen Gregory
FRC #2587 (Afrobots)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Houston, Texas
Posts: 227
CyberWolf_22 is just really niceCyberWolf_22 is just really niceCyberWolf_22 is just really niceCyberWolf_22 is just really nice
Re: Using gyro.c with other analog sensors no go

I would like to see an example of how you would interleave the measurements. Not necessarily for the accelerometer but for a potentiometer mounted to our arm.
__________________
  #4   Spotlight this post!  
Unread 13-02-2005, 16:12
jimfortytwo jimfortytwo is offline
Registered User
AKA: Jim Paulos
#0418 (Purple Haze)
Team Role: Student
 
Join Date: Feb 2003
Rookie Year: 2002
Location: austin
Posts: 65
jimfortytwo is just really nicejimfortytwo is just really nicejimfortytwo is just really nicejimfortytwo is just really nicejimfortytwo is just really nice
Send a message via ICQ to jimfortytwo Send a message via AIM to jimfortytwo Send a message via Yahoo to jimfortytwo
Re: Using gyro.c with other analog sensors no go

We have a similar situation, where we would like to juggle inputs from a pot and the gyro.

Once you call Disable_Gyro(), can you turn it back on again? In autonomous mode we'd be perfectly content to read only from the gyro while turning, then read from our pot on the straightaways, and then go back to reading from the gyro for a bit.

Is doing that more complicated than writting a complimentary function to Disable_Gyro() that just flips those two interupt bits? Or would we need a call to Initialize_Gyro()? Or do neither of those options work?
  #5   Spotlight this post!  
Unread 15-02-2005, 07:19
Jeff G Jeff G is offline
Registered User
#0648
 
Join Date: Nov 2004
Location: Quad Cities, IL & IA
Posts: 5
Jeff G is an unknown quantity at this point
Re: Using gyro.c with other analog sensors no go

Quote:
Originally Posted by Kevin Watson
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
Can we not simply use a standard analog input for the gyro? Why is it necessary to use the ADC as set up in the example code?

Thanks - Jeff
  #6   Spotlight this post!  
Unread 15-02-2005, 11:22
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Using gyro.c with other analog sensors no go

Quote:
Originally Posted by Jeff G
Can we not simply use a standard analog input for the gyro?
Sure, if you only need angular rate of change.


Quote:
Originally Posted by Jeff G
Why is it necessary to use the ADC as set up in the example code?
For those that need heading too, you need to integrate the gyro's output, which means that you must also know the amount of time between ADC samples. The way I look at it, reading and restarting the ADC during a timer interrupt service routine is the simplest and most elegant way to solve the problem short of using external hardware.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #7   Spotlight this post!  
Unread 15-02-2005, 12:02
Jeff G Jeff G is offline
Registered User
#0648
 
Join Date: Nov 2004
Location: Quad Cities, IL & IA
Posts: 5
Jeff G is an unknown quantity at this point
Re: Using gyro.c with other analog sensors no go

Quote:
Originally Posted by Kevin Watson
Sure, if you only need angular rate of change.


For those that need heading too, you need to integrate the gyro's output, which means that you must also know the amount of time between ADC samples. The way I look at it, reading and restarting the ADC during a timer interrupt service routine is the simplest and most elegant way to solve the problem short of using external hardware.

-Kevin
Doesn't get_analog() obtain a reading when requested since it is off the FRC, or is it only updated once per master loop?

In which case how about I use the timer only to gain an accurate measure of the master loop interval?

I want to run several other analog inputs along with the Gyro, and heading is important as I am using your robot code. Slightly modified to handle a steered front wheel and counting every trigger from the encoders, since they are only 16 pulse.

I really appreciate the ability to start with your code and tweak from there!!

Thanks - Jeff
  #8   Spotlight this post!  
Unread 16-02-2005, 15:56
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Using gyro.c with other analog sensors no go

After reading some more out of the PIC18C manual, and doing some testing, here's what I did:

Using the EDU, I made meassurements of how long it takes to read the analog input, from start to finnish. (Using timer 1 with 1:8 prescaler.) It averaged around 138.8586 clock cycles to go through, or about 0.111087 milliseconds (which is a bit long with all the extra instructions and the overhead to get the timer value).

Based on this value, and the relative rarity that the gyro timer goes off (about 400Hz if the comments are correct), we decided it was ok to switch channels and wait and everything inside the interupt. If anyone encounters problems doing this, please say so.
  #9   Spotlight this post!  
Unread 18-02-2005, 18:22
dmurdz's Avatar
dmurdz dmurdz is offline
Registered User
AKA: Dan
FRC #1027 (Mechatronic Maniacs)
Team Role: Leadership
 
Join Date: Feb 2005
Rookie Year: 2004
Location: West Springfield, Massachusetts
Posts: 54
dmurdz is on a distinguished road
Send a message via AIM to dmurdz Send a message via MSN to dmurdz
Re: Using gyro.c with other analog sensors no go

All right guys I need some help

Me and my team are planning on hooking up some switches and arm feedback as analog inputs, but when we run the program the gyro "hogs up all the space" for lack of better words. Any way around this or to fix this???
  #10   Spotlight this post!  
Unread 18-02-2005, 18:25
dmurdz's Avatar
dmurdz dmurdz is offline
Registered User
AKA: Dan
FRC #1027 (Mechatronic Maniacs)
Team Role: Leadership
 
Join Date: Feb 2005
Rookie Year: 2004
Location: West Springfield, Massachusetts
Posts: 54
dmurdz is on a distinguished road
Send a message via AIM to dmurdz Send a message via MSN to dmurdz
Re: Using gyro.c with other analog sensors no go

Asking Jim42's question from above:

Once you call Disable_Gyro(), can you turn it back on again?

We need to know!!!
  #11   Spotlight this post!  
Unread 20-02-2005, 12:14
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,579
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Using gyro.c with other analog sensors no go

Quote:
Originally Posted by dmurdz
Asking Jim42's question from above:

Once you call Disable_Gyro(), can you turn it back on again?

We need to know!!!
Just call initialize_gyro again, or if you didn't do anything with the timer, adc, etc you can just turn on timer2 again.
  #12   Spotlight this post!  
Unread 06-03-2005, 02:15
Manoel's Avatar
Manoel Manoel is offline
Registered User
FRC #0383 (Brazilian Machine)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 2000
Location: Porto Alegre, RS, Brazil
Posts: 608
Manoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond reputeManoel has a reputation beyond repute
Send a message via ICQ to Manoel Send a message via MSN to Manoel
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
Everyone serious about autonomous and capping this year needs a gyro and some kind of arm feedback (ie, potentiometer) yet I couldn't find any real code on reading two analog inputs. So, assuming the sample rate is doubled (800 Hz), will this code work?
Our RC is a few thousand miles away in some spooky Caribbean harbor and our EDU is locked up somewhere over at the school, so I can't really test it.
Code:
void Timer_2_Int_Handler(void)
{
	unsigned int adc_result;
	unsigned int adc_result_2;


	if (last_conversion == POTENCIOMETRO)
	{
	ADCON0bits.CHS0 = 0;
	ADCON0bits.CHS1 = 0;
	ADCON0bits.CHS2 = 0;
	ADCON0bits.CHS3 = 0;

	// get the latest ADC conversion
	adc_result = ADRESH;
	adc_result <<= 8;
	adc_result += ADRESL;

	// add the ADC data to the accumulator
	accum += adc_result;

	// increment the sample counter
	samples++;

	// start another analog to digital conversion
	ADCON0bits.GO = 1;

	// check to see if we've got a full sample set
	if(samples >= GYRO_SAMPLES_PER_UPDATE)
	{
		// should the completed sample set be used to calculate the gyro bias?
		if(calc_gyro_bias == TRUE)
		{
			// convert the accumulator to an integer and update gyro_bias
			avg_accum += accum;
			avg_samples++;
		}
		else
		{
			// update the gyro rate
			gyro_rate = (int)accum - gyro_bias;

			// integrate the gyro rate to derive the heading 
			gyro_angle += (long)gyro_rate;
		} 

		// reset the accumulator to zero
		accum = 0;

		// start a fresh sample set
		samples = 0;
	}

	last_conversion == GYRO;
	}
	else
	{
	ADCON0bits.CHS0 = 1;
	ADCON0bits.CHS1 = 0;
	ADCON0bits.CHS2 = 0;
	ADCON0bits.CHS3 = 0;
	// get the latest ADC conversion
	adc_result_2 = ADRESH;
	adc_result_2 <<= 8;
	adc_result_2 += ADRESL;
	ADCON0bits.GO = 1;
	potenciometro = adc_result_2;
        last_conversion = POTENCIOMETRO;
	}
}
__________________
Manoel Flores da Cunha
Mentor
Brazilian Machine
Team # 383

Last edited by Manoel : 06-03-2005 at 02:20.
  #13   Spotlight this post!  
Unread 06-03-2005, 04:04
Goldeye Goldeye is offline
Registered User
AKA: Josh Hecht
FRC #0694 (Stuypulse)
Team Role: College Student
 
Join Date: Jan 2005
Rookie Year: 2005
Location: New York
Posts: 145
Goldeye has a spectacular aura aboutGoldeye has a spectacular aura aboutGoldeye has a spectacular aura about
Send a message via AIM to Goldeye
Re: Using gyro.c with other analog sensors no go

To be safe, you should change the channel after getting the value. Also, be sure to double check the reference manual to make sure you have the bits right for the channel selection, we had some trouble with that when we to alternate between gyro and accelerometer.

In the end, we didn't use it though; our sensors were giving bad readings, presumably broken. We did come up with two rather ingenuitive ways of solving the direction and arm height problems, though I'm not too sure I'm supposed to share them just yet. What's it matter though if we can't get the robot to drive straight when it's going for the tetra
  #14   Spotlight this post!  
Unread 06-03-2005, 16:32
Meandmyself's Avatar
Meandmyself Meandmyself is offline
Registered Magic Programming User
AKA: Gordon
#1123 (AIM robotics Crimson Lightning)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: springfield, VA
Posts: 26
Meandmyself will become famous soon enough
Re: Using gyro.c with other analog sensors no go

You can definetely get arm feedback without using two analog inputs. If nothing else you can use an external adc and put it into 8 digital inputs, or however many are practical.
__________________
They call me the Idea man.
Not because my ideas work,
But because I have ideas...


I'm not a programmer. I'm an electrical guy who can program. If only I understood C!

www.aim-robotics.org //team website
www.tjhsst.edu/~gburgett //cool stuff for school
  #15   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
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
heres the code. y this not working omega Programming 16 31-03-2004 15:18
Getting Fancy with Sensors FadyS. Programming 30 10-03-2004 15:02
IR sensors: dealing with reflections? gnormhurst Programming 3 08-03-2004 20:04
Why not analog sensors?? gnormhurst Programming 16 07-03-2004 16:14
Interrupts and rotation sensors kor Programming 3 12-02-2004 11:05


All times are GMT -5. The time now is 22:47.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi