View previous topic :: View next topic |
Author |
Message |
jacqueskleynhans
Joined: 10 Apr 2008 Posts: 109 Location: Cape Town, South Africa
|
Flash Storage |
Posted: Thu Aug 28, 2008 5:29 am |
|
|
Hi i was wondering how i can store adc values and then printf when the memory is full is that possible. Need to store values from an accelerometer. Values need to be stored as floats. Stored in the flash mem.
Im using a 16f877a which has a flash mem of 368 bytes so that probably equates to 5 samples per channel.
Is it better to create an array to store the values in or how do i go about doing this ?
Regards _________________ "THE ONLY EASY DAY WAS YESTERDAY" |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Aug 28, 2008 7:22 am |
|
|
16F877A has 256 Byte of EEPROM, actually. EEPROM is written in Byte entities, so you have to store your float data bytewise, e. g. from a union or by a type cast. Having a function that stores a single float to choosen EEPROM address would be the most simple solution to my opinion, e. g.:
Code: | void WriteFloatEeprom(int8 bAddress, float fData)
{
int8 i;
for(i = 0; i < 4; ++i) write_eeprom(bAddress + i, *(&fData + i));
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 28, 2008 10:57 am |
|
|
Quote: | write_eeprom(bAddress + i, *(&fData + i)); |
This won't work, because the address of the float will increment by 4
bytes when you add 1 to it. You need to cast the float pointer into a byte
pointer before you add a byte index ('i') to it. See the sample code in this FAQ article:
http://www.ccsinfo.com/faq.php?page=write_eeprom_not_byte |
|
|
|