CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

HIGH_INTS = TRUE
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
asmallri



Joined: 12 Aug 2004
Posts: 1680
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Aug 02, 2006 2:03 am     Reply with quote

Try to use the fast directive. In this case you will need to replace:

Code:
 SaveToRxCircularbuffer(NewChar);


With some in-line assembler or with code that will not affect other registers with the exception of the WREG and STATUS register. Avoid manipulating a variable larger than 8 bits. If your assembler uses FSR (mine would) then save this into a dedicated location in memory (hint use #locate) and restore it before exiting the ISR.

Using this method can potentially save 100 CPU cycles per interrupt.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Aug 02, 2006 7:47 am     Reply with quote

That sounds great asmallri. Would you post some code showing how this is done. -or a link-

It just helps me to get it to gell into my head. I like to take working code fragments and changes bits here and there to make sure I am understanding it correctly
EdWaugh



Joined: 07 Dec 2004
Posts: 127
Location: Southampton, UK

View user's profile Send private message

Hi
PostPosted: Thu Aug 03, 2006 5:10 am     Reply with quote

Yea I've been looking at the flags, I was mostly getting overrun with the odd framing error but I thought the framing errors might be due to a previous overrun error...

I have three interrupts active:

- External, very rare, once an hour disables all interrupts and performs house keeping tasks for a few seconds, we are not interested in the serial data here.

- Timer2, 400Hz which I divide by counting to ten in the interrupt and on every tenth count I run the data sampling, external SPI and internal A2Ds. This is all quite fast tho. This is also where the circular buffer is read to get out the NMEA strings I want to receive, there are a few char comparisons and moving chars from one string to another but I think this should really take no time on a 40MHz pic.

- RDA, HIGH, at the top of the priority list as well as a high interrupt. I'd expect this to interrupt everything else so I'm surprised that I still get some overruns. All it does is copy the byte to a buffer and update the variables regarding buffer position, there are no function calls.

I've managed to fix the problem by reducing the RS232 speed to 4800 baud (from 9600) which is just fast enought to do what I want. Putting the speed way up to 115,200 baud doesn't actually seem to cause more errors than at 9600 baud.

Anyway, reducing the speed has solved it to my satisfaction but ideally I would like to know that I can do better than this as this is quite a typical application for me. Suggestions are welcome as always.

cheers

ed
Ttelmah
Guest







PostPosted: Thu Aug 03, 2006 6:02 am     Reply with quote

Some comments.
First, you talk about the external interrupt 'disabling all interrupts'. How are you doing this? You are aware, that you must _never_ use the 'enable_interrupts(GLOBAL)' line inside an ISR?.
Second comment. You talk about the 400Hz interrupt, on every tenth run, doing data sampling, esternal SPI, and handling internal A2D's. These could add up to a _lot_ of time. The 'plural' on A2D, implies that there must be settling time between channel selection. The A2D itself, implies several uSec to take a reading. SPI, depending on the clock rate, could easily involve several uSec of delay, etc. etc.. Add the overhead of the interrupt, and this may well be the heart of your problem. To read AD values inside an interrupt at reasonable speed, I'd suggest building a state machine, in your 400Hz interrupt, and doing something like:
First state - select channel to read
Second state - trigger ADC conversion
Third state - read value
Do one 'state' each time the interrupt occurs, and repeat for the channels needed. Add states for the SPI read etc.. This way the delays are not included inside the interrupt time...

Best Wishes
EdWaugh



Joined: 07 Dec 2004
Posts: 127
Location: Southampton, UK

View user's profile Send private message

PostPosted: Thu Aug 03, 2006 6:13 am     Reply with quote

Thanks for the advice, I didn't know about the enable_interrupts(GLOBAL) inside an ISR thing although I'm not doing that. I set a flag in the isr which gets picked up in my main while(1){} loop. I am disabling interrupts in the isr tho, is that wrong? I just assumed I was stopping all future interrupts, does the compiler helpfully renable them for me when the isr exits?

The compiler manual says you don't need to disable interrupts in an isr as they are disabled anyway although I think this is not true for me as I have a HIGH interrupt as well...

The state machine thing is an interesting idea I might give it a try.

cheers

ed
Ttelmah
Guest







PostPosted: Thu Aug 03, 2006 8:17 am     Reply with quote

Disabling an individual interrupt inside the handler is fine.
There is no point in putting RDA in the priority list at all, if it is set as 'high'. The priority list, affects the order that the interrupts are 'polled' in the global (low priority) handler. if you have only one high priority interrupt there is no order involved here. However see below...
What version is yout compiler?. The handling of 'high' has changed with different versions. What pin is your 'external' interrupt connected to (INT0?)?. If this is connected to INT0, then this potentially introduces a problem, that may be at the 'core' of your difficulty. On the 18 chips, if interrupt priorities are enabled, then INT0, is always a 'high priority' interrupt. This increases the complexity of the high priority handler... You might want to try putting this onto INT1, if the line is available, and see what the effect is.
What is the actual chip?. Have you checked for any erratas?. There are a _lot_ on some of the latter chips...

Best Wishes
EdWaugh



Joined: 07 Dec 2004
Posts: 127
Location: Southampton, UK

View user's profile Send private message

Hi
PostPosted: Thu Aug 03, 2006 8:50 am     Reply with quote

My compiler is 3.245 and the chip is an 18f6722 my other very rare (hourly from an RTC) interrupt is on int_ext1 but that's a good point about ext0, I hadn't considered that. I do have other devices on ext_0 so I guess its worth watching out for it.

I hadn't disabled the invidudal interrupt inside the handler I was trying GLOBAL so I'll change that. I appreciate your right about the priority list I was just trying to do everything I could to make it work better!

I'll have a check of the erratas.

cheers

ed
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Aug 03, 2006 9:53 am     Reply with quote

Quote:
I'll have a check of the erratas.
Yesterday the errata list for the PIC18F6722 was updated. Now you have another 13 more errata's to take care of, a total of 37 errata's! Thanks Microchip. Mad
asmallri



Joined: 12 Aug 2004
Posts: 1680
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Aug 04, 2006 1:37 am     Reply with quote

Here is an extract from my interrrupt handler used with the FAST directive.

All local variables are fixed (via #locate) in the access bank.

Code:
      // store the received byte in the ring buffer                     
      #asm
      movff   FSR0L, IH_FSR0L
      movff   FSR0H, IH_FSR0H
      lfsr   0, RxBaseRFID
      movf   RxHeadRFID, W
      movff   SWU_RCREG, PLUSW0
      movff   IH_FSR0L, FSR0L
      movff   IH_FSR0H, FSR0H
      #endasm

      ++RxHeadRFID;
      RxHeadRFID %= RxQSizeRFID;
      // Disable Timer 2 interrupt and enable start bit detection

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group