View previous topic :: View next topic |
Author |
Message |
tranz
Joined: 10 Feb 2007 Posts: 78
|
Interrupt Doubt__URGENT |
Posted: Sun Jun 01, 2008 11:36 am |
|
|
Hi,
I am trying to send a bunch of data via UART, so I am using interrupt based routine, where in once the data is received it would transfer the data to an EEPROM device.
But since the data will be in STREAM form, I would not like the interrupt to get over till the entire data is transmitted. So I would like the LOOP to go on an on, till the data is transmitted.
Here is my code as of now.
Code: |
#INT_RDA
void isr_routine()
{
while()// have to put some condition to make it not leave the loop till the interrupt is high.
{
getdata=fgetc(HOSTPC);
write_ext_eeprom(0,getdata);
}}
void main()
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
}
|
So I would like the while ( SOME CONDITION) to go on till the entire data is transferred to the EEPROM device, any suggestions?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 01, 2008 2:34 pm |
|
|
Use the Ex_Sisr.c example file, save the incoming data in a global array.
Keep a count of the total number of bytes received in a global variable.
In main(), check the count, and when you have received the correct
number of bytes, then call the write_ext_eeprom() function from within
main() to write all the bytes to eeprom. Here's the file location:
Quote: | c:\Program Files\picc\Examples\Ex_sisr.c |
|
|
|
tranz
Joined: 10 Feb 2007 Posts: 78
|
|
Posted: Sun Jun 01, 2008 5:41 pm |
|
|
Thanks for the link, unfortunately the data that is coming through the serial port cant be stored, it has to be sent over to the eeprom immediately. Since the size of the data is too big for it to be stored, I am looking at somewhere around 16Kb of data.
Is there any other suggestion? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 01, 2008 6:05 pm |
|
|
You could use an FRAM from Ramtron, instead of a conventional EEPROM.
FRAM is compatible with an eeprom except that it doesn't have a write
delay time.
http://www.ramtron.com/products/nonvolatile-memory/serial.aspx
You can use the i2c or SPI versions.
Then you can use Ex_Sisr.c and write the bytes to FRAM in main().
Just increase the bus speed on the FRAM so that the write operation
is completed in less than one UART character time. |
|
|
Indy
Joined: 16 May 2008 Posts: 24
|
|
Posted: Sun Jun 01, 2008 6:06 pm |
|
|
From an architectural point of view it doesn't make sense to receive your data with a while-loop in the interrupt handler. Interrupts are supposed to handle exceptions and for good response time should be as short as possible. Even with a slow PIC at 4MHz and a high speed serial data of 115kbit receiving a single byte of data means you are wasting close to 99% of the CPU power.
Note that most EEPROMs are slow in being written to, maybe even slower than your receive stream.
For a better design suggestion tell us:
What is your receiving baudrate?
What is the part number of your external eeprom? |
|
|
tranz
Joined: 10 Feb 2007 Posts: 78
|
|
Posted: Sun Jun 01, 2008 6:14 pm |
|
|
The Baud Rate I am working on is about 9600, and the EEPROM is 25LC640. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon Jun 02, 2008 8:08 am |
|
|
Indy. There are some times you want a while loop in ISR.
In serial if you RX a byte while buffering the last one, you could check this
with a while loop and save time going out of, and back into the ISR.
Saving a bunch of reg and restoring them takes time.
And that is what happens when the program goes into and out of the ISR.
You can potentially save that time by putting a while loop in the ISR.
Then it checks if, upon leaving the ISR, you would just go back into it.
If you check that in the ISR then that will be faster, and perhaps allow for faster baud or less errors. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Mon Jun 02, 2008 9:01 am |
|
|
One thing about most eeproms is that their memory consists of 'pages' which are physical boundaries. If you attempt to write data that is larger than this 'page' can contain then you will roll-over and begin over writing at the beginning of the page again.
If you do need to write more data than the page can contain, you need to fill up the page, tell the eeprom to write the data to it's internal memory and then you can start sending data to the next page. Unfortunately, this write requires a minimum amount of time to accomplish. If your data is still streaming during this write then the data that is sent to the eeprom will be lost and not stored. You will need some sort of buffer in order to save it all to an eeprom.
Ronald |
|
|
Indy
Joined: 16 May 2008 Posts: 24
|
|
Posted: Mon Jun 02, 2008 9:17 am |
|
|
Treitmey, I do agree with your exception. The code is not complete yet and I got triggered by the line: Code: | while()// have to put some condition to make it not leave the loop till the interrupt is high. | Reading it again I'm not really sure what Tranz is trying to say here. At first reading I assumed he wants the loop to continue until some external event happens, meaning the interrupt would be active for a long time. Otherwise, if the loop is supposed to break when no more data is waiting in the UART buffer as Treitmey suggests than I was wrong and this is a good design. |
|
|
Indy
Joined: 16 May 2008 Posts: 24
|
|
Posted: Mon Jun 02, 2008 9:33 am |
|
|
tranz wrote: | The Baud Rate I am working on is about 9600, and the EEPROM is 25LC640. | Writing data to this EEPROM can take up to 5ms. At 9600 baud you will receive 5 new bytes in these 5ms so you have a problem when writing single bytes. Luckily the EEPROM allows for page writes in which you can write 32 bytes at once, speeding up the process. This requires some buffering at the PIC and as Rnielsen mentions you will have to correctly handle the page boundaries.
Personally I favour the mentioned alternative of using FRAM chips over EEPROM because FRAM is much easier to use. |
|
|
tranz
Joined: 10 Feb 2007 Posts: 78
|
|
Posted: Mon Jun 02, 2008 10:09 am |
|
|
Thanks guys,
Will let you know how the progress is, based on the results. Unfortunately I cannot use FRAMs at this point of time, since there is a time constraint and I have to make do with what I have got.
Thanks again, much appreciated. |
|
|
|