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.

Basic Timed Interrupt



I was looking into the code that is provided to create an interrupt based on time.  I have a MSP430FG6418 chip on an experimenter's board.

This is the code im trying to understand  as of right now:

---------------------------------------------------------

#include  <msp430xG46x.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  FLL_CTL0 |= XCAP18PF;                     // Set load cap for 32k xtal
  P5DIR |= 0x02;                            // Set P5.1 as output
  BTCTL = BTDIV + BT_fCLK2_DIV16;           // ACLK/(256*16)
  IE2 |= BTIE;                              // Enable BT interrupt

  _BIS_SR(LPM3_bits + GIE);                 // Enter LPM3, enable interrupts
}

// Basic Timer Interrupt Service Routine
#pragma vector=BASICTIMER_VECTOR
__interrupt void basic_timer_ISR(void)
{
  P5OUT ^= 0x02;                            // Toggle P5.1
}

---------------------------------------------------------

 

The thing is, i really dont understand how to set the interrupt time itself. My guess is:

BTCTL = BTDIV + BT_fCLK2_DIV16;

But i really dont know what BTDIV or BT_fCLK2_DIV16 are. I tried just putting numbers and i managed to changed the frequency of the toggling by directly assigning a value like this:

BTCTL = 300

But I still dont understand how it works, and when i use any value below 300 or above 3000 the led will not turn on at all...

Im new to this, and i  know its something simple, but I really cannot understand this. All I want is a simple way to say "every x seconds, cause interrupt"

 

thanks for any help yall can provide

  • You should take a look at the 4xx family users guide slau056j.pdf. The section about the basic timer explains the usage of the registers.
    I consider this an RTFM question.

    Anyway, here's a short explanation:

    Most MSP hardware module registers (except those for a data transfer) are combined bitfields.
    In this case, the BTCTL register contains 5 different settings:
    - Bit 6 (BTHOLD) holds the timer.
    - Bit 5+7 (BTSSEL+BTDIV) select teh clock source for the timer. In your case ACLK/256
    - Bit 3+4 (BZFRQx) determine the LCD update frequency and
    - Bit 0-2 (BTIPx) set the timer unterrupt interval. BT_fCLK2_DIV16 means one interrupt each 16th timer tick. In your case (with an ACLK of 32768Hz) the interrupt comes with (32768/(256*16))= 8 Hz.

    This means, not setting the BTDIV bit will speed up the blink frequency by 256 (too fast for the eye) while using BT_fCLK_DIV2/4/8 will speed it up by a factor of 8/4/2 while using BT_fCLK_DIV32/53/238/256 will slow it down accordingly.

  • Thank you  for taking the time to help  me out. I understand it now.

    I dont mind reading manuals, I really did no know which one contained information pertinent to my device. I will definitely refer to it from now on.

    Thanks again for the big help.

  • chris c said:
    I dont mind reading manuals, I really did no know which one contained information pertinent to my device.


    Well, for a beginner the TI way to do it isn't that obvious. Yet it is a way to avoid duplicate information, as the MSPs are build in a very modular way.

    Usually, you need three documents: the device datasheet, the errata sheet (if any) and the family users guide.

    The users guide contains informations about the modules availbale in any or all devices of a family. This includes general description, detailed functionality (sometimes too detailed, sometimes not enough), program flow diagrams, sometime sshort examples and a complete description of a modules registers and functionality.
    Sometimes, modules are working together (such as the clock module and the timers/uarts, or the DMA), so sometimes you'll find the critical hint at a different location than expected. So it's important to read through the more general parts of the users guide. This includes the sections about the CPU (even if you don't want to program in assembly) and the clock module. Even the introduction may hold some valuable information that is not repeated afterwards.

    The device datasheet tells the pinout of one or more members of a family, the modules they contain, the exact addresses where the modules' registers are located, the electrical specifications and all other device-dependent informations. Besides the pinout and the maximum values (voltages, frequencies), most of this informations is so specific that you normally don't need it. Yet sometimes there are important informations about e.g. the meaning of certain register settings, if these differ from device to device (usually, the users guide then refers to the device datasheet, but not always)

    The errata sheet contains a list of known silicon bugs (things that are not working as intended and differ from the users guide) along with workarounds. There are usually only a few and some of them very specific, so you never encoutner them. But it's good to browse through them once, so you'll remember them when you are stuck with some unexpainable behaviour.

    If you still encounter problems, then look for an updated document. No datasheet is perfect until its obsolete :) And TI updates often.

  • Jens-Michael - your last post is quite helpful.  I'd suggest inserting something of this nature on the "Read Me First" document we get in the experiementing kit.  I also didn't know I needed to find a slau208h.pdg to figure out what I'm trying to do.  Thanks.

    GP

  • Indeed, a 'read me first' document that explains the basic structure of the TI documentation and appnodes (including the weird naming) would be helpful.
    It should be linked on a prominent place right at top of every product page.

**Attention** This is a public forum