View previous topic :: View next topic |
Author |
Message |
Can
Joined: 26 Feb 2012 Posts: 23
|
Crash/Freeze Problem |
Posted: Sun Feb 26, 2012 3:42 am |
|
|
Hello everyone,
I am trying to build a data logger. I was able to achieve the USB connection between the logger to the computer using CDC. I am able to send commands to the logger using the keyboard. I am able to keep the real time using a DS1307. Up to this point everything is ok. However as this is a logger, I need to log data to some place. I chose to keep the data in the unused parts of the program flash as this will let me keep data for one week in 5 minutes intervals.
My problem is, I am trying to read the program flash which I reserved for logging my data and printing the data over USB. However after printing some data (but not too much) it keeps crashing. I am using an 18F2550 with a 20MHz crystal. Here is the part of the code that keeps crashing:
Code: |
void ReadArrayFromFlash()
{
int16 FlashStartAddress;
int say;
int n;
FlashStartAddress = FLASH_DATA_START; //Defined previously to be the halfway of the program memory
for(say=0;say<10;say++){
read_program_memory( FlashStartAddress, veriSeti, 8 ); //veriSeti is defined as int8 veriSeti[8] previously
for(n = 0; n < 8; n++)
{
printf(usb_cdc_putc,"%u:%u ",n,veriSeti[n]);
}
printf(usb_cdc_putc, "%u. veri yazıldı\r\n",say);
FlashStartAddress += 8;
}
}
|
I crashes mostly before it finishes the first line like this
0:255 1:255 2:255 3:255 4:255 5:2
0:255 1:
etc.
I tried putting delays between stuff but it gets the situation worse. I also tried usb_cdc_putc_fast() but it didn't help either..
Thanks, |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sun Feb 26, 2012 5:09 am |
|
|
Add an external memory.
Even writing only every 5 minutes, you could kill the chip in under 35 days, writing to the program memory like this....
Every time you write, you use one of the write life cycles of the chip. Just 10000 cycles minimum warranted.
Program memory is _not_ designed for repeated writes like this.
Is your write code still running when you do the read?.
Remember that when you write to a program memory location, code execution completely stops for the write cycle time. 2mSec. USB, _requires_ that the packet receive ISR is handled quickly. Anything over perhaps 1mSec delay, can cause USB problems. Writing to the program memory, while handling USB, will cause problems.
You need to use an external memory, to avoid the life problems (which will also avoid the write problem as well). You could probably program round the problem, by setting a flag that prevents memory writes taking place while the USB transmission is occurring, buffering the data and only writing later, but the write life problem will remain.
Best Wishes |
|
|
Can
Joined: 26 Feb 2012 Posts: 23
|
|
Posted: Sun Feb 26, 2012 8:17 am |
|
|
O oh, I didn't know that i would be consuming one write cycle each time I write to the program flash, even small amounts..
I was just trying to read from the memory before figuring out how to write to it.
So I guess i will just go with an external EEPROM and try to get it working.
Thank you. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sun Feb 26, 2012 8:42 am |
|
|
If you're going to add an EEPROM, can I suggest you look at an FRAM instead. Slightly more expensive, but _massively_ faster. Instead of the 4mSec/block write time, the write time on FRAM is so fast that it finished before you can send the next byte.
If you are only reading, your current problem is probably elsewhere. Look at your cap on the Vusb pin. The specified size really is a minimum, and this cap _must_ have good high frequency performance. Something like a 0.47uF polyester is 'ideal'. Don't try to go too large though. If this rail is not really stable it will cause USB hangs and crashes. Same applies to the main chip's supply. What is your brownout setting?. How is the supply generated?. What smoothing have you got close to the PIC?.
Best Wishes |
|
|
Can
Joined: 26 Feb 2012 Posts: 23
|
|
Posted: Sun Feb 26, 2012 9:33 am |
|
|
I'll check out the FRAM and see if works for me or not.
For the cap on Vusb, I already have a 0.47 uF, I have a decoupling cap between Vcc and Vss, which I receive from the USB, I don't have a brownout setting, and I don't get what you mean "smoothing"
When I read the RTC and print it through USB I don't have an issue, the issue only rises when i try to dump the data read from the program flash.
Thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sun Feb 26, 2012 10:48 am |
|
|
As for logging data, depending of the amout of data to store, you might want to consider a 'Vinculum' based flashdrive interface. Simple, cheap, easy to program and 100% compatible with PC programs, if you save the data in CSV format. About $20 for a real 'plug and play' solution to unlimited data storage with ZERO interface problems that MMS/SD has. If you value your time consider all solutions, EEPROM, FRAM, Vinculum, SD, etc. Each has good things and bad things...
Cost of hardware is cheap these days, compared to R&D time (labour), so while $20 upfront compared to $10 might seem excessive, factor in your wasted time because the $10 'solution' didn't work right 'out of the box' makes spending a little extra up front worthwhile. |
|
|
Can
Joined: 26 Feb 2012 Posts: 23
|
|
Posted: Sun Feb 26, 2012 2:16 pm |
|
|
temtronic I agree with you that out-of-box solutions will save huge time however 20$ worth solution is out of limit for me. I need to keep the cost as low as I can. In which case I need to put a lot of my time in the project but hey it has a bright side. The more effort I put, the more things I have for writing in my thesis ;)
Best, |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Sun Feb 26, 2012 3:06 pm |
|
|
Ttelmah wrote: | If you're going to add an EEPROM, can I suggest you look at an FRAM instead. |
I used Ramtron FRAMs exclusively for many years but the past couple of years they have simply not been available. Zero supplier and manufacturer stock with no timeline for availability. I see that in the recent past a small number have become available again but I'm hesitant to specify their FRAMs in new products. I'm not sure what is the reason for this but I'm leery given the silence around the shortage. Did they discover a flaw in the design and pulled stock while they fixed the issue? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sun Feb 26, 2012 3:16 pm |
|
|
Digikey, Mouser and Future all have large quantities...as of today
anyway. Newark seems to be out of stock. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Sun Feb 26, 2012 7:04 pm |
|
|
dyeatman wrote: | Digikey, Mouser and Future all have large quantities...as of today
anyway. Newark seems to be out of stock. |
Encouraging. Last time I was designing something that needed an EEPROM was last July and there was no stock available anywhere. I remember none being available about 12-18 months prior to that as well. Made me nervous (still does)...parts shortages don't last that long and don't encompass an entire product line. Makes me wonder what they found wrong, if anything. |
|
|
|