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.

MSP430I2041: How to monitor DVCC for power failure

Part Number: MSP430I2041

Hello ,

There is another query from us as we want to detect power failure condition .
For that we are monitoring VMONIFG flag but we are using it with internal DVCC voltage reference to compare .
As there is example of external voltage m (VMONIN Pin)reference is available ,but there is no example on how to use DVCC .
Can you please guide us how we can use it?
Thanks & Regards,
Ashwini Jadhav
  • Hello,

    You should be able to use the example and just change the VMONLVLx bits in the VMONCTL register. The functionality should be very similar regardless of what's being monitored. See Section 3.2.3 in the user's guide for more details.

  • I have went through user's guide.

  • here is my code on which we are working but not getting the expected results .Pleas check n let me know if anything m missing.For monitoring DVCC there is no need of external circuitry to be add right?

    WDT_hold(WDT_BASE);
    
    // Setup the LED
    GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN4);
    GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN4);
    
    // Setup the voltage monitor to compare VMONIN to 1160mV
    PMM_setupVoltageMonitor(PMM_DVCC_2850MV);
    
    // When started up, VMON requires a settling time of 0.5us
    // MCLK = ~16MHz; 1 cycle = ~0.0625us
    __delay_cycles(10);
    
    // Setup VMONIN Pin
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2,GPIO_PIN3,GPIO_TERNARY_MODULE_FUNCTION);
    
    // Enable the voltage monitor interrupt
    PMM_enableInterrupt(PMM_VMON_INTERRUPT);
    
    
    while(1) {
    // If we are not in ISR then VMONIN > 1160mV
    GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN4);
    }
    __attribute__((interrupt(VMON_VECTOR)))
    void VMON_ISR(void) {
    // VMONIN < 1160mV, LED Off
    GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN4);
    }

  • You're not enabling global interrupts. Look at the "pmm_ex2_vmon1160mV.c" code example again.

  • Also, when you paste code, please insert it using Insert > Code > C. I've updated your thread accordingly. If it's formatted, it's easier to read and you may have a better chance of getting help from the community.

  • Hello James,

    Had enable the global interrupts but still not getting results as expected.

    As we want to save the data into flash whenever there is power failure condition will be occurs.

  • Had enable the global interrupts but still not getting results as expected.

    What do you mean by results? Is the VMON ISR getting called when the DVCC drops below the defined level?

    As we want to save the data into flash whenever there is power failure condition will be occurs.

    That's a different topic and can be addressed later after the VMON ISR is working correctly. Let's focus on that for now.

  • yes VMON ISR got call whenever DVCC drops below defined level.As we tried with hardcoded values ,they are getting saved in the memory whenever VMON ISR Called.

    But as we tried with live data to be saved then it is not working.

  • yes VMON ISR got call whenever DVCC drops below defined level.

    So your VMON functionality is working correctly. That's good and should address the main question of this thread.

    As we tried with hardcoded values ,they are getting saved in the memory whenever VMON ISR Called.

    But as we tried with live data to be saved then it is not working.

    This is slightly off topic from the original question. I don't understand why the dummy data gets written and live data doesn't. They should be the same type and should work the same. What do you mean "it is not working"? Does that mean the live data does not get written to Flash but the dummy (hardcoded) values are written to Flash?

    Additional comments:

    • Modify the linker file to have a dedicated segment in main (not info) memory for storing these values. After reading the stored values, that segment should be erased to prepare for the write in VMON ISR.
    • Use the highest VCC trip level (3) to have more time to back up values. Consider using an external voltage divider to trigger VMON earlier than the internal trip level to give yourself more time.
    • Make sure the Flash controller is running as fast as possible (but less than max) to minimize write time in VMON ISR to ensure all data gets written before power loss.

    Here is some pseudo code for writing values in RAM to Flash in VMON ISR:

    /* Check for Flash Access */
    while (FCTL3 & BUSY);
    
    /* Write Energy Values in RAM to Backup Memory Segment in Flash */
    FCTL3 = FWKEY;                                          // Clear LOCK bit
    FCTL1 = FWKEY | WRT;		                            // Set WRT bit for write
    *ACTIVE_POWER_BACKUP_ptr = active_power_working;        // 32-bit value
    *REACTIVE_POWER_BACKUP_ptr = reactive_power_working;    // 32-bit value
    *APPARENT_POWER_BACKUP_ptr = apparent_power_working;    // 32-bit value
    *ENERGY_RESIDUAL_BACKUP_ptr = energy_residual_working;  // 32-bit value
    
    /* Trap for Power Loss */  
    while(1)
    {
      __no_operation();
    }

  • Hello,

    Actually what we observed that ISR get called on PowerON condition which is expected to be called on PowerOff condition .

    For this we have increased this delay cycles to 1000000 which ~.5sec & now when there is poweroff condition but ISR not getting called.

    i.e.// When started up, VMON requires a settling time of 0.5us
    // MCLK = ~16MHz; 1 cycle = ~0.0625us
    __delay_cycles(1000000);

    So please guide us what could be the problem for this.

  • Actually what we observed that ISR get called on PowerON condition which is expected to be called on PowerOff condition .

    Keep in mind that the device will start executing code after the brownout reset (BOR) is released by BORH and SVSL during power on (see Figure 3-2 in the user's guide). The device can safely execute code when VCC is at least 2.2V. Thus, if the VMON is enabled (e.g. 2.8-V) before your supply voltage reaches a value greater than the limit (e.g. 3.0-V) defined for VMON, the VMON ISR will be triggered. If you're using a custom board and are following the recommended capacitor ratio of 10 for CVCC to CVCORE, you can measure how long the supply voltage takes to reach a threshold higher than the VMON level for VCC and wait that long before enabling VMON in your code.

    Also, make sure you're including the 'low_level_init.c' file in your CCS project for the MSP430i2041. If you import a code example from Resource Explorer, it should automatically import that file too.

  • Part Number: MSP430I2041

    Hello,

    We have used sample code pmm_ex2_vmon1160mV .

    Edited for DVCC  for the level 2.850V as below,

    Original code-----------------

    PMM_setupVoltageMonitor(PMM_VMONIN_1160MV);

    __delay_cycles(10);

    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2,GPIO_PIN3,GPIO_TERNARY_MODULE_FUNCTION);

    PMM_enableInterrupt(PMM_VMON_INTERRUPT);

    Edited one--------------------

    PMM_setupVoltageMonitor(PMM_DVCC_2850MV);

    __delay_cycles(10);

    //GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2,GPIO_PIN3,GPIO_TERNARY_MODULE_FUNCTION); //not used as not using external voltage

    PMM_enableInterrupt(PMM_VMON_INTERRUPT);

    P2.3 pin is NC.

    In interrupt routine saving data to flash.

    But this code is not working. Not saving data to flash in ISR.(Flash save function tested separately, its working) Not entering in ISR.

    Did I missed something in code?

    Anuradha.

  • Hi Anuradha,

    I've merged your thread with this one because it's the same topic. Please see my recommendations above.

  • Hi James,

    We are both are working on the same project and facing this issue since long back.

    I have checked your all recommendations already.

    Please check the above code for DVCC enable for VMONIN and suggest corrective action if needed.

    Or please suggest sample code for DVCC mode.

    Our basic query is if we are using DVCC no need to connect external ckt for ref vtg. correct? (Ashwini has asked it before but not answered)

    Please help us to run this feature successfully.

    Thanks,

    Anuradha.

  • Hi Anuradha,

    We are both are working on the same project and facing this issue since long back.

    Earlier in this thread, Ashwini confirmed that the VMON ISR was getting triggered correctly when DVCC dropped below the selected threshold. This issue should be resolved already. Have you discussed this together?

    Please check the above code for DVCC enable for VMONIN and suggest corrective action if needed.

    Or please suggest sample code for DVCC mode.

    You are already using the only DriverLib VMON code example, 'pmm_ex2_vmon1160mV.c'. To use DVCC mode, change the VMONLVLx bits in the VMONCTL register and remove the configuration for P2.3 as the VMONIN pin. These are fairly simple changes and the example is not that complex. Using the code example and an adjustable power supply, you should be able to easily test it. The LED provides simple visual feedback on the VMON status.

    There are other non-DriverLib register-level VMON code examples that you can leverage such as 'msp430i20xx_pmm_03.c'.

    Our basic query is if we are using DVCC no need to connect external ckt for ref vtg. correct? (Ashwini has asked it before but not answered)

    Please help us to run this feature successfully.

    Ashwini mentioned going through the user's guide, and it is clear about this functionality. It describes how VMON monitors the "on-chip DVCC to a specified limit". "On-chip" means no external circuitry is required.

  • --No it was not that  VMON ISR was getting triggered correctly when DVCC dropped below the selected threshold. Actually during power ON VMON ISR was triggering and she assumed it was during power OFF. (for saving values in flash during power off)

    --At power up we have increased delay and now at the time of power up not triggering but not at power off as well. ( we are writing  flash data in ISR and in next power on reading the same from flash but no expected result)

    --Yes, the code is simple but seems not working for power off condition. We have selected DVCC mode and varying the vcc supply vtg from 3.3 to 2.5V keeping VMON triggering vtg 2.85V. It is working as it is simple to demonstrate by varying the potentiometer. But our real application is to save data during power off condition. Not by gradually varying supply vtg, in sudden power off condition (happen within microseconds). Here we are not getting expected result.

    Please suggest possible solution.

    Thanks 

    Anuradha.

  • It sounds like the VMON functionality is working but you don't have enough time to write to Flash memory on the way down during a power loss. I would recommend confirming the VMON functionality by turning on a LED or driving a GPIO high at the beginning of the VMON ISR. Then, you could disable interrupts and enter an endless while() loop until power is lost.

    For the next debug step, I would measure how long it takes your code to write to Flash by toggling a GPIO and capturing the time on with a logic analyzer. Then, measure how long the GPIO stays high in the VMON ISR. If you need more time, consider increasing the capacitance on DVCC to slow down the rate of power loss.

    Try these recommendations and try to narrow down what specifically is working and is not working.

  • Hello James,

    Thanks for these suggestions. We will try on these debugging steps.

    Anuradha.

  • Great. I hope that helps you narrow down what is and isn't working.

**Attention** This is a public forum