Go to Post Come on how can you not be excited about IRI! - richardp [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
  #16   Spotlight this post!  
Unread 23-01-2006, 00:34
Joel J's Avatar
Joel J Joel J is offline
do you..
no team
 
Join Date: May 2001
Rookie Year: 2000
Location: San Jose, CA
Posts: 1,445
Joel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond repute
Re: Analog-to-Digital Converter Code

Yes, it samples faster than the rate the data is being sent.

I have another question for Kevin (of course, I'm trying to optimize everything, but I don't want to make a bad move while doing this):

Is there a specific reason for switching from doing both the initiation of and saving of an ADC sample in the timer interrupt? I remember in last year's gyro code that both functions were done in the same place, whereas now you are using both the timer interrupt, and the ADC interrupt to take the samples. Is it safe to kinda shift the ADC functionality to the timer interrupt and reduce the extra overhead by removing the ADC interrupt altogether? Or do the two of them together execute faster, somehow, than the single timer?

Before you:
- Started the initial A/D conversion in Initialize_XXXX()
- Saved the value at the start of the timer2 interrupt
- Did the if/else/etc to put the value in the right place
- Started another A/D conversion by setting the GO bit.
- Exited the timer2 interrupt.

And if I get the go ahead, I'll just do this again.
__________________
Joel Johnson

Division By Zero (229) Alumni, 2003-2007
RAGE (173) Alumni, 1999-2003
  #17   Spotlight this post!  
Unread 23-01-2006, 11:59
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,600
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: Analog-to-Digital Converter Code

Quote:
Originally Posted by Chriszuma
so then does it take values 4x faster? It seems like taking the average over 4 program cycles would make it less precise.
The following whitepaper goes much more in depth and may make more sense: http://www.chiefdelphi.com/forums/pa...le&paperid=234
  #18   Spotlight this post!  
Unread 23-01-2006, 17:16
mgurgol mgurgol is offline
Registered User
FRC #1094
 
Join Date: Jan 2006
Location: St Louis MO
Posts: 76
mgurgol is just really nicemgurgol is just really nicemgurgol is just really nicemgurgol is just really nicemgurgol is just really nice
Re: Analog-to-Digital Converter Code

Quote:
Originally Posted by Kevin Watson
Well, I finally posted the ADC and Gyro code for the 2006 robot controller. Sorry about the delay, but I ran into a nasty bug that caused me to spend a few days in the fourth and fifth levels of programmer hell. The bug was in the design of the PIC18F8722 (yes, a bug in the sillicon) and I had to figure out what was going on. Anyway, the gyro code works really, really well with the gyro in the kit of parts. The accelerometers also work really well, but I need to do more testing before I unleash that code.


-Kevin
I have downloaded the FRC_GYRO code, compiled and linked it in MPLAB, and it controls the gyro great, thanks.

When I copy the FRC_Library into my 2006 project code (to update from the 8250 (2005) to the 8722 (2006) controller, I am getting a link error saying that symbol ifi_packet_num1 has multiple definitions. I was able to determine that there is a copy of ifi_utilities.o (where ifi_packet_num1 is defined) in the FRC_Library (that wasn't there in 2005). I was able to work around the problem by removing ifi_utilites.c from the project, and it linked fine.

My question is: Is there some setting I am missing in my project that would allow the linker to use the first instance of the object file it comes across versus including all versions. I see ifi_utilities.c in the frc_gyro (gyro.mcp) project, and the link works correctly. Since I don't modify ifi_utilities.c my work around shouldn't be a problem, but I would like to know why one project will link correctly, while another one won't.

Thanks, Mark
  #19   Spotlight this post!  
Unread 23-01-2006, 23:09
Chriszuma's Avatar
Chriszuma Chriszuma is offline
Jack of all trades
AKA: Chris Hammond
FRC #0068 (Truck Town Thunder)
Team Role: Alumni
 
Join Date: Oct 2004
Rookie Year: 2005
Location: Clarkston, MI
Posts: 290
Chriszuma is just really niceChriszuma is just really niceChriszuma is just really niceChriszuma is just really nice
Send a message via AIM to Chriszuma
Re: Analog-to-Digital Converter Code

Quote:
Originally Posted by Joe Ross
The following whitepaper goes much more in depth and may make more sense: http://www.chiefdelphi.com/forums/pa...le&paperid=234
Wow, that really explained it well. Thanks.
  #20   Spotlight this post!  
Unread 23-01-2006, 23:22
Joel J's Avatar
Joel J Joel J is offline
do you..
no team
 
Join Date: May 2001
Rookie Year: 2000
Location: San Jose, CA
Posts: 1,445
Joel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond repute
Re: Analog-to-Digital Converter Code

Quote:
Originally Posted by Joel J.
Yes, it samples faster than the rate the data is being sent.

I have another question for Kevin (of course, I'm trying to optimize everything, but I don't want to make a bad move while doing this):

Is there a specific reason for switching from doing both the initiation of and saving of an ADC sample in the timer interrupt? I remember in last year's gyro code that both functions were done in the same place, whereas now you are using both the timer interrupt, and the ADC interrupt to take the samples. Is it safe to kinda shift the ADC functionality to the timer interrupt and reduce the extra overhead by removing the ADC interrupt altogether? Or do the two of them together execute faster, somehow, than the single timer?

Before you:
- Started the initial A/D conversion in Initialize_XXXX()
- Saved the value at the start of the timer2 interrupt
- Did the if/else/etc to put the value in the right place
- Started another A/D conversion by setting the GO bit.
- Exited the timer2 interrupt.

And if I get the go ahead, I'll just do this again.
As I was waiting for your reply I took a look at the spec sheet for the PIC18f8722. It says there is a set delay of at least 2.5 microseconds that has to exist between the setting of an analog channel and the initiation of its conversion (to allow the sample and hold capacitor to start charging). Is this the reason for the seperation of the two actions?

I also see the following:
Quote:
Acquisition time may be set with the ACQT2:ACQT0 bits (ADCON2<5:3>) which provides a range of 2 to 20 TAD. When the GO/DONE bit is set, the A/D module continues to sample the input for the selected acquisition time, then automatically begins a conversion. Since the acquisition time is programmed, there may be no need to wait for an acquisition time between selecting a channel and setting the GO/DONE bit.
which makes it seem as though the PIC could implement a delay by itself. But taking another look at your code, I noticed that you enabled manual acquisition (ADCON2<5:3> = 0). Did you find the PIC to be unreliable in this area, or have I totally missed the point?

I'll wait for your feedback before continuing.
__________________
Joel Johnson

Division By Zero (229) Alumni, 2003-2007
RAGE (173) Alumni, 1999-2003

Last edited by Joel J : 23-01-2006 at 23:28.
  #21   Spotlight this post!  
Unread 24-01-2006, 00: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: Analog-to-Digital Converter Code

Quote:
Originally Posted by Joel J.
Yes, it samples faster than the rate the data is being sent.

I have another question for Kevin (of course, I'm trying to optimize everything, but I don't want to make a bad move while doing this):

Is there a specific reason for switching from doing both the initiation of and saving of an ADC sample in the timer interrupt? I remember in last year's gyro code that both functions were done in the same place, whereas now you are using both the timer interrupt, and the ADC interrupt to take the samples. Is it safe to kinda shift the ADC functionality to the timer interrupt and reduce the extra overhead by removing the ADC interrupt altogether? Or do the two of them together execute faster, somehow, than the single timer?

Before you:
- Started the initial A/D conversion in Initialize_XXXX()
- Saved the value at the start of the timer2 interrupt
- Did the if/else/etc to put the value in the right place
- Started another A/D conversion by setting the GO bit.
- Exited the timer2 interrupt.

And if I get the go ahead, I'll just do this again.


This is a great question. When I modified the code last Summer to separate the ADC and gyro functionality, I added the ability to sample multiple ADC channels using a simple round-robin algorithm. If you read the pic18f8520 data sheet you'll notice the second paragraph on page 217 which states:
"After the A/D module has been configured as desired, the selected channel must be acquired before the conversion is started...To determine acquisition time, see Section19.1 “A/D Acquisition Requirements”. After this acquisition time has elapsed, the A/D conversion can be started."

What this means is that you need to allow sufficient time for the sample-and-hold capacitor to charge between the time you change the channel and can actually start the conversion. Providing this delay within an ISR is, to say the least, un-cool. My solution was to start the conversion using the timer 2 ISR and manage data and change the ADC channel in the ADC ISR. The sample-and-hold capacitor then has ample time to charge between the ADC and timer 2 ISRs. This is how the currently posted code works.

The pic18f8722, used in the current robot controller, has added circuitry to automatically provide the acquisition delay before conversion begins (see page 277 of the p18f8722 data sheet). In the next revision of the ADC code I suspect that I'll be able to do away with the ADC interrupt and do everything in the timer 2 ISR. Perhaps this would be a good programming exercise for you?

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #22   Spotlight this post!  
Unread 24-01-2006, 00:34
Joel J's Avatar
Joel J Joel J is offline
do you..
no team
 
Join Date: May 2001
Rookie Year: 2000
Location: San Jose, CA
Posts: 1,445
Joel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond repute
Re: Analog-to-Digital Converter Code

ok, great!

I'll modify your code for use now, and then I'll swap in your next revision when you make it gold.

Thanks for the feedback.
__________________
Joel Johnson

Division By Zero (229) Alumni, 2003-2007
RAGE (173) Alumni, 1999-2003
  #23   Spotlight this post!  
Unread 08-02-2008, 19:32
McLOVIN's Avatar
McLOVIN McLOVIN is offline
I am McLOVIN
AKA: I am McLOVIN
no team
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2004
Location: South of the Border
Posts: 8
McLOVIN is an unknown quantity at this point
Re: Analog-to-Digital Converter Code

For some reason our team is having great difficulty in getting the analog inputs to work, no matter what we plug into the inputs or print. We have initialized them and receive no errors yet no inputs are received. We have attempted testing a gyro, accelerometer, ultrasonic sensor, and variable resistor (potentiometer) but none have made a difference.
__________________
[i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i]


I am McLOVIN


[i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i]
  #24   Spotlight this post!  
Unread 08-02-2008, 19:38
lukevanoort lukevanoort is offline
in between teams
AKA: Luke Van Oort
no team
 
Join Date: Oct 2005
Rookie Year: 2005
Location: Waterloo, ON, Canada
Posts: 1,873
lukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond repute
Send a message via AIM to lukevanoort
Re: Analog-to-Digital Converter Code

Quote:
Originally Posted by McLOVIN View Post
For some reason our team is having great difficulty in getting the analog inputs to work, no matter what we plug into the inputs or print. We have initialized them and receive no errors yet no inputs are received. We have attempted testing a gyro, accelerometer, ultrasonic sensor, and variable resistor (potentiometer) but none have made a difference.
There is a #define statement in adc.h that is something like NUMBER_OF_CHANNELS (I'm going from memory here, so I don't know exactly what the statement actually defines). Is that defined as 16? We had some analog input trouble last year when we only had 1 channel active and were trying to tune four PID loops using pots that were connected to analog ports that weren't enabled, which didn't work very well, but caused no compile-time errors.
__________________
Team 1219: 2009 - Mentor
Team 587: 2005 - Animator, 2006-2008 - Team Captain

Last edited by lukevanoort : 08-02-2008 at 19:41.
  #25   Spotlight this post!  
Unread 08-02-2008, 19:44
McLOVIN's Avatar
McLOVIN McLOVIN is offline
I am McLOVIN
AKA: I am McLOVIN
no team
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2004
Location: South of the Border
Posts: 8
McLOVIN is an unknown quantity at this point
Re: Analog-to-Digital Converter Code

Actually that wasn't the problem, but we seem to have fixed it. Our problem actually was that the interrupt Timer_4_ISR was defined in both adc.c, adc.h and timers.c and .h. No errors appeared but it didnt allow inputs.
__________________
[i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i]


I am McLOVIN


[i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i]
  #26   Spotlight this post!  
Unread 08-02-2008, 20:36
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: Analog-to-Digital Converter Code

Quote:
Originally Posted by McLOVIN View Post
Actually that wasn't the problem, but we seem to have fixed it. Our problem actually was that the interrupt Timer_4_ISR was defined in both adc.c, adc.h and timers.c and .h. No errors appeared but it didnt allow inputs.
This is documented in the readme.txt file included with the software. Specifically, items 2 and 3:

Quote:
By default the analog to digital and gyro software is disabled.
Perform these steps to get your gyro working:
1) Enable the Initialize_ADC() and Initialize_Gyro() functions in
teleop.c/Initialization().
2) Enable the timer 4 interrupt service routine in ifi_frc.h
3) Make sure timer 4 is disabled at the top of timers.h.
4) Depending on the operating modes you will be using the gyro,
place calls to the Process_Gyro_Data() function in the disabled.c/
Disabled_Spin(), autonomous.c/Autonomous_Spin() and/or teleop.c/
Teleop_Spin() functions.
5) Add gyro bias calibration code that will execute before you
use your gyro. Example calibration code has been placed in
disabled.c/Disabled() that can be used for the competition (this
requires that you use a mode dongle to emulate the field
controller, which will put you in disabled mode for a period of
time before transitioning to autonomous mode). For testing
purposes you can also use the example code in teleop.c/Teleop()
to make sure your gyro is working.
6) Follow the instructions in adc_readme.txt, adc.h, gyro_readme.txt,
and gyro.h for information related to installation and calibration
of your gyro.
7) If building for the 2004 or 2005 PIC18F8520 based robot controller,
you will need to use the adc_8520.c source file instead of adc.c.
The header file adc.h will work with either version.
8) If building for the 2004 or 2005 PIC18F8520 based robot controller,
you will need to enable the ADC interrupt service routine in
ifi_frc.h
-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #27   Spotlight this post!  
Unread 14-02-2008, 22:11
windell747 windell747 is offline
Registered User
FRC #2477
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2001
Location: Hawaii
Posts: 158
windell747 will become famous soon enoughwindell747 will become famous soon enough
Re: Analog-to-Digital Converter Code

Hi Kevin, We have recently come to realize that the p1_y and p1_x ADCs are somewhat noisy. The output value varies randomly maybe about +/-10 of 127 when the joystick is connected, but not touched. Does your code address this problem? We were trying to work around the problem using a comb digital filter.

Thanks,
Windell
  #28   Spotlight this post!  
Unread 14-02-2008, 22:26
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: Analog-to-Digital Converter Code

Quote:
Originally Posted by windell747 View Post
Hi Kevin, We have recently come to realize that the p1_y and p1_x ADCs are somewhat noisy. The output value varies randomly maybe about +/-10 of 127 when the joystick is connected, but not touched. Does your code address this problem? We were trying to work around the problem using a comb digital filter.

Thanks,
Windell
No, that code runs on the PIC inside the operator interface, which I didn't write. I would try using a running average of 2-4 samples to see if it quiets down.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #29   Spotlight this post!  
Unread 16-02-2008, 19:52
srinivas srinivas is offline
Registered User
FRC #1677 (QUANTUM NINJAS)
Team Role: Mentor
 
Join Date: Oct 2007
Rookie Year: 2007
Location: michigan
Posts: 2
srinivas is an unknown quantity at this point
Send a message via Yahoo to srinivas
Re: Analog-to-Digital Converter Code

Quote:
Originally Posted by Kevin Watson View Post
This is a great question. When I modified the code last Summer to separate the ADC and gyro functionality, I added the ability to sample multiple ADC channels using a simple round-robin algorithm. If you read the pic18f8520 data sheet you'll notice the second paragraph on page 217 which states:
"After the A/D module has been configured as desired, the selected channel must be acquired before the conversion is started...To determine acquisition time, see Section19.1 “A/D Acquisition Requirements”. After this acquisition time has elapsed, the A/D conversion can be started."

What this means is that you need to allow sufficient time for the sample-and-hold capacitor to charge between the time you change the channel and can actually start the conversion. Providing this delay within an ISR is, to say the least, un-cool. My solution was to start the conversion using the timer 2 ISR and manage data and change the ADC channel in the ADC ISR. The sample-and-hold capacitor then has ample time to charge between the ADC and timer 2 ISRs. This is how the currently posted code works.

The pic18f8722, used in the current robot controller, has added circuitry to automatically provide the acquisition delay before conversion begins (see page 277 of the p18f8722 data sheet). In the next revision of the ADC code I suspect that I'll be able to do away with the ADC interrupt and do everything in the timer 2 ISR. Perhaps this would be a good programming exercise for you?

-Kevin
Hello Kevin
When our team is using your FRC gyro code. there seems to be a problem. The motors are twitching. That is the arm and shoulder motors are coming back but are not staying in there.
Can u please tell us what to do about that. We caliberated the victors and checked the victors and checked the voltages. But when we use the default code without gyros the code works fine.

Please let us know what is happenning.

Thank you
Srinivas
  #30   Spotlight this post!  
Unread 17-02-2008, 13:07
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,600
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: Analog-to-Digital Converter Code

Quote:
Originally Posted by srinivas View Post
Hello Kevin
When our team is using your FRC gyro code. there seems to be a problem. The motors are twitching. That is the arm and shoulder motors are coming back but are not staying in there.
Can u please tell us what to do about that. We caliberated the victors and checked the victors and checked the voltages. But when we use the default code without gyros the code works fine.

Please let us know what is happenning.

Thank you
Srinivas
What PWMs are your victors connected to? PWMs 13-16 are controlled by the user processor and subject to glitches under high load when using IFI's Generate_PWMs function. If you move those motors to another PWM or use Kevin's replacement PWM code, it should work better.
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
Out of the Box Camera Code russell Programming 9 21-10-2009 05:28
Updated: Example Gyro Interface Code Kevin Watson Programming 2 28-03-2005 04:36
Example gyro code released. Kevin Watson Programming 60 17-03-2005 18:32
Team THRUST - Kevin's Code and Camera Code Combine Chris_Elston Programming 3 31-01-2005 22:28
heres the code. y this not working omega Programming 16 31-03-2004 15:18


All times are GMT -5. The time now is 14:27.

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