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.

2 minutes of delay needed.

Other Parts Discussed in Thread: MSP430G2231, MSP430WARE

Hi,

 Please send me example code for MSP430G2231 to generate 2 minutes of delay.

Ex; The micro reads an input in say analog pin1. I need a code that execute high on other pin after 2 minutes have expired.

Thanks,

Sanjay

  • You will probably want to use a TIMER_A module to do this. With a 32,768 Xtal input, you can get up to 16-second delay with Timer_A by selecting the correct input divider and timer count value.

    You can download the sample code from TI website (I think MSP430Ware includes it) and look at the G2xxx samples provided, and adapt for your needs yourself. If you have specific questions about your implementation than you can ask those. Be mindful that we are not here to do your homework for you.
  • You can also use __delay_cycles(1000 * Freq_In_Mhz) to generate 1 millisecond delay.

    Suppose you are running CPU at 8 MHz then code will be

    #define CONTROLLER_FREQ                      8                    // 8 MHz

    #define DELAY_NO_OF_SECOND             60 * 2           // 2 Minutes

    long i = 0;

    for(i=0; i < (DELAY_NO_OF_SECOND*1000); i++)

    {

     __delay_cycles(1000 * 8);

    }

  • You certainly can, if this is just a "demonstration" project. The processor can't do anything else in the meantime, so in normal "real-world" design, that is not good practice nor recommended design.
  • No Crystal:

    Use 1MHz dco, smclk div-by-8, timer div-by-8
    1'000'000 /8 /8 =  15625 ticks a second

    (max in a 16bit) 65535 /15625 = 4.19424
    rounded down, the slowest you can get is 4 seconds.

    So make the timer irq  count down a counter that starts at 30, and when it reaches 0 wake-up main with:

    __bic_SR_register_on_exit(LPM0_bits);

    P.S alternative is to use WDT, as it's 15bit slowest you can get is 2sec but is easier to set up.

**Attention** This is a public forum