EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Saving Values to non-volatile memory

Started by Amer November 11, 2009
Hello all,
I am using ADC12 to measure a voltage about 5 times a second. However, I would like to remember the last conversion even if power is disconnected (ie, someone deliberately disconnecting the battery). I was thinking about saving to flash every time a conversion is completed.
I am not so familiar with flash technology but does this seem like a feasible idea?

Thank you.

A

Beginning Microcontrollers with the MSP430

On Thu, 12 Nov 2009 00:19:43 -0000, you wrote:

>Hello all,

> I am using ADC12 to measure a voltage about 5 times a second.
> However, I would like to remember the last conversion even if power
> is disconnected (ie, someone deliberately disconnecting the
> battery). I was thinking about saving to flash every time a
> conversion is completed.

> I am not so familiar with flash technology but does this seem like a
> feasible idea?

5 times a second is doable. You will need to think closely about what
to do in cases where power may be removed before the flash write
completes. Could provide enough energy supply (capacitor) so that if
it is 'unplugged' that it has enough time to finish before power falls
too far. And/or that you check to ensure the capacitor is
sufficiently charged _before_ initiating a write, so that you know it
can complete before Vcc drops too much. Or come up with some other
scheme.

Likely, Al will have something to say about this.

Jon
On Wed, 11 Nov 2009 16:37:58 -0800, I wrote:

>On Thu, 12 Nov 2009 00:19:43 -0000, you wrote:
>
>>Hello all,
>
>> I am using ADC12 to measure a voltage about 5 times a second.
>> However, I would like to remember the last conversion even if power
>> is disconnected (ie, someone deliberately disconnecting the
>> battery). I was thinking about saving to flash every time a
>> conversion is completed.
>
>> I am not so familiar with flash technology but does this seem like a
>> feasible idea?
>
>5 times a second is doable. You will need to think closely about what
>to do in cases where power may be removed before the flash write
>completes. Could provide enough energy supply (capacitor) so that if
>it is 'unplugged' that it has enough time to finish before power falls
>too far. And/or that you check to ensure the capacitor is
>sufficiently charged _before_ initiating a write, so that you know it
>can complete before Vcc drops too much. Or come up with some other
>scheme.
>
>Likely, Al will have something to say about this.

I was imagining that you'd write these sequentially and that you'd
have some reasoned scheme for finding the 'last value.' For example,
that you don't allow some value and fill flash with that, first. Then
you can always find the last one. Or you could set up a different
scheme.

But you _need_ to concern yourself over writing to the same location
over and over. Flash has a rather limited number of times you can do
that. Best to have a method by which the writes are spread out over
the memory region you decide to use, so that each location gets about
the same number of write events to it. This will take some education
and thought to make work well.

Forgot to mention that point.

Jon
Folks,

I'm developing a project on the MSP430F5438 chip. I use SVMHIFG this way to sense
loss of input voltage and call my shutdown routine:

#pragma vector=SYSNMI_VECTOR
__interrupt void SysNmiISR(void)
{
switch (SYSSNIV)
{
case 0x02: // SVMLIFG
TxBuffer(" ", 40, 1);
TxBuffer("*************** SVMLIFG", 40, 1);
__no_operation();
break;

case 0x04: // SVMHIFG
ShutdownSaveTotals();
break;
....................................................
I then have time to save all this, and as an exercise to assure I had ample time,
I am able to write them all out to a serial port about 3 times before dying.

sysConfigurationNv.savedFlag = 0; // unsigned char
sysConfigurationNv.savedGrandTotal = currentGrandTotal; // 64-bit double
sysConfigurationNv.savedTotal = currentTotal; // 64-bit double
sysConfigurationNv.savedDeliveryActive = deliveryActive; // unsigned char
sysConfigurationNv.savedTicketPrinted = ticketPrinted; // unsigned char
sysConfigurationNv.savedMass = currentMass; // 32-bit float
These are written to a specific memory location that is always cleared on successful startup
so I don't have to erase prior to writing. On startup, I check that sysConfigurationNv.savedFlag
has been changed from 0xFF. If so, I restore the local variables frome the saved data.

This may help,
Mike Raines
________________________________
From: m... [mailto:m...] On Behalf Of Jon Kirwan
Sent: Wednesday, November 11, 2009 7:42 PM
To: MSP430 list
Subject: Re: [msp430] Saving Values to non-volatile memory

On Wed, 11 Nov 2009 16:37:58 -0800, I wrote:

>On Thu, 12 Nov 2009 00:19:43 -0000, you wrote:
>
>>Hello all,
>
>> I am using ADC12 to measure a voltage about 5 times a second.
>> However, I would like to remember the last conversion even if power
>> is disconnected (ie, someone deliberately disconnecting the
>> battery). I was thinking about saving to flash every time a
>> conversion is completed.
>
>> I am not so familiar with flash technology but does this seem like a
>> feasible idea?
>
>5 times a second is doable. You will need to think closely about what
>to do in cases where power may be removed before the flash write
>completes. Could provide enough energy supply (capacitor) so that if
>it is 'unplugged' that it has enough time to finish before power falls
>too far. And/or that you check to ensure the capacitor is
>sufficiently charged _before_ initiating a write, so that you know it
>can complete before Vcc drops too much. Or come up with some other
>scheme.
>
>Likely, Al will have something to say about this.

I was imagining that you'd write these sequentially and that you'd
have some reasoned scheme for finding the 'last value.' For example,
that you don't allow some value and fill flash with that, first. Then
you can always find the last one. Or you could set up a different
scheme.

But you _need_ to concern yourself over writing to the same location
over and over. Flash has a rather limited number of times you can do
that. Best to have a method by which the writes are spread out over
the memory region you decide to use, so that each location gets about
the same number of write events to it. This will take some education
and thought to make work well.

Forgot to mention that point.

Jon




Memfault Beyond the Launch