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.

Watch dog timer problem

Other Parts Discussed in Thread: MSP430G2231, MSP430G2211

Dears,

I have generated some sample code for watch dog timer.

In my program I have enabled 21Mhz SMCLK which generates 100KHz PWM with TACCR0 interrupt.

I tried to generate a watch dog interval timer interrupt for 32ms. But when I loaded the program to MSP430G2231 using Launch pad the program loaded for once but I doesn't worked and after that I cannot load program to the device. The launch pad is working as I programmed the MSP430G2211 device sample with other program. I have only one MSP430G2231 device and  It is now, not able to reload the program. I have attached the program which I loaded to MSP430G223

 

#include <msp430g2231.h>

 

volatile unsigned char   heart_beat = 0, loop_count = 0;

unsigned int      i = 0, Duty = 0, count = 0;

 

void task(void);

void init_pwm(void);

void entry_point(void);

 

void main(void)

{

                DCOCTL = 0xE0;

                BCSCTL1 = 0xCF;

                for (i = 0; i < 0xfffe; i++); 

                P1SEL = 0x44;

               P1DIR |= 0x45;

                init_pwm();

                while(1)

                {

                                while(!heart_beat);

                                switch(loop_count)

                                {

                                                case 0:  entry_point();

break;

                                                case 1:  task();

                                                                break;                  

                                                default:break;

                                }             

                                heart_beat = 0;

                }

}

 

void init_pwm(void)

{

                TACCTL0 = CCIE;

                TACCTL1 = OUTMOD_7;

                TACCR0 = 210;                                                                  

                TACTL = TASSEL_2 + MC_1; 

                _BIS_SR(GIE);

}

 

void entry_point(void)

{

                WDTCTL = WDT_MDLY_32; 

                IE1 |= WDTIE;

                _BIS_SR(LPM4_bits + GIE);

}

               

void task(void)

{

                count++;                             

                if(count > 25000)

                {

                                Duty++;

                                count = 0;

                }

                if(Duty > 200)

                                Duty = 1;

}

               

// Timer A0 interrupt service routine

#pragma vector=TIMERA0_VECTOR

__interrupt void Timer_A (void)

{

                if(heart_beat)

                {

                                while(1)

                                {

                                                P1OUT |= 0x01;

                                }

                }             

               

                TACCR1 = Duty;

                heart_beat = 1;

}

 

// Watchdog Timer interrupt service routine

#pragma vector=WDT_VECTOR

__interrupt void watchdog_timer(void)

{

  P1OUT ^= 0x01;

}

 

 

 Kindly help me to identify what is the problem in my program. I amvery new to TI. So please help me.

With best regards

 Yasin JI

 

  • Yasin J.I. said:
    WDTCTL = WDT_MDLY_32; 

    This could be the reason. I'm not sure whether this define contains the WDT password. If not, this line will cause a device reset.

    Since the G devices don't have a BSL and your code doesn't use many initialized variables, the delay between processor start and hitting this instruction might be too small to allow the programming software to attach to the MSP, resulting in an inaccessible (because constantly resetting) MSP.

     

    There are other issues:

    When initializing the timer, you set the trigger to a timer value of 210. Yet you doN't clear the timer before, so it may well be that you're already near the 210 ticks and the interrupt comes almost instantly.

    Yasin J.I. said:
    for (i = 0; i < 0xfffe; i++); 

    Normally, this should provide enough time so teh JTAG can connect. But unfortunately, the compilers for the MSP do some optimization to make code slimmer and faster. And since ypu don't use i inside thsi loop, the compiler may replace this whole loop with an i=0xFFFE assignment, or, since you don't use i ever after, it may discard the loop completely.
    Use __delay_cycles() instead.

    Also, there is a deadlock condition in your code (I'm not sure whether this is intentional): main() waits until heart_beat is 1, then it calls entry_Point(), where it goes into LPM4. LPM4 might disable the clocks needed for fiurther time roperation (I haven't checked). But even if the clocks are still active, the next timer interrupt will enter an endless loop, toggling the port pin with >100kHz (@1MHz system clock) forever. heart_beat is never reset, loop_count is not incremented anywhere.

     

    About how to possibly revive the MSP, see here

**Attention** This is a public forum