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.

How to implement timeout timer functionality in MSP430F2370

Other Parts Discussed in Thread: MSP430F2370, TRF7960

Hello,

I am new to this controller. I am using TRF7960 module that has MSP430F2370 Controller. I want to implement timeout timer of 1milli second. Someone suggest me how to implement  this. I am using default TRF7960 Stack given by TI .

Ashi

  • Use some reference codes available on TI website for MSP430F2370.

    you will have to use one of the available timers -> load the count -> start the timer -> timer interrupt is generated.

    The count will be the number of clock cycles of the clock used by the timer module.

  • Hi Chethu Gowda,


    This is the file included in Stack. I am not able to understand how to use these default apis given by TI. They are using these apis in finding RFID tags UID.

    //===============================================================

    extern u08_t i_reg;
    extern u08_t irq_flag,flag;

    //===============================================================
    // NAME: void Msp430f23x0DileyMillisecond (u08_t n_ms)
    //
    // BRIEF: Is used to create delays.
    //
    // INPUTS:
    // Parameters:
    // u08_t n_ms delay time in ms
    //
    // OUTPUTS:
    //
    // PROCESS: [1] do loop of 1 ms duration as often as required
    //
    // CHANGE:
    // DATE WHO DETAIL
    // 23Nov2010 RP Original Code
    //===============================================================

    void
    Msp430f23x0DelayMillisecond(u32_t n_ms)
    {
    while (n_ms--)
    {
    __delay_cycles(DELAY_1ms); // clock speed in Hz divined by 1000
    }
    }

    //===============================================================
    // NAME: void Msp430f23x0CounterSet (void)
    //
    // BRIEF: Is used to set the timerA.
    //
    // INPUTS:
    //
    // OUTPUTS:
    //
    // PROCESS: [1] set timerA
    //
    // CHANGE:
    // DATE WHO DETAIL
    // 23Nov2010 RP Original Code
    //===============================================================

    void
    Msp430f23x0CounterSet(void)
    {
    TACTL |= TACLR;
    TACTL &= ~TACLR; // reset the timerA
    TACTL |= TASSEL0 + ID1 + ID0; // ACLK, div 8, interrupt enable, timer stopped

    TAR = 0x0000;
    TACCTL0 |= CCIE; // compare interrupt enable

    }

    //===============================================================
    // NAME: void Msp430f23x0OscSel (u08_t mode)
    //
    // BRIEF: Is used to select the oscilator.
    //
    // INPUTS:
    // Parameters:
    // u08_t mode crystal oscillator or DCO for
    // main clock
    //
    // OUTPUTS:
    //
    // PROCESS: [1] select the oscilator
    //
    // CHANGE:
    // DATE WHO DETAIL
    // 23Nov2010 RP Original Code
    //===============================================================

    void
    Msp430f23x0OscSel(u08_t mode)
    {

    u08_t ii1 = 0;

    if (mode == 0x00) // select crystal oscilator
    {
    BCSCTL1 |= XTS + XT2OFF; // ACLK = LFXT1 HF XTAL
    BCSCTL3 |= LFXT1S1; // 3 – 16MHz crystal or resonator
    // the TRF796x sys_clk pin works as ocillator
    // it is set to 6.78 MHz (= 13.56 MHz / 2) in Trf797xInitialSettings()
    // turn external oscillator on
    do
    {
    IFG1 &= ~OFIFG; // Clear OSCFault flag
    for (ii1 = 0xFF; ii1 > 0; ii1--) // Time delay for flag to set
    {
    }
    } while ((IFG1 & OFIFG) == OFIFG); // OSCFault flag still set?

    BCSCTL2 |= SELM1 + SELM0 + SELS; // MCLK = SMCLK = HF LFXT1 (safe)

    return;
    } // end of IF case

    else //select DCO for main clock
    {
    DCOCTL |= DCO0 + DCO1 + DCO2;
    BCSCTL1 |= XT2OFF + XTS + RSEL0 + RSEL1 + RSEL2;

    BCSCTL2 &= ~(SELM1 + SELM0 + SELS + DCOR);

    return;
    }
    //_BIC_SR(OSCOFF);
    }

    //===============================================================
    // NAME: void Msp430f23x0TimerAHandler (void)
    //
    // BRIEF: Is used to handle the interrupts generated by timerA.
    //
    // INPUTS:
    //
    // OUTPUTS:
    // Globals:
    // u08_t i_reg indicates TIMEOUTs
    //
    //
    // PROCESS: [1] handle the interrupts generated by timerA
    //
    // CHANGE:
    // DATE WHO DETAIL
    // 23Nov2010 RP Original Code
    //===============================================================

    #pragma vector=TIMERA0_VECTOR
    __interrupt void
    Msp430f23x0TimerAHandler(void)
    {
    u08_t irq_status[4];

    STOP_COUNTER;

    irq_flag = 0x03;

    Trf797xReadIrqStatus(irq_status);

    *irq_status = *irq_status & 0xF7; // set the parity flag to 0

    if(*irq_status == 0x00 || *irq_status == 0x80)
    {
    i_reg = 0x00; // timer interrupt
    }
    else
    {
    i_reg = 0x01;
    }
    if(flag==1)
    {
    flag=2;
    }
    //__low_power_mode_off_on_exit();
    }

    //========================================================================================

    I am doing this to get a timeout of 100ms, but still unsuccessful.

    McuCounterSet(); //set timer A
    //COUNT_VALUE = COUNT_1ms * 10; // for 4 ms TIMEOUT
    TACCR0 = 2000;
    START_COUNTER; // start timer up mode

    where: 

    #define COUNT_VALUE TACCR0 //counter register
    // #define START_COUNTER TACTL |= MC0 + MC1 //start counter in up/down mode
    #define START_COUNTER TACTL |= MC1 //start counter in up mode

    #define STOP_COUNTER TACTL &= ~(MC0 + MC1) //stops the counter

    //---------------------------------------------------------------

    #define COUNT_1ms 847
    #define COUNT_60ms 0xC684

    Ashi

  • Ashi Gupta said:
    am doing this to get a timeout of 100ms, but still unsuccessful.

    unsuccessful in getting interrupt or getting exact delay of 100ms.

    Ashi Gupta said:
    McuCounterSet(); //set timer A
    //COUNT_VALUE = COUNT_1ms * 10; // for 4 ms TIMEOUT
    TACCR0 = 2000;
    START_COUNTER; // start timer up mode

    This part looks OK.

    Ashi Gupta said:
    TACCR0 = 2000;

    but this value should give u delay of 500ms.

  • Ashi Gupta said:
    I am not able to understand how to use these default apis given by TI. They are using these apis in finding RFID tags UID.

    These ar enot really APIs but simple standard funcitons dealign with the timer. And they don't have anything specifically to do with RFID, except of the call to Trf797xReadIrqStatus(irq_status); in the timer ISR.
    And the funcitons contain excellent and exhaustive comments (unusual for TI demo code).
    However, there are soem superfluous code lines and also a potential bug:

    extern u08_t irq_flag,flag; needs to read extern volatile u08_t irq_flag.

    Now about your delay. Yes, you program the timer and start it. You also need to clear the 'timer expired' or 'timeout' bit in irq_flag. When the timeout expired, irq_flag will suddenly ad magically contain the timout bit set,a s teh ISR will set it.

    After starting the timeout, you begin your operation that might timeout. YOu loop until you either are done (in which case you stop the timeout) or unil the timeout bit is suddenly set in irq_flag, which indicates that the timeout has expired. In which case you bail out of your current operation.

  • Thanku..problem resolved with this help.

    Ashi

**Attention** This is a public forum