View previous topic :: View next topic |
Author |
Message |
homfray
Joined: 19 Nov 2003 Posts: 45 Location: Oxford
|
Can I run at 40Mhz |
Posted: Tue Aug 03, 2004 9:56 am |
|
|
I am using a PIC18F8621 with a 40MHz external clock (DS1075-080).
I want to check the inputs of two digital ports and comparing them to the previous values if any are different I record them to the internal memory and record the time.
I would like to do this as quickly as possible (technically 1us would be great but I can just about live with 5). I will be needing to use an interrupt to make sure that I have a constant loop time.
I have made a small progam to see how fast I can go and I appear to go fairly slow 10us for the below program. This makes me think that I am either not setup the PLL correctly or that the interrupt is not correctly done
What settings should I be using
I have configured (in MPLAB IDE configure>configuration bits) to EC-OSC2 as RA6, software enabled 4xPLL (should i use hardware or software???).
Code: | #define Fosc 40000000 // I'm using a 40 MHz crystal
#include <18F8621.h>
//-------------------------------------------------------------------------------------
// COMPILER DIRECTIVES and HARDWARE CONFIGURATION
#use delay(clock = Fosc)
//-------------------------------------------------------------------------------------
// GLOBALS - GENERAL
static short state = 0; //State Switch for watchdog
//-------------------------------------------------------------------------------------
// INTERRUPTS
#int_rtcc
void int_rtcc_isr(void)
{
set_timer0(65475);
state=~state;
}
//-------------------------------------------------------------------------------------
// MAIN
void main()
{
setup_counters(RTCC_INTERNAL, RTCC_DIV_1);
set_timer0(65475);
enable_interrupts(GLOBAL); // set global interrupts
enable_interrupts(INT_RTCC); // disable timer interupt
while (1)
{
output_bit(PIN_H0,state);
}
} |
When I try to add fuses the EC-OSC2 as RA6, software enabled 4xPLL in the configuration settings changes to RC-OSC2 as RA6.
I am not sure if i should be using timer1 as my interrupt as I think it is being used in the actual clock timing.
What configuration settings do i need, what fuses and registers do I need to set, what timer/interrupt and its configuration do I need to make this go the fastest it can
Any help from you lot would be excellent as I am beginning to go slightly mad |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Aug 03, 2004 10:47 am |
|
|
At 40Mhz, 1us is only 10 instructions and 5us would be 50 instructions. You won't stand a chance of doing this with the standard int handler. I suggest you use the high priority int and write your own handler. RJ Hamlett has posted many times on int handlers. Search for his posts under Ttelmah for examples. |
|
|
Guest
|
|
Posted: Tue Aug 03, 2004 11:00 am |
|
|
The maximum clock for this device is 40Mhz. If you are using an external 40Mhz source, you don't need to use the PLL. |
|
|
Guest
|
|
Posted: Tue Aug 03, 2004 11:12 am |
|
|
Mark wrote: | Search for his posts under Ttelmah for examples. |
I get nothing when I do an author search of Ttelmah?? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 03, 2004 11:42 am |
|
|
The board doesn't support author search for unregistered user names
...unfortunately.
Since he always signs his posts with "Best Wishes", you can build your
search string like this:
best wishes interrupts
Then set it to Search For All Terms. |
|
|
|