View previous topic :: View next topic |
Author |
Message |
P_Santos
Joined: 07 Jul 2011 Posts: 114
|
Posted: Fri Jan 04, 2013 5:42 pm Post subject: Flash area writing |
|
|
Hello,
I need write many times during program execution one byte at a non-volatile memory location
One possibility would be in the eeprom of the Atmega. According to the Datasheet, each
cpu eeprom cell supports as much as 100,000 written, what for my case would be a long-term impediment
In addition to the time of approx. 15ms it is necessary to complete the writing.
Is there any way to write the byte i need in the micro Flash area so that don't have this
limitation of quantities and timing of written?
Apreciate any help
Thanks
Best regards
P_Santos |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Jan 04, 2013 8:26 pm Post subject: |
|
|
answer : no.
possible alternatives :
- back up battery
- external fram (ramtron) chip
- more intelligent write where you use an array and count the number of writes. _________________ Mark |
|
Back to top |
|
|
P_Santos
Joined: 07 Jul 2011 Posts: 114
|
Posted: Sat Jan 05, 2013 3:45 pm Post subject: |
|
|
Thank You Albertsm |
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Sat Jan 05, 2013 4:04 pm Post subject: |
|
|
Hi,
I read from one of your previous post that you are using the DS1307.
Just use the non-volatile SRAM of your RTC chip.
The DS1307 serial real-time clock (RTC) is a lowpower,
full binary-coded decimal (BCD) clock/calendar
plus 56 bytes of NV SRAM.
56-Byte, Battery-Backed, General-Purpose RAM with Unlimited Writes.
Datasheet: LINK
Best regards,
Luciano |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
|
Back to top |
|
|
Tiny
Joined: 10 Nov 2010 Posts: 101 Location: The Netherlands
|
Posted: Sat Jan 05, 2013 4:51 pm Post subject: |
|
|
I had the same problem, i must store a power-on timer to log the time that de unit is powered.
i do al logging every minute, 100000 minutes = 1666 hrs
i need-it al least 30000 hrs totale
the solution for me is that is use an index counter that points to the eprom location that where used for the logtimer
Code: |
eprom locations
' 199 = index tbv row teller logtimer
' 200...203 204...207 208...211 212...215 216...219
' 220...223 224...227 228...231 232...235 236...239
' 240...243 244...247 248...251 252...255 256...259
' 260...263 264...267 268...271 272...275 276...279
Dim Logtimer As Dword 'hold runtime
Dim Byte_1 As Byte At Logtimer Overlay
Dim Byte_2 As Byte At Logtimer + 1 Overlay
Dim Byte_3 As Byte At Logtimer + 2 Overlay
Dim Byte_4 As Byte At Logtimer + 3 Overlay
Sub Updatelogtimer()
Local Teller As Integer
Teller = 4
Teller = Teller * Indexlogtimer
Teller = Teller + 200
Readeeprom E2prom_waarde , Teller
Byte_4 = E2prom_waarde
Incr Teller
Readeeprom E2prom_waarde , Teller
Byte_3 = E2prom_waarde
Incr Teller
Readeeprom E2prom_waarde , Teller
Byte_2 = E2prom_waarde
Incr Teller
Readeeprom E2prom_waarde , Teller
Byte_1 = E2prom_waarde
Incr Logtimer
If Logtimer > 100000 Then
Logtimer = 1
Incr Indexlogtimer
If Indexlogtimer = 20 Then Indexlogtimer = 0
Writeeeprom Indexlogtimer , 199
End If
Teller = 4
Teller = Teller * Indexlogtimer
Teller = Teller + 200
Writeeeprom Byte_4 , Teller
Incr Teller
Writeeeprom Byte_3 , Teller
Incr Teller
Writeeeprom Byte_2 , Teller
Incr Teller
Writeeeprom Byte_1 , Teller
Print , "Uptime: " ; Logtimer ; " minuts"
End Sub
|
Tiny |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Sat Jan 05, 2013 5:12 pm Post subject: |
|
|
@Tiny
But what happens after an power failure? you don't know the value of logtimer anymore and therefore you can't know what the last used eeprom address was. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
P_Santos
Joined: 07 Jul 2011 Posts: 114
|
Posted: Sat Jan 05, 2013 7:35 pm Post subject: |
|
|
Hello Luciano,
Great idea, thank you
Sometimes during program execution i need to save a byte value, in this case on register 9 NV SRAM of the DS1307
On powerup i need to get this value from the DS1307
Can this code work?
Code: |
dim bin_pos as byte
Get_pos: 'on Powerup get the value of register 9
I2cstart ' init start
I2cwbyte Ds1307w ' send adress
I2cwbyte 9 ' choose the register
I2cstart ' init start
I2cwbyte Ds1307r ' send adress
I2crbyte Bin_pos , Nack ' get the value of register 9 on the DS1307 and save it on var bin_pos
I2cstop
Return
'
Set_pos: 'sometimes during program execution save the value of var bin_pos to the register 9 of DS1307
I2cstart ' init start
I2cwbyte Ds1307w ' send address
I2cwbyte 9 ' choose the register
I2cwbyte Bin_pos ' and write the value of bin_pos to the register 9 NV SRAM of 1307
I2cstop
Return
|
Best regards
P_Santos |
|
Back to top |
|
|
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy
|
Posted: Sat Jan 05, 2013 8:26 pm Post subject: |
|
|
Hi,
Use two bytes of SRAM in the DS1307 RTC chip, in the first byte you store a flag,
in the second byte you store your value.
(Pseudocode)
When you write:
- Write 170 in the first byte (flag). (DEC 170 = BIN 10101010).
- Write the value in the second byte.
- Read back the value from the second byte.
- If the read value is OK, write 85 in the first byte (flag). (DEC 85 = BIN 1010101).
When you read:
Read the flag value from the first byte.
If flag = 85 then
Read the value from the second byte
Else
Restore default value or print error
Endif
When read 85 from the first byte, then you know that the value in the
second byte was written OK.
I don't know what you are storing, but if you use more bytes,
you can store the current value and the previous one and use
this second one in case the current value is corrupted.
(In case the value of the flag is not 85).
Best regards,
Luciano |
|
Back to top |
|
|
Tiny
Joined: 10 Nov 2010 Posts: 101 Location: The Netherlands
|
|
Back to top |
|
|
|