Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   New C18 3.0+ Compatible FRC Code (http://www.chiefdelphi.com/forums/showthread.php?t=60377)

Guy Davidson 03-01-2008 19:28

Re: New C18 3.0+ Compatible FRC Code
 
Kevin,

While we're looking at the new code, what is the difference between interrupts 1,2 and 3-6? I read the encoders readme, and I understand how they differ. However, I haven't seen any documentation about the interrupts themselves. Could you please explain me how (if it all) they differ?

Alan Anderson 03-01-2008 21:33

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by sumadin (Post 667264)
Kevin,

While we're looking at the new code, what is the difference between interrupts 1,2 and 3-6? I read the encoders readme, and I understand how they differ. However, I haven't seen any documentation about the interrupts themselves. Could you please explain me how (if it all) they differ?

Digital inputs 1 and 2 each go to separate interrupt circuits. They can be configured to cause an interrupt on either a low-to-high or high-to-low transition of the input. The interrupt service routine can inspect individual flags to determine which input caused the interrupt.

Digital inputs 3-6 all go together to a third interrupt circuit, and automatically cause an interrupt on any input transition. There's only one flag to say that "something changed" on those pins. In order to determine which of the four inputs is responsible, the software has to do its own bookkeeping to compare the previous input state against the present one.

That's a simple explanation. There's more detail in the PIC manual if you want it.

Guy Davidson 03-01-2008 21:45

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Alan Anderson (Post 667329)
Digital inputs 3-6 all go together to a third interrupt circuit, and automatically cause an interrupt on any input transition. There's only one flag to say that "something changed" on those pins. In order to determine which of the four inputs is responsible, the software has to do its own bookkeeping to compare the previous input state against the present one.

This makes sense. Thank you. I'll try using some of them soon, hopefully the ISRs in Kevin's code work as-is and then the difference won't really matter to me.

Kevin Watson 04-01-2008 03:31

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Code Monkey (Post 667114)
Last year we got an updated adc code which only used 1 interrupt per sample, instead of 2. Is this already implemented in the new adc code?

This evening I integrated a modified version of the ADC and gyro code into the new RC code and it seems to be very solid (while doing other things, including a bunch of printf()s, I have the ADC sampling at 6400Hz with no problems). The new ADC code uses the 8722s acquisition delay feature, which allows me to run it at one interrupt per sample, instead of two. I should be able to release it tomorrow.

Quote:

Originally Posted by Code Monkey (Post 667114)
Also last year we had to use a new processor .h file for the encoders. I see the encoder work is in progress, so this will also disappear, I hope?

This is next on my list.

-Kevin

Mike Mahar 04-01-2008 09:53

Re: New C18 3.0+ Compatible FRC Code
 
Thanks for the link to Microchip. I went there three times and couldn't find it. The page looked like a sales page so I didn't scroll down and see the download links. Oh well. I've got it now.

Ed Sparks 04-01-2008 11:00

Re: New C18 3.0+ Compatible FRC Code
 
Quote:

Originally Posted by Kevin Watson (Post 667435)
..... I should be able to release it tomorrow.

-Kevin


Thank you Kevin for all of your hard work! I like what I see so far and I can assure you that team 34 will put this to good use.

Lafleur 04-01-2008 11:11

Re: New C18 3.0+ Compatible FRC Code
 
Kevin:

Here are some change that I made to your serial routine to set the baudrate correctly for any processor speed.

in serial_port.c

#ifdef ENABLE_SERIAL_PORT_ONE
void Init_Serial_Port_One(void)
{
// Start by initializing the serial port with code
// common to receive and transmit functions
// SPBRG = BAUD_38400 ; // baud rate generator register [251]
SPBRG = SPBRG_VAL_1; // defined in hardware.h
//
#ifdef USART1_USE_BRGH_LOW
TXSTAbits.BRGH = 0; // high baud rate select bit (asynchronous mode only) [248]
#else // 0: low speed
TXSTAbits.BRGH = 1; // high baud rate select bit (asynchronous mode only) [248] // 1: high speed
#endif // 1: high speed


.................................................. .................................................. .................................................. ......


#ifdef ENABLE_SERIAL_PORT_TWO
void Init_Serial_Port_Two(void)
{
// Start by initializing the serial port with code
// common to receive and transmit functions
// SPBRG2 = BAUD_9600; // baud rate generator register [251]
SPBRG2 = SPBRG_VAL_2; // defined in hardware.h
//
#ifdef USART2_USE_BRGH_LOW
TXSTA2bits.BRGH = 0; // high baud rate select bit (asynchronous mode only) [248]
#else // 0: low speed
TXSTA2bits.BRGH = 1; // high baud rate select bit (asynchronous mode only) [248] // 1: high speed
#endif // 1: high speed





------------------------------------------------------------------------------------------------------------------------------------------------------------


in the hardware set up routines...




// Define system xtal/clock frequency
//
#define CLOCK_FREQ (40000000) // Frequency in Hz

#if defined(__18CXX) // All PIC18 processors
#include <p18cxxx.h>
#define INSTR_FREQ (CLOCK_FREQ/4) // PIC18 clock divider
#else
#error Unknown processor or processor not defined
#endif


// Set up serial port(s) baud rate
//
#define BAUD_RATE_1 (38400) // Serial port 1, bps
#define BAUD_RATE_2 (38400) // Serial Port 2, bps

// set as needed...
//#define USART1_USE_BRGH_LOW // for most lower baud rates
//#define USART2_USE_BRGH_LOW // for most lower baud rates

#if defined(USART1_USE_BRGH_LOW)
#define SPBRG_VAL_1 ( ((CLOCK_FREQ/BAUD_RATE_1)/64) - 1)
#else
#define SPBRG_VAL_1 ( ((CLOCK_FREQ/BAUD_RATE_1)/16) - 1)
#endif

#if defined(USART2_USE_BRGH_LOW)
#define SPBRG_VAL_2 ( ((CLOCK_FREQ/BAUD_RATE_2)/64) - 1)
#else
#define SPBRG_VAL_2 ( ((CLOCK_FREQ/BAUD_RATE_2)/16) - 1)
#endif

#if ((SPBRG_VAL_1 > 255) || (SPBRG_VAL_2 > 255))
#error "Calculated SPBRG value is out of range for current CLOCK_FREQ."
#endif

Code Monkey 04-01-2008 14:19

Re: New C18 3.0+ Compatible FRC Code
 
To be clear, without Kevin this would be miserable. Team 1622 is massively
in your debt. Thank you.

For those who have not already installed the MCC upgrade, make sure you put it in the same directory with the upgraded MPLAB 8.0. Otherwise the linker can't find the libraries. I know by the trying it the wrong way.

comphappy 04-01-2008 19:23

Re: New C18 3.0+ Compatible FRC Code
 
Rookie team 2605 will be using your code, it is structured in a way that makes more sense, I have not gone through it all the way yet, but so far so good. BTW is there a better search tool in mplab than the just straight basic find? For my embedded systems work I am always using grep and regexps, so far mplab has been really disappointing.

B.Johnston 04-01-2008 21:16

Re: New C18 3.0+ Compatible FRC Code
 
Comphappy,

The answer maybe Yes!

Try under the Project Menu > Find in Project Files.

Once you enter your keyword you'll be able to see the results in the output window under the find in files tab.

Double click on whatever you want to see and a new window will open with a pointer to your chosen element.

I hope this answers your question, as I'm not really sure as to what grep would deliver as a result.

comphappy 04-01-2008 22:01

Re: New C18 3.0+ Compatible FRC Code
 
Thanks that is what I was looking for, still not very good, but better then what I had found. Grep is extreamly flexible long as you are willing to spend the time to learn how to use it correctly.

Kevin Watson 04-01-2008 22:22

Re: New C18 3.0+ Compatible FRC Code
 
Here's a snapshot of the latest build:

http://kevin.org/frc/ifi_frc_beta_3.zip
http://kevin.org/frc/ifi_frc_gyro_beta.zip (with integrated ADC and Gyro code)

-Kevin

Guy Davidson 04-01-2008 22:33

Re: New C18 3.0+ Compatible FRC Code
 
Kevin,

Is there any change log? So we can keep track of what's bew in beta 3? Other than, of course, the ADC and gyro in that version.

Thanks.

jtdowney 05-01-2008 00:03

Re: New C18 3.0+ Compatible FRC Code
 
I know MPLAB can generate a makefile for you but those always seem messy so I wrote up a quick one to use for myself with Kevin's new code. Figured I'd share it here in case anyone else finds it useful.

Code:

# Makefile for Kevin Watson's (http://kevin.org) C18 3.0 compatible FRC code
CC = C:\\mcc18\\bin\\mcc18.exe
CFLAGS = -p=18F8722 -k -mL -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
LD = C:\\mcc18\\bin\\mplink.exe
LDFLAGS = 18f8722.lkr
LIBS = ifi_frc_8722.lib
LIBPATH = C:\\mcc18\\lib
MAP = ifi_frc.map
RM = del

SOURCES = autonomous.c disabled.c ifi_code.c ifi_frc.c interrupts.c pwm.c \
          serial_ports.c teleop.c timers.c
OBJECTS = $(SOURCES:.c=.o)
EXECUTABLE = ifi_frc

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
        $(LD) /l"$(LIBPATH)" $(LDFLAGS) $(OBJECTS) $(LIBS) /m"$(MAP)" /w /o"$(EXECUTABLE).cof"

.c.o:
        $(CC) $< -fo="$@" $(CFLAGS)

clean:
        $(RM) $(OBJECTS) $(EXECUTABLE).cof $(EXECUTABLE).hex $(MAP)


sparrowkc 05-01-2008 18:57

Re: New C18 3.0+ Compatible FRC Code
 
Forgive my noobiness, but is that makefile what I need to develop on ubuntu? Set up c18 in wine, put the file in the directory with the code and do a make? Will that give me a loadable hex file? There was another makefile posted earlier that looked like it was made for Linux, should I use that?


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

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