|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools |
Rating:
|
Display Modes |
|
#166
|
|||
|
|||
|
Re: New C18 3.0+ Compatible FRC Code
Quote:
The analog inputs are not instantaneous. You have to start them, then wait a certain amount of time and then read them. The code in adc.c will do that for you and uses a timer to wait. Calls to Get_ADC_Result will simply fetch the result that the library has already captured for you. The function Get_Analog_value does the start/wait/read operation in-place and takes longer and consumes valuable cycles that could be put to better use doing something else. |
|
#167
|
|||
|
|||
|
Re: New C18 3.0+ Compatible FRC Code
Kevin, I have question about adc.c.
In Timer_4_ISR you have two for loops that cover the same range of indexes. Code:
if(samples >= adc_samples_per_update)
{
// update the ADC result array
for(i=0; i < num_adc_channels; i++)
{
adc_result[i] = (long)(accum[i] >> adc_result_divisor);
}
// reset the sample accumulator(s) to zero
for(i=0; i < num_adc_channels; i++)
{
accum[i] = 0L;
}
// signal that a fresh sample set is available
adc_update_count++;
// start a fresh sample set
samples = 0;
}
Code:
if(samples >= adc_samples_per_update)
{
// update the ADC result array
for(i=0; i < num_adc_channels; i++)
{
adc_result[i] = (long)(accum[i] >> adc_result_divisor);
// reset the sample accumulator to zero
accum[i] = 0L;
}
// signal that a fresh sample set is available
adc_update_count++;
// start a fresh sample set
samples = 0;
}
|
|
#168
|
||||
|
||||
|
Re: New C18 3.0+ Compatible FRC Code
I have used this method in the past on my Vex bot. It works fairly well but is not perfect. For use in straight line driving, as in Hybrid mode, it should be sufficient. BTW, make sure you account for the dead-band associated with the Victor.
|
|
#169
|
||||||
|
||||||
|
Re: New C18 3.0+ Compatible FRC Code
There have been at least two makefiles posted in this thread.
|
|
#170
|
||||
|
||||
|
Re: New C18 3.0+ Compatible FRC Code
Quote:
-Kevin |
|
#171
|
|||
|
|||
|
Re: New C18 3.0+ Compatible FRC Code
Kevin:
An idea... A quick and dirty utilizations counter... Add a global long integer to you project called "cycle". At the end of the while(TRUE) in main.c, do a cycle++ to build a loop counter, this will tell you how many time you have been in the while(TRUE) loop. In the 26.4ms loop, read the cycle counter, clear it and divide by (264k clock cycles, the number of clock cycles in 26.4ms - the number of cycles used in the while(TRUE) ) This will give you a crude % utilization of the CPU that the teams can use to check on there code efficiency... also, the counter could be scaled so that one could use an unsigned int Last edited by Lafleur : 11-01-2008 at 18:50. |
|
#172
|
||||
|
||||
|
Re: New C18 3.0+ Compatible FRC Code
how exactically are we supposed to build in 7.21 with the c18 3.10 and now i can't just push F10 to build.
edit: also when I open it it does not open correctly when I try to open the project files. Last edited by Loki1989 : 11-01-2008 at 19:44. Reason: found new issues |
|
#173
|
|||
|
|||
|
Re: New C18 3.0+ Compatible FRC Code
Quote:
|
|
#174
|
|||
|
|||
|
Re: New C18 3.0+ Compatible FRC Code
Quote:
an error in my logic.... you also need to take the number of loops and multiply by the number of cycles in the loop and use this to subtract from the total number of cycles in the 26ms... tom lafleur This is the code I did in a TEST module with only the ATD and Serial ports, I have a timer that interrupts me ever 100ms. I disable all interrupts and use the MPLAB simulator to measure the number of cycles in the main loop. In my case it was 42 cycles. Note, division is only by 10,000 and not 1,000,000 to give a % with out the need to multiply by 100, saving some cycles. int util; long int cycle = 0; is a global in the code, it needs to be long because of the multiplication need a long in the main loop I have a cycle++; // here we will calculate the % of the CPU we are using // we are here every 100ms, that 1,000,000 cycles of the processor at 40MHz // utilization = the number of times in the do nothing loop, * the number of cycles in // the main loop. 42 is current number of cycles in main loop util = 100 - ((cycle * 42)/10000); cycle = 0; Last edited by Lafleur : 12-01-2008 at 13:01. Reason: Update |
|
#175
|
||||
|
||||
|
Re: New C18 3.0+ Compatible FRC Code
Quote:
-Kevin |
|
#176
|
||||
|
||||
|
A Makefile (forced to call it Makefile.txt to upload) for Linux in included. I'm using cxoffice (a canned wine setup) but it can be easily altered to work with plain old wine or to run under Windoze. This compiled Kevin's latest stuff with no errors but with a bunch of signed/unsigned warnings. I have not run the code on the robot yet!
Enjoy |
|
#177
|
|||
|
|||
|
Re: New C18 3.0+ Compatible FRC Code
Hi,
EDIT - We've got a working install of mplab 8.00, but we can't seem to get 3.00 installed. We run through the installer fine, but it doesn't seem to actually install.. MPLAB is still using 2.40, and we can't find the installation directory of 3.00 - only 2.40. I'm trying to install mplab 8.00 and the 3.0 compiler, I downloaded the software on the first post, and the tried running it over the install of mplab 7.20. It seemed to install, but now when ever we open mplab it says 8.00 is not enabled, but we can still use 7.20. How is the best way to install it and the compiler with pre-existing versions all ready installed? Last edited by bronxbomber92 : 12-01-2008 at 11:17. |
|
#178
|
||||
|
||||
|
Re: New C18 3.0+ Compatible FRC Code
Kevin, First of all thanks, this will be a great help.
Our team has a 2005 robot controller and operator interface mounted to a board for testing purposes when it is not practical to use the current robot controller (e.g., the current controller is on the robot, and the robot is being built or modified). We swapped out the libraries and linker files for the ones corresponding to the PIC18F8520, changed the target to the 8520, and tried to compile. We got this error(in your ifi_frc_gyro code, if it's relevant): Code:
C:\Users\NetElemental\Documents\Code\ifi_frc_gyro\ifi_code.c:33:Error [1105] symbol 'ifi_analog_channels' has not been defined The line code corresponds to Code:
29 #if defined(__18F8722) 30 OpenADC( ADC_FOSC_RC & ADC_RIGHT_JUST & ADC_0_TAD, 31 ADC_channel & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS,15); 32 #else 33 OpenADC( ADC_FOSC_RC & ADC_RIGHT_JUST & ifi_analog_channels, 34 ADC_channel & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS ); 35 #endif Thanks, James Last edited by NetElemental : 12-01-2008 at 12:18. Reason: Inaccuracy |
|
#179
|
|||
|
|||
|
Re: New C18 3.0+ Compatible FRC Code
CPU Utilization
In a quick test I did today, using a ATD sample rate of 200Hz, I had 19% utilizations of the processor. Changing only the ATD sample rate to 6400Hz, utilization went to 43%. |
|
#180
|
||||
|
||||
|
Re: New C18 3.0+ Compatible FRC Code
Quote:
-Kevin |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Does the camera code suits to all versions of MPLAB and C18? | razer | Programming | 3 | 04-01-2007 14:50 |
| Trying to follow C18 interrupt context code... | dcbrown | Programming | 5 | 21-12-2006 09:01 |
| Error w/ FRC code | JamesBrown | Programming | 2 | 08-01-2005 16:17 |
| Programming code Fix FRC | Ferazel2001 | Programming | 6 | 08-02-2004 02:46 |
| FRC default code | hedgehogger | Programming | 2 | 21-01-2004 18:41 |