eeprom saving at power failure

I know there was a thread on this 3 years ago, but I have made a circuit that keeps the 5v steady for 310mS after power is cut, and 540mS before it drops below 3v.

I want to store 8 bytes in EEPROM at power failure ( I have a signal to a pin that drops to 0 when the power is cut, ( from a zener that monitors the 12 volts coming in - with protection diodes to avoid going above VCC to the chip )

I know the power used by the 328 will increase while writing, but does anyone know how long it takes to store 8 bytes to EEPROM ?

I can increase the storage cap ( 1500 MFd at the moment ) if needed..

3.3mS. I think your 310mS would be plenty.

Thanks Bob,

I might even use a smaller cap ..

Hmm, its not writing, any ideas?

I havn’t tried eeprom saving before, I have this bit of code, “unsaved” is to stop it writing more than once at power off, and dcOK is the 12v to the 5v reg monitor :-

 unsaved = HIGH;
 
 XH = EEPROM.read ( 1 );
 XT = EEPROM.read ( 2 );
 XU = EEPROM.read ( 3 );
 XC = EEPROM.read ( 4 );
 NH = EEPROM.read ( 5 );
 NT = EEPROM.read ( 6 );
 NU = EEPROM.read ( 7 );
 NC = EEPROM.read ( 8 );

  if ( XH < 6 ){ XH = 6 ; }
  if ( NH < 1 ){ NH = 1 ;}
 
 

pinMode ( clearPin, OUTPUT);
pinMode ( dcOK, INPUT );          //  5v if 12v supply into 5 v reg

   digitalWrite(latchPin, LOW);      // blanking all displays
   for ( int k=0; k<=8; k++ ){
  shiftOut(dataPin, clockPin, LSBFIRST, blanked);      
     digitalWrite(latchPin, HIGH);
     delay (5);
   }  
    showtime ();
    digitalWrite(clearPin, HIGH);

 attachInterrupt(0, checkbutton, RISING);   // interupt routine from vt input ht12 to load new number to queue  
  }
  //*************************************************************
  void loop()
  { 
  
  dcOKstate = digitalRead ( dcOK );  
   if ( dcOKstate == HIGH )
   
   
   {      //  this bits the working disply routine 
                              if ( flash == HIGH ) {     
                                   unsigned long currentblinkMillis = millis();  //  blink to flash counter number
                                   if(currentblinkMillis - previousblinkMillis > 500) { previousblinkMillis = currentblinkMillis;   
                                   if (blinkState == LOW) blinkState = HIGH; else   blinkState = LOW;  }  // blinkwithoutdelay    
                                   
                               timer (); 
                             } else {// end of if flash == high
                             blinkState= LOW;
                           if (fifo.count () > 0 )   { getnumber (); }  //  sees if there are any unread numbers in queue subroutine
                             
                             }//  end of else
  }
  
  else {
 
 if ( unsaved == HIGH  )  { 
    EEPROM.write(1, XH);
    EEPROM.write(2, XT);
    EEPROM.write(3, XU);
    EEPROM.write(4, XC);
    EEPROM.write(5, NH);
    EEPROM.write(6, NT);
    EEPROM.write(7, NU);
    EEPROM.write(8, NC);
    
    unsaved = LOW;
    
 }
  }

 } //end of loop

Works fine now - I was generating the various data from a variable that was preset in the definitions.

I think I will use this in all my displays now, hopefully 100,000 power failures will be after my lifetime !

Looks like the top of your sketch got cut off.

Can you light up and LED or something where the else{} for unsaved == HIGH is to see that its actually getting there?

What makes XH, etc actually change in the sketch?

Oh - ok, never mind!

That would have been a good idea for the LED, I couldnt run the sketch with the chip in the arduino board as the decoder chip for the wireless link is on my protoboard.

The 5v stays high for the same time ( over 300mS ) while it is saving to eeprom, so I am happy with this Powerout saving.

Perhaps I should post the schematic somewhere as the subject has come up many times....