This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SVS on MSP430F and read/write process through flash

Other Parts Discussed in Thread: MSP430F47197

I found the following regarding the SVS:

MSP430F471xx Demo - SVS, Toggle port 5.1 on Vcc < 2.8V

 

 

#include <msp430.h>

int i;

int main(void)

{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer

  P5DIR |= BIT1;                            // P5.1 - Set as output

  SVSCTL = VLD3;                            // SVS enabled @ 2.8V, no POR

  while(1)

  {  

    while(SVSCTL&SVSFG)

    {

      P5OUT ^= BIT1;                        // Toggle LED

      for (i = 0; i < 0x4000; i++);         // SW Delay

    }

  }

}

 

 

 

//   MSP430x471xx Demo - SVS, POR @ 2.5V Vcc

 

 

#include <msp430.h>

 

int main(void)

{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer

  P5DIR |= BIT1;                            // Set P1.0 to output direction

  SVSCTL = 0x60 + PORON;                    // SVS POR enabled @ 2.5V

 

  for (;;)

  {

    volatile unsigned int i;

    i = 50000;                              // Delay

    do (i--);

    while (i != 0);

    P5OUT ^= BIT1;                          // Toggle P1.0 using exclusive-OR

  }

}

 

 

 

 

 

 

 

SOURCE:

 

 

http://www.ti.com/lsds/ti/microcontroller/16-bit_msp430/msp430_software_landing.page

But I need more sample codes regarding the SVS+ read/write flash memory.

Any idea or reference please?

  • You should be aware that there is no common 'MSP430F'. At the very least, there is 'MSP430F1', F2, F4 and F,5/F6 family.
    Each of them has more or less differences regarding SVS (most F1x devices don't have one, and the handling of the SVS differs significantly across families) and flash writing. While the basic concept is roughly the same, the devil is in the detail.

    The two demos you posted us the quite simple SVS in the 4x family to (first case) set a flag if voltage is below ~2.8V, or (second case) let the same flag trigger a POR when the voltage is below ~2.5V.

    However, the 4x family SVS isn't very precise. The trigger level varies up to +-0.25V around the nominal value for different MSPs.

    What exactly do you want to do?

  • Jens-Michael Gross said:

    You should be aware that there is no common 'MSP430F'. At the very least, there is 'MSP430F1', F2, F4 and F,5/F6 family.
    Each of them has more or less differences regarding SVS (most F1x devices don't have one, and the handling of the SVS differs significantly across families) and flash writing. While the basic concept is roughly the same, the devil is in the detail.

    The two demos you posted us the quite simple SVS in the 4x family to (first case) set a flag if voltage is below ~2.8V, or (second case) let the same flag trigger a POR when the voltage is below ~2.5V.

    However, the 4x family SVS isn't very precise. The trigger level varies up to +-0.25V around the nominal value for different MSPs.

    What exactly do you want to do?

    Well, actually I have a MSP430F47197 Evaluation module to play with. I wrote a code as follows.

    1. Shows start on the LCD.

    2. Start to count up from 0 to 100.

    As you know the low power MSP430 series can power LCD without external power even though I have an external power to power up the LEDs on the board. 

    What is the objective:

    I would like to load the program and unplug the FET's cable. Then power it up with power cord 120v that is converted to almost 4v to feed the board.

    So, the LCD shows the count up process.

    As it is counting up I would like to unplug the power cord and as you may know LCD is connected to Capacitors and it takes time for the LCD contents to be gone. Let's say 45 46 47 ... and start to get paled and faded out!

    I would like to apply SVS to detect the power loss and then write the content on the LCD and re-call it again from flash and show it as I plug the power cord again.

    As you mentioned 4X family SVS is not very precise. Is the above-mentioned process practical?

  • Okay, if I understand you right, you want to detect a power loss to save the current state of the application to flash and continue when power returns.

    CaEngineer said:
    that is converted to almost 4v to feed the board.

    I hope you have another regulator to supply the MSP with no more than 3.6V. 4V is a bit outside the specs.

    CaEngineer said:
    As you mentioned 4X family SVS is not very precise. Is the above-mentioned process practical?

    As usual, it depends.

    The SVS is relatively low power (15µA) and can be used to detect sudden power loss. But won't be precise. Also, it can only detect the supply voltage of the MSP.
    When the board is powered by 4V and the MSP with 3.3V, the SVS can only trigger when voltage goes below 2.8V (worst case). There's not much headroom then to do a flash erase and write.

    But when you have an AC-powered device, supply current is not an issue. You can then connect the 4V with a resistor divider to the MSP's comparator. This way you can very precisely trigger the write process even if the MSP supply hasn't started dropping yet. (e.g. on 3.7V). The Comparator requires up to 140µA plus the additional cross-current through the resistor divider, but if you have 'unlimited' power, this won't be a problem.

    Anyway, before writing, you should switch off all other consumers, like LEDs, to not burn the remaining charge prematurely.

  • Jens-Michael Gross said:

    Okay, if I understand you right, you want to detect a power loss to save the current state of the application to flash and continue when power returns.

    Correct! 

     I hope you have another regulator to supply the MSP with no more than 3.6V. 4V is a bit outside the specs.

    I use MSP430F47197 evaluation module which has voltage regulator and MCUis powered at around 3 something by FET.

    Also, it can only detect the supply voltage of the MSP.

    It is powered by FET during the programming. Thereafter we powered it by power cord 120v to 3.9 v to MSPF430.

    Only trigger when voltage goes below 2.8V (worst case). There's not much headroom then to do a flash erase and write.

    According to the datasheet, flash can read/write with minimum of 2.2 volts.

    But when you have an AC-powered device, supply current is not an issue. 

    Yes I would like to play with AC power which is converted to DC and will be ready to use by micro.

     

    Anyway, before writing, you should switch off all other consumers, like LEDs, to not burn the remaining charge prematurely.

     

    This is not done by SVS automatically?

     

     

     

     

  • CaEngineer said:

    Only trigger when voltage goes below 2.8V (worst case). There's not much headroom then to do a flash erase and write.

    According to the datasheet, flash can read/write with minimum of 2.2 volts.

    [/quote]

    When Vcc has already begun to drop, writing to flash will cause it to drop even faster. Also, flash write, even though possible down to 2.2V, requires a relatively stable voltage. If voltage drops too much too fast (even if still above 2.2V) flash write may fail.

    CaEngineer said:

    Anyway, before writing, you should switch off all other consumers, like LEDs, to not burn the remaining charge prematurely.

    This is not done by SVS automatically?[/quote]
    No. The SVS will either reset the device, or trigger an interrupt. It doesn't know whether a port pin has a LED attached or drives a vital signal that must not be touched. It's up to you to switch off all current sinks inside the ISR to preserve as much of the remaining power as possible for the write.

    In your situation, my suggestion is to us a 1:1 resistor divider on the supply voltage (before the regulator). Measure this with the ADC, so you'll see when the unregulated voltage begins to drop. Then (assuming a sufficient storage cap) there's plenty of time to shut down and safe the data before the regulated voltage begins to drop.

  • Jens-Michael Gross said:
    When Vcc has already begun to drop, writing to flash will cause it to drop even faster. Also, flash write, even though possible down to 2.2V, requires a relatively stable voltage. If voltage drops too much too fast (even if still above 2.2V) flash write may fail.

    Oh ***! I didn't know that writing to flash causes a problem. Then I might use an external EEPROM?! What do you think?Does that have the same affect?

  • Jens-Michael Gross said:
    In your situation, my suggestion is to us a 1:1 resistor divider on the supply voltage (before the regulator). Measure this with the ADC, so you'll see when the unregulated voltage begins to drop. Then (assuming a sufficient storage cap) there's plenty of time to shut down and safe the data before the regulated voltage begins to drop.

    Oh cool solution! I have a customized ready board now and I am not sure about the existence of such resistor on my board but I need to put into account later on. Thanks for sharing your experience on SVS! I will keep you updated shortly!

  • I guess I better work on the E-meter first and get it to work and test the SVS after. :)

  • CaEngineer said:
    Then I might use an external EEPROM?

    Writing to external EEPROM also requires some energy and weakens the reserves and causes the voltage to drop faster. How much and how sensible the EEPROM is to this, depends on the EEPROM. Also, external device access usually takes more time (thus more voltage drop during the process)

  • Thanks Jens-Michael. I will work on that as soon as I get my Energy meter worked! (y)

  • Jens-Michael Gross said:
    set a flag if voltage is below ~2.8V

    Seems the flag that you mentioned which is called SVSFG set to 1 but never gets back and get stuck in while loop. What can I do to get out of the loop right after power loss?

    #include <msp430f47197.h>
    
    int i;
    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
       FLL_CTL0 |= XCAP11PF;                     // Configure load caps
    
      // Wait for xtal to stabilize
      do
      {
        IFG1 &= ~OFIFG;                         // Clear OSCFault flag
        for (i = 0x47FF; i > 0; i--);           // Time for flag to set
      }
      while ((IFG1 & OFIFG));                   // OSCFault flag still set?
      
      P5SEL =BIT1+BIT2+BIT3+BIT4;               // Set COM pins for LCD --- 
      LCDACTL = LCDON+LCD4MUX;                  // 4mux LCD, ACLK/32
      P5DIR |= 0x20;                            // P4.6 - Set as output
       P5OUT ^= 0x20; 
      SVSCTL = VLD3;                            // SVS enabled @ 2.8V, no POR --- or using 0x80
      while(1)
      {   
        if(SVSCTL & SVSFG)
        {
            P5DIR |= 0x80;  
          P5OUT ^= 0x80;                        // Toggle LED
      //    for (i = 0; i < 0x4000; i++);         // SW Delay
        //  SVSCTL |= PORON;
         //  _BIS_SR(LPM4_bits + GIE);  
       
      LCDMEM[SVSFG+48];
          
    //            
    //           char *Flash_ptr;
    //  Flash_ptr = (char*) 0x001;             
    //  char value = *Flash_ptr;
    //    value ^= value ;
    //   *Flash_ptr = value;
    //  0x001 = *Flash_ptr;
        }
      }
    }

  • I guess I found my solution by set the flag back!

          SVSFG == 1; set back to one 

    What do you think?

  • Jens-Michael Gross said:
    15µA

    Yes. Typical 10 uA and Max 15uA.

    Jens-Michael Gross said:
    it can only detect the supply voltage of the MSP

    In our case we will power the board by 120v AC and then it is converted down to 3.3v for Vcc.

    Jens-Michael Gross said:
    MSP with 3.3V

    Can any  MSP430F4xx family works with less than Vcc= 3.3v?
    Jens-Michael Gross said:
    There's not much headroom then to do a flash erase and write.

    This is my problem and I believe we do not have enough time to read and write and the power quickly is gone! but may I use one of the LPM0-LPM4 modes to save the energy and have time to write into flash?

  • CaEngineer said:
          SVSFG == 1; set back to one 

    This is no assignment, it is an expression. Both, 'SVSFG' and '1' are constants and the result of the expression is 'true' (= -1 = 0xFF), since SVSFG is coincidentally 0x01.
    You do not assign the result to any variable, so it is discarded and the whole line does nothing. Likely, the compiler will eliminated it silently.

    CaEngineer said:
    In our case we will power the board by 120v AC and then it is converted down to 3.3v for Vcc.

    I don't think you have a monolithic chip which takes 120VAC and outputs 3.3VDC?
    Liekly, you have a transformer stage and a rectifier stage, with an unregulated or only roughly regulated output of >4V.
    You can measure this voltage before the regulator (with a proper voltage divider) and see when it begins to drop (due to power loss) long before it get so low that the 3.3V regulator begins to fail.
    You can still use the SVS for this, as it can be configured to compare an external voltage (SVSIN) to 1.2V

  • Jens-Michael Gross said:
    I don't think you have a monolithic chip which takes 120VAC and outputs 3.3VDC?

    Yes we have AC to DC converter on the board. The chip does not convert 120 to the lower voltage for sure.

  • CaEngineer said:
    Can any MSP430F4xx family works with less than Vcc= 3.3v?

    Sure. If running below 3MHz, only 1.8V are required (but you can't program the flash then, it requires 2.7V. 2.9V are good for 4.6MHz and for 8MHz you'll need 3.6V. AFAIK, all 4x family device share this spec. And the 1X family has similar requirements.

    CaEngineer said:
    Yes we have AC to DC converter on the board. The chip does not convert 120 to the lower voltage for sure.

    So between the AC/DC converter and the 3.3V regulator, you have a low DC voltage which will start to drop long before the 3.3V regulator can't maintain the 3.3V. You can measure this intermediate voltage with a proper voltage divider. If it is typically 5V, you can use a 4:1 divider, to get 1.25V on normal operation, and when the voltage drops below 4.8V. the SVS (configured to check SVSIN input against 1.2V) will trigger. However, the 3.3V regulator won't fail until the voltage has dropped by another 0.8V or so.

**Attention** This is a public forum