>-----Original Message----- >From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] >On Behalf Of Padu >Sent: 12 November 2004 07:05 >To: Microcontroller discussion list - Public. >Subject: [PIC]: Interrupt vs. Main loop > > >I'm facing a conceptual dilemma, many of the gurus here and >elsewhere recommend to keep interrupt code to a minimum. >That's what I'm trying to do, but I'm having some serious >problems to transfer data gathered at the interrupt procedure >and use it on the main loop. > >The interrup is receiving a constant stream of UART data at >19200baud (it will be faster as soon as I get the appropriate >crystal). What I have to do is to interface with my >compactflash card and store each one of those bytes in it. I >intend to store data as FAT files (I know, 512 bytes blocks). >Thing is when I'm trying to process something on the main >loop, things are coming at a faster rate on the interrupt. > >One thing I've tried was to setup a circular list of 64 bytes, >push data on the interrupt and pop it on the main loop, it >didn't work. Then I've increased the circular buffer size to >128, then I started to see some of the expected bytes on my CF >(actually I'm sending them via USART to the PC just to test, >but I'll replace to writing to the CF later). When I increased >to 255, then almost got it, but still the interrupt was >winning the race. I feel that if I had a big enough buffer, >eventually it would work out, but perhaps there is a better >way to solve it. > >Should I put all my CF writing code in the interrupt >procedure? Would I be risking to get overrun errors? > >I have to confess, I'm enjoying learning all these new things >about PIC and electronics, but sometimes it's frustrating, >things don't happen at the same speed of software >development... or I'm too impatient to be a newbie again. Does the main loop have to do a lot of other things at the same time as writing to compact flash? If yes, then you will simply have to arrange a priority system, where the compact flash has the highest priority of all the main loop tasks. If writing data to the CF is all the main loop does then you have a simple case of data coming in too quickly for the PIC to handle. A larger buffer will simply delay the problem if amount the data coming in is much larger than the buffer size. Some form of flow control on you serial link would be the best solution. Moving time consuming operations into the interrupt is simply going to create you more problems, especialy if you up the bit rate as you will start getting overrun problems. Regards Mike ======================================================================= This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. ======================================================================= _______________________________________________ http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist