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.

Needed clarification with the Timer Interrupt service notation

Other Parts Discussed in Thread: CC430F5137, CC430F6137


I am confused with the Timer_ISR representation.The below two are the examples of cc430f5137 included int he TI_explorer

#include <msp430.h>

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // P1.0 output
TA1CCTL0 = CCIE; // CCR0 interrupt enabled
TA1CCR0 = 50000;
TA1CTL = TASSEL_2 + MC_1 + TACLR; // SMCLK, upmode, clear TAR

__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts
__no_operation(); // For debugger
}

// Timer A0 interrupt service routine
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
P1OUT ^= 0x01; // Toggle P1.0
}

In the above what does this line represent or used for TIMER1_A0. for what Timer1 is used and A0 is used.

#include <msp430.h>

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P1DIR |= 0x01;                            // P1.0 output
  TA1CTL = TASSEL_2 + MC_2 + TACLR + TAIE;  // SMCLK, contmode, clear TAR
                                            // enable interrupt

  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, enable interrupts
  __no_operation();                         // For debugger
}

// Timer_A3 Interrupt Vector (TAIV) handler
#pragma vector=TIMER1_A1_VECTOR
__interrupt void TIMER1_A1_ISR(void)
{
  switch(__even_in_range(TA1IV,14))
  {
    case  0: break;                          // No interrupt
    case  2: break;                          // CCR1 not used
    case  4: break;                          // CCR2 not used
    case  6: break;                          // reserved
    case  8: break;                          // reserved
    case 10: break;                          // reserved
    case 12: break;                          // reserved
    case 14: P1OUT ^= 0x01;                  // overflow
             break;
    default: break; 
  }
}

Here the what does thes lines represents or denotes.what is the use of them

1)Timer_A3 Interrupt Vector (TAIV) handler

2)TIMER1_A1_


As I am not sure of what will be correct to use instead of my timer_ISR lines shown below for my reuired code

1) #pragma vector=TIMER0_A0_VECTOR
   __interrupt void TIMER0_A0_ISR(void)

2)#pragma vector=TIMER0_A0_VECTOR

__interrupt void Port_3(void)// P3SEL |= BIT2;

#include <msp430.h>
volatile int ccr_current=0,ccr_previous=0,y=0,freq1[3],freq=0,freq_needed=0;

//Timer Interrupt
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
{
 //__bic_SR_register_on_exit(CPUOFF);//wakes up CPU from OFF
}

#pragma vector=TIMER0_A0_VECTOR
__interrupt void Port_3(void)// P3SEL |= BIT2;
{
	unsigned int ccr_current;
	  ccr_current = TA0CCR1;
	  if(ccr_current < ccr_previous) {
	    freq = 32768 / (ccr_current + 65536 - ccr_previous);
	  } else {
	    freq = 32768 / (ccr_current - ccr_previous);
	  }
	  ccr_previous = ccr_current;
	y=y+1;
	freq1[y]=freq;
 //__bic_SR_register_on_exit(CPUOFF);//wakes up CPU from OFF
}

int main(void)
{
 WDTCTL = WDTPW | WDTHOLD;
//TA0CCR0: Reference clock
TA0CTL = TASSEL_1;
 TA0CCTL0 = CCIE; // interrupt enabled
TA0CCR0=32768;
TA0CTL |= MC_1;// set timer in up mode
TA0CTL |= MC0; // start timer
//TA0CCR1: It will read the input pulse signal
 P3SEL |= BIT2; //it is connected to TA0CCR1A
TA0CCTL1|=CAP; //for capture mode
TA0CCTL1|=CM_1; //capture on rising edge
 while(1)
 {
  if(y==2) //calculate freq if two rising edges were captured
     {
	    freq_needed=freq1[1]+freq1[2];
          //transmit freq_needed through UART to the terminal
          y=0;
      }
  __bis_SR_register(CPUOFF + GIE);//makes CPU OFF and enables interrupts
  }
}

can some one explain about the things.

Thanks.

  • I am not sure why you have an ISR that handles the timer interrupt and call it "Port3".

    You also have two ISRs for the same vector, which should give you a linker error.

    I would suggest you look at the datasheet for your device, specifically the "Peripherals" section. MSP430 comes in various flavors, some have multiple UARTs, some have multiple TIMERs etc. When there is more than one timer, they have to be named so as to be distinguishable from one another.

    TIMER_A is the type of timer, and the 0,1, etc is which one of the multiple TIMER_A peripherals you are accessing.

    As to the naming of the vector (in the pragma statement) you need to look at the system include file for your device (cc430f6137.h in your case) to see how the vectors are named:

    /************************************************************
    * Interrupt Vectors (offset from 0xFF80)
    ************************************************************/
    
    
    #define AES_VECTOR          (45 * 2u) /* 0xFFDA AES */
    #define RTC_VECTOR          (46 * 2u) /* 0xFFDC RTC */
    #define LCD_B_VECTOR        (47 * 2u) /* 0xFFDE LCD B */
    #define PORT2_VECTOR        (48 * 2u) /* 0xFFE0 Port 2 */
    #define PORT1_VECTOR        (49 * 2u) /* 0xFFE2 Port 1 */
    #define TIMER1_A1_VECTOR    (50 * 2u) /* 0xFFE4 Timer1_A3 CC1-2, TA1 */
    #define TIMER1_A0_VECTOR    (51 * 2u) /* 0xFFE6 Timer1_A3 CC0 */
    #define DMA_VECTOR          (52 * 2u) /* 0xFFE8 DMA */
    #define CC1101_VECTOR       (53 * 2u) /* 0xFFEA CC1101 Radio Interface */
    #define TIMER0_A1_VECTOR    (54 * 2u) /* 0xFFEC Timer0_A5 CC1-4, TA */
    #define TIMER0_A0_VECTOR    (55 * 2u) /* 0xFFEE Timer0_A5 CC0 */
    #define ADC12_VECTOR        (56 * 2u) /* 0xFFF0 ADC */
    #define USCI_B0_VECTOR      (57 * 2u) /* 0xFFF2 USCI B0 Receive/Transmit */
    #define USCI_A0_VECTOR      (58 * 2u) /* 0xFFF4 USCI A0 Receive/Transmit */
    #define WDT_VECTOR          (59 * 2u) /* 0xFFF6 Watchdog Timer */
    #define COMP_B_VECTOR       (60 * 2u) /* 0xFFF8 Comparator B */
    #define UNMI_VECTOR         (61 * 2u) /* 0xFFFA User Non-maskable */
    #define SYSNMI_VECTOR       (62 * 2u) /* 0xFFFC System Non-maskable */
    #define RESET_VECTOR        (63 * 2u) /* 0xFFFE Reset [Highest Priority] */
    

    Match these up with the vectors listed in the datasheet to know which one to use.

  • thanks Brian Boorman and here are the answers to your questions

    1)I am not sure why you have an ISR that handles the timer interrupt and call it "Port3".

    I want to read the input pulse signal from the P3SEL |= BIT2; (it is connected to TA0CCR1A)for which the frequency will be measured depending on the reference clock signal 

    2)You also have two ISRs for the same vector, which should give you a linker error.

    Yes,you are right I am getting Load_programme_error.

    Can you please suggest me the ways of correcting the things in the above code.

    thanks.

  • Govardhan Reddy Patancheru said:

    2)You also have two ISRs for the same vector, which should give you a linker error.

    Yes,you are right I am getting Load_programme_error.

    Can you please suggest me the ways of correcting the things in the above code.

    - Don't have two ISR's for the same vector :) Isn't that obvious?

    If you read Brian's post carefully enough you will notice that each timer have **two** vectors. So consult User's  Guide to find out what your are doing wrong

  • Now I was bale to remove the Load_programme_error

    By following these lines from cc430f5137 .h file 

    SFR_16BIT(TA0CCR0);                           /* Timer0_A5 Capture/Compare 0 */
    SFR_16BIT(TA0CCR1);                           /* Timer0_A5 Capture/Compare 1 */
    #ifdef __ASM_HEADER__ /* Begin #defines for assembler */
    #define TIMER0_A1_VECTOR        ".int54"                     /* 0xFFEC Timer0_A5 CC1-4, TA */
    #else
    #define TIMER0_A1_VECTOR        (54 * 1u)                    /* 0xFFEC Timer0_A5 CC1-4, TA */
    #endif
    #ifdef __ASM_HEADER__ /* Begin #defines for assembler */
    #define TIMER0_A0_VECTOR        ".int55"                     /* 0xFFEE Timer0_A5 CC0 */
    #else
    #define TIMER0_A0_VECTOR        (55 * 1u)                    /* 0xFFEE Timer0_A5 CC0 */
    #endif

    And modifying like this

    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void TIMER0_A0_ISR(void)
    {
    __bic_SR_register_on_exit(CPUOFF);//wakes up CPU from OFF
    }
    #pragma vector=TIMER0_A1_VECTOR
    __interrupt void TIMER0_A1_ISR(void)
    {
    //freq caclculation
    }

    But now I want to modify this code such that it

    works with measuring the signal read out using ADC_channel instead of directly reading input signal of a port.

    can anyone give some guidelines (or) suggestions for modifying this.

    Thanks.

  • Govardhan Reddy Patancheru said:

    But now I want to modify this code such that it

    works with measuring the signal read out using ADC_channel instead of directly reading input signal of a port.

    Please explain what you want to do with ADC here - in freq measurement application.

  • I want to read my Sensor output through ADC channel and want to measure the freq of the ADC read signal.

    Can I know how to do this.

    Thanks.

  • Govardhan Reddy Patancheru said:
    I want to read my Sensor output through ADC channel and want to measure the freq of the ADC read signal.

    So your frequency measurement part is working? You tested it and it works as expected?

  • Actually ,I haven't tested the frequency measurement part as I am having problem with my board!!

    First, I thought I will connect the input signal to one of the ports for the frequency measurement code but the original board on which I am using the cc430f5137 is already having the sensor output connected to its ADC channel.

    So,I want to go with the frequency measurement of the sensor output read by ADC channel and will try to solve if there is problem with the code.

    can you guide me out with this.

    Thanks.

  • Govardhan Reddy Patancheru said:
    can you guide me out with this.

    No. I am bored and lost motivation :) Good luck!

  • Can you please atleast provide some examples or related materials for this.

    Thanks.

  • Govardhan Reddy Patancheru said:
    can some one explain about the things.

    The timer nomenclature is indeed very confusing for newcomers. This is easy to forget after you got used to it.

    For ISRs, the naming is
    TIMERx_yz_VECTOR.
    y is the type of timer (A, B or D).
    x is the number of the timer (some MSPs have up to 3 TimerA modules)
    Z is either 0 or 1. 0 is the vector for the timer's CCR0 interrupt, 1 is for all other CCR interrupts and the timer overflow interrupt.

    Historically there are some aliases: when there was only one TimerA in a device, TIMER_A0/TIMER_A1 was used for it. This is identical to TIMER0_A0 and TIMER0_A1.

    Similarly, there are aliases for the registers. For TA0R there is also TAR. And for TA0CCRx there is also TACCRx and even CCRx. The same has happened to the signals name son the physical pins: "TA0.1" is the output of TA0CCR1. However, on older devices, it is just called "TA1".

    Independently from the interrupt and register names, there is another timer-related nomenclature: "Timer_A3" (note the case), as used in the code comment, refers to the timer implementation: a TimerA module with 3 CCR register (CCR0 to CCR2). Other MSPs have a Timer_A2 or Timer_A5 module. Or multiple modules in different combinations. IIRC, there's one with two Timer_A3 and one Timer_A5 modules.

**Attention** This is a public forum