Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Need interupts help, and another question... (http://www.chiefdelphi.com/forums/showthread.php?t=25762)

Kevin Karan 21-02-2004 18:51

Need interupts help, and another question...
 
Im having a problem getting the interupts working on the FRC. My sensor group has been working all the work period on seperate codes for the trackers, line sensors and encoders using the edubot. This week I ported everything for use on the FRC, but Im having a big problem getting the interupts to work. First, I just used the initialization routines that I made for the edubot, and worked on the edubot, in the FRC code but it didnt work. I tried putting the code out of kevin(.org)'s interupts example (they were almost identical) and still nothing. I tried using the code in first's timers guide but that was also identical. Im having this problems on timers 1,2 and interupts 1-6. Ive tried dissableing all interupts exept for one, but no luck. This is the code im using (as an example) to initialize the interupts for the drive encoders:
Code:

void Initialize_Encoders(void) 
{
        // init interupt 1
        TRISBbits.TRISB2 = 1;                //make input
        INTCON3bits.INT2IP = 0;                //low priority
        INTCON2bits.INTEDG2 = 1;        //rising-edge
        INTCON3bits.INT2IE = 1;                //enable
       
        // init interupt 2
        TRISBbits.TRISB3 = 1;                //make an input
        INTCON2bits.INT3IP = 0;                //low priority
        INTCON2bits.INTEDG3 = 1;        //rising-edge
        INTCON3bits.INT3IE = 1;                //enable
}

This is the code im using to initialize my 1khz timer:
Code:

void Initialize_Timer_2(void) 
{
        TMR2 = 0;                                // 8-bit
        PR2        = 249;                                // period register
        T2CONbits.T2OUTPS0 = 1;        // 1:10 postscaler
        T2CONbits.T2OUTPS1 = 0;       
        T2CONbits.T2OUTPS2 = 0;       
        T2CONbits.T2OUTPS3 = 1;

        T2CONbits.T2CKPS0 = 1;        // 1/4 prescaler
        T2CONbits.T2CKPS1 = 0;       

        PIE1bits.TMR2IE = 1;        // enable pr2

        IPR1bits.TMR2IP = 0;        // low priority

        T2CONbits.TMR2ON = 1;        // enable
}

I am using kevin(.org)'s interupt hander low (actualy im pretty much using his user_routines_fast.c) which is pretty much identical to FIRST's. The tracker interupt init is FIRST's.
Im calling the inits from User_Initialization like im supposed to.

My other question is if we can exclude some parts of firsts code, like the printf library since they take up a large chunk of the program flash memory and I want to use that space for other stuff.
Thanks,
Kevin Karan
Team 174 Arctic Warriors Programmer

Astronouth7303 21-02-2004 20:17

Re: Need interupts help, and another question...
 
As for the first part, ask Kevin.

As for the second part, I think that printf is the only one you can exclude, but only if you aren't using printf() anywhere. And this year's mem is huge, so if you filled it already, tell us!

Kevin Karan 21-02-2004 20:26

Re: Need interupts help, and another question...
 
Quote:

Originally Posted by Astronouth7303
As for the first part, ask Kevin.

As for the second part, I think that printf is the only one you can exclude, but only if you aren't using printf() anywhere. And this year's mem is huge, so if you filled it already, tell us!

er... where do I ask him, or may he see this post?
And I did fill it up :D, Its a mix of a heavily modified tracker, a math library, and my drive system that (hopefully) makes accurate speed/power ajustments relitive to the maximum speed of the bot as seen with the encoders. Thanks!

Astronouth7303 21-02-2004 21:23

Re: Need interupts help, and another question...
 
Quote:

Originally Posted by Kevin Karan
er... where do I ask him, or may he see this post?

PM him, or wait till he sees this.

Quote:

Originally Posted by Kevin Karan
And I did fill it up :D, Its a mix of a heavily modified tracker, a math library, and my drive system that (hopefully) makes accurate speed/power ajustments relitive to the maximum speed of the bot as seen with the encoders. Thanks!

:yikes: :yikes: My eyes hurt from that dinner-plate type action. :yikes: :yikes: One word: OPTIMIZE. I hear it's huge. I see why you asked about printf. At this point, do conditional compilation of the debug stuff. But unfortunately, most of IFI's stuff stays. Good Luck! (your gonna need it.)

Rickertsen2 21-02-2004 22:06

Re: Need interupts help, and another question...
 
Quote:

Originally Posted by Kevin Karan
My other question is if we can exclude some parts of firsts code, like the printf library since they take up a large chunk of the program flash memory and I want to use that space for other stuff.
Thanks,
Kevin Karan
Team 174 Arctic Warriors Programmer

Yea. You can scrap alot more than jsut the printf lib. The first thing we did was gut the default code. I don't remember the exact amount of memory e saved, but we were able to shave off over about 20% of the code. Besides, printf, two other good places that have a lot of room for a diet are userroutines.c and ifi_utilities.c. It is also a good idea to turn on certian compilar optimizations. You would be surprised how much those can save you in some cases. If you don't understand the memory allocation, then it would be a good idea to read up on that, because it will allow you to write better code. The compiler manual is the best resource for that, although i think it kinda sucks.

Kevin Watson 22-02-2004 03:22

Re: Need interupts help, and another question...
 
Quote:

Originally Posted by Kevin Karan
Im having a problem getting the interupts working on the FRC.

The one thing that comes to mind is to make sure that you also set all interrupt inputs as an INPUT (e.g., digital_io_01 = INPUT) while in User_Initialization(). Other than that, can you be more specific when you say they "don't work". If you're really stuck, send me the code and I'll have a look.

-Kevin

DanL 22-02-2004 10:27

Re: Need interupts help, and another question...
 
If you're having problems with interrupts, Daniel Katanski of team 240 wrote an amazingly helpful whitepaper on the topic - I recommend you read the whole thing, as not only it explains in details how to use interrupts and timers, but it also gives some neat programming tricks here and there. I just began using interrupts the other day (after sitting down for a day with that whitepaper and pouring through each line of the default code), so I think other people on this board are going to be more helpful than me in terms of debugging. However, I do want to include this part from the whitepaper:

Quote:

When initializing a digital input interrupt there are 5 things that must be done, they are:
1. Set the port to be an input (as shown in the code above).
2. Set the interrupt on the pin to be a low priority interrupt.
3. Set the edge select (rising from 1 to 0, or falling 0 to 1, remember bit values versus voltages).
4. Clear the interrupt flag.
5. Enable interrupts.
I printed out a copy of that and taped it to the computer monitor. During my debugging stage, I kept on referring back to there to see what I was forgetting - as a beginer, I found that probably the most important part of the entire whitepaper. I would also add "Make sure you call ALL of the necessary initialization functions," but you said you already are doing that.

Although it'll take quite a bit of work to incorporate into your code if you built something off the default IFI code, something that you might also wish to check out is Kevin's heavily annotated interrupt and timer template code. Kevin - you did a great job with your comments on that one - they helped me a lot.

Kevin Karan 22-02-2004 11:20

Re: Need interupts help, and another question...
 
thanks everyone, esp SuperDanman and Kevin Watson. I dont have time on the frc again untill tomarrow, so Im going to have to wait to test this untill then, but what I did was strip some of the excess calories from Kevin Watson's interupt template (most of the printf library and some of the leftover first functions in user_routines) then put everything into that. Let you know how it goes.
Thanks for pointing out that whitepaper SuperDanman, helped alot.


All times are GMT -5. The time now is 13:40.

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