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.

LOW_POWER_MODE

Other Parts Discussed in Thread: MSP430F2002, MSP430F2012

Good Day

Hi I have a question is the following

In CCS'm doing a practice which involves making a zero crossing detector to detect when the sine wave crosses zero network and additionally I put a supercapacitor or a battery to that when no mains voltage into low power mode and last toggle a pin for at least 1 hour.

I put the WDT as timer for about one second and if it finds that there is no zero crossing in 1 second then goes into low power mode.

But when I test the microcontroller takes 10 seconds and is as if it will reset and go back to doing nothing

My question is how do the test in a correct way?

Thanks

unsigned int wdtCounter = 0;
void main(void){
    WDTCTL = WDT_MDLY_32;        // Watchdog Timer interval to ≈32ms
    IE1 |= WDTIE;                // Enable WDT interrupt
    P1DIR |= BIT4;               // Set P1.0 to output direction
    P1OUT |= BIT0;               // Turn on LED at 1.0
    P1IE |= BIT3;                // Enable P1.3 interrupt
    P1DIR &= ~BIT3;              // Port 1 P1.3 (push button) as input = 0              // Enable P1.3 pull-up resistor
    P1IFG &= ~0x08;              // clear P1.3 interrupt flag
    _BIS_SR(GIE);                // Enable interrupts
    while(1);
}
#pragma vector=WDT_VECTOR         // Watchdog Timer interrupt service routine
    __interrupt void watchdog_timer(void) {
    if(wdtCounter == 32){        // 249 * 32 ms = 7968 ms, ≈ 8 s
        P1OUT ^= BIT4;           // P1.0 turn off, red LED
        wdtCounter = 0;
        _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/interrupt
    }
    else
        wdtCounter++;
}
#pragma vector=PORT1_VECTOR       // Port 1 interrupt service routine
  __interrupt void Port_1(void) {
    wdtCounter = 0;               // reset watchdog timer counter
               // turn red LED on
    P1IFG &= ~BIT3;               // clear P1.3 interrupt flag
    _BIC_SR(LPM0_EXIT);           // wake up from low power mode
}
  • Hello

    Turns out I is generating a reset for MSP430F2002 pin 10 that is pin RST / NMI put him to work as NMI but I consuming LPM0_bits voltage mode, then not as deshabillitar that pin or put it so not generate the interruption by the reset because if I connect this pin to the battery, the battery will discharge very quickly.

    I appreciate the help wanted me to give

    thanks

  • Hi David, did you resolve the problem already?

    I was looking at your code and spotted a few things that might cause it to go wrong.

    At the end of the Port_1 ISR you have _BIC_SR(LPM0_EXIT);, which I think should just be LPM0_EXIT; or alternatively _BIC_SR_IRQ(LPM0_bits);.

    You have a comment // Enable P1.3 pull-up resistor but the code to do that (P1REN |= BIT3;) is missing, so there's no pullup.

    The line _BIS_SR(LPM0_bits + GIE); puts the MSP to sleep inside the watchdog_timer ISR and enables interrupts. The ISR never returns and the next ISR call is nested. The result is that if Port_1 ISR doesn't happen, then the stack grows every second as return address and status register are pushed but not popped. Eventually that will stomp over something important in memory or exhaust memory completely. Try _BIS_SR_IRQ(LPM0_bits); instead, which will make the CPU enter LPM0 after returning from the ISR.

  • Gracias por su respuesta!!
    Pero la deteccion del cruce por cero si la esta haciendo porque esta conectado a la red de 120Vac le hice un divisor de tension y limito la tension con un zener de 3.6V y le envio la señal de cruce por cero y la esta reconociendo pero me di cuenta de que el error esta en el pin 10 del reset porque cuando no hay tension disponible de la red el VCC es cero pero si conecto ese pin a la pila, la pila se descarga en 4 minutos lo cual es muy rapido y si lo pongo como NMI es pin la pila se agota pero dura mas 
    Mi pregunta es el PIN 10 de msp430f2012 que es el pin de RST/NMI se puede configurar de alguna forma para que no resete el microcontrador y dure mas tiempo la pila?
    unsigned int wdtCounter = 0;
    void main(void){
        WDTCTL = WDT_MDLY_32;        // Watchdog Timer interval to ≈32ms
        IE1 |= WDTIE;                // Enable WDT interrupt
        P1DIR |= BIT4;               // Set P1.4 to output direction
        P1OUT |= BIT0;               // Turn on LED at 1.0
        P1IE |= BIT3;                // Enable P1.3 interrupt
        P1DIR &= ~BIT3;              // Port 1 P1.3 (push button) as input = 0            
        P1IFG &= ~0x08;              // clear P1.3 interrupt flag
        _BIS_SR(GIE);                // Enable interrupts
        while(1);
    }
    #pragma vector=WDT_VECTOR         // Watchdog Timer interrupt service routine
        __interrupt void watchdog_timer(void) {
        if(wdtCounter == 32){        // 32 * 32 ms = 1024 ms, ≈ 1 s
            P1OUT ^= BIT4;           // P1.0 turn off, red LED
            wdtCounter = 0;
            _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/interrupt
        }
        else
            wdtCounter++;
    }
    #pragma vector=PORT1_VECTOR       // Port 1 interrupt service routine
      __interrupt void Port_1(void) {
        wdtCounter = 0;               // reset watchdog timer counter
                   // turn red LED on
        P1IFG &= ~BIT3;               // clear P1.3 interrupt flag
        _BIC_SR(LPM0_EXIT);           // wake up from low power mode
    }
  • Thanks For Your Answer!
    But the zero-crossing detection if the portion doing this BECAUSE THIS Connected 120Vac network without divider I will stress and tension I limit con un 3.6V zener and costs The zero crossing signal and this portion recognizing But I realized that the error is not in the reset pin 10 BECAUSE WHEN No network available voltage VCC is zero ESE But if I connect pin to the battery, the battery itself in 4 Minutes Download the what is very fast and if I put it pin NMI Como itself Stack exhausting but lasts longer
    My question is PIN 10 msp430f2012 That is pin RST / NMI can Set To Any way resete What's the Time microcontrador and battery last longer?

    unsigned int wdtCounter = 0;
    void main (void) {
        WDTCTL = WDT_MDLY_32 / / Watchdog Timer intervalo de ≈ 32 ms
        IE1 | = WDTIE / / Habilitar la interrupción WDT
        P1DIR | = BIT4 / / Set P1.4 a la dirección de salida
        P1OUT | = BIT0 / / Activar el LED en el 1,0
        P1IE | = Bit3 / / Habilitar P1.3 interrupción
        P1DIR & = ~ Bit3 / / Puerto 1 P1.3 (pulsador) como entrada = 0            
        P1IFG & = ~ 0x08; / ​​/ P1.3 claro indicador de interrupción
        _BIS_SR (GIE) / / Habilitar las interrupciones
        mientras que (1);
    }
    # Pragma vector = WDT_VECTOR / Timer rutina de servicio de interrupción / Watchdog
        __interrupt void watchdog_timer (void) {
        if (wdtCounter == 32) {/ / 32 * 32 ms = 1024 ms, ≈ 1 s
            P1OUT ^ = BIT4 / / P1.0 desvío, LED rojo
            wdtCounter = 0;
            _BIS_SR (LPM0_bits + GIE); / / Introducir LPM0 w / interrumpir
        }
        más
            wdtCounter + +;
    }
    # Pragma vector = PORT1_VECTOR / / Puerto 1 rutina de servicio de interrupción
      __interrupt void Port_1 (void) {
        wdtCounter = 0; contador del temporizador watchdog / / reset
                   / / Enciende el LED rojo
        P1IFG & = ~ Bit3 / / P1.3 claro indicador de interrupción
        _BIC_SR (LPM0_EXIT); / / despierta del modo de bajo consumo
    }
  • David Ramirez said:
        mientras que (1);

    you shouldn't try to run a hujman language translator over a computer source code :)

    Your concept is wrong. If your main code doesn't do anything, you simply go into LPM in main isntead of using a busy.waiting endless while loop.
    To have a fast wakeup, you may enter LPM0 only.

    When your timeout expires, you can enter a deeper LPM by setting additional LPM bits.

    [void main(void){

    [...]
      _BIS_SR(GIE);                // Enable interrupts
        while(1);
       _BIS_SR(LPM0_bits|GIE); // processor stops here until interrupt. All Clocks are still running. But main() won't continue.
    }
    #pragma vector=WDT_VECTOR         // Watchdog Timer interrupt service routine
        __interrupt void watchdog_timer(void) {
    [...]
            _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/interrupt
            _BIS_SR_IRQ(LPM4_bits); // switch off all clocks for maximum power saving
    [...]
    }
    #pragma vector=PORT1_VECTOR       // Port 1 interrupt service routine
      __interrupt void Port_1(void) {
    [...]
        _BIC_SR(LPM0_EXIT);           // wake up from low power mode
        _BIC_SR_IRQ(LPM4_bits);    // exit LPM4 when the ISR exits (re-enable the clocks)
        _BIS_SR_IRQ(LPM0_bits);    // but enter LPM0 instead. (main() will still be frozen, but further interrupts will happen faster. Those two liens are of no effect if you are already in LPM0 and the timer hasn't expired yet.
    }
    This LPM0/LPM4 tango has to be changed if your applicaiton wants to do something in main() between the interrupts. But for the current applicaiton, it should provide maximum pover-effectivity.
    Don't forget that your (unknown to me) external circuitry that generates the port pin interrupt, may still draw significant power.
  • I mean when I'm in an interruption I have to use _BIS_SR_IRQ (LPM4_bits) instead of _BIS_SR (LPM4_bits);

    My question is what is the difference between _BIS_SR_IRQ (LPM4_bits) and _BIS_SR (LPM4_bits);

    thanks

  • When an interrupt occurs the current status register (SR) value gets pushed onto the stack. Returning from the interrupt service routine restores the SR to the saved value on the stack. _BIS_SR_IRQ (LPM4_bits) sets the LPM4_bits in this saved copy on the stack. When the ISR returns the saved value is copied into SR and the CPU goes to sleep (LPM4) after the ISR has finished.

    _BIS_SR (LPM4_bits) sets the status register directly and puts the CPU to sleep right away.

  • I have one last question is on the RST pin which is connected to a resistor to Vcc 47Komh if put in ultra low power mode and connect the battery resistance to the microcontroller not resete, that pin may consume a considerable stream draining the battery or place it as NMI?

    Thanks for your answers.

  • David Ramirez said:
    that pin may consume a considerable stream draining the battery or place it as NMI?

    Where should it go? Not into the pin (maximum pin input leakage current is 50nA)
    And the also present 100nF (or less) capacitor should be of ceramic type and have a very low leakage current too.

    The only current through this pin is when the capacitor is discharged and power is turned on. Then the capacitor will short th eresistor to GND and keep RST low for some time, until the capacitor has charged.

    BTW: almost all 5x /6x family MSPs already have an internal pullup resistor on RST. TH e5438(non-A) is an exception where this pullup is off by default.

  • Thanks for all your replies

    What happens is that LPM_3 mode first have to put the subroutine and then the low power mode so the supercap voltage and consume very little lasts a long time compared to other microcontrollers thank you very much!

**Attention** This is a public forum