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.

Problem with my Timer

#include <msp430x44x.h>
#include <stdio.h>

//************************************************
//Globale Variablen
//************************************************
unsigned int x=0;
unsigned int m=0;
unsigned long Time;
unsigned long Time_O;
char Daten[10];
int Sensor[4];

//************************************************
// Initialiesierung des Timers
//************************************************
void Init_Timer()
     {
	 
	 P1IN = 0x01;	   								  // Set Pin 1.0 als Input
	 P1SEL |= 0x01;	   								  // Set Pin 1.0 als CCI0A
	 
	 TACCTL0 = CM_1+ CCIS_0+ CAP+ SCS+ CCIE;	      // Capture on rising edge,CCI0A,Capture mode,Synchronized,interrupt enable 		                               
 	 TACTL = TASSEL_2 + MC_2+ TAIE;    	              	  // SMCLK,Continuous mode,interrupt request
	 
	 }

//************************************************	 
// Initialiesierung der Clock
//************************************************
void Init_Clock()
     {
	 
	 FLL_CTL1 = SELS;                                 // SMCLK 8MHz
	 
	 }

//************************************************
// Initialiesierung der USART Schnittstelle	 
//************************************************
void Init_USART()
     {
  
     P2SEL |= 0x30;                                   // P2.4,5 = USART0 TXD/RXD
     ME1 |= UTXE0 + URXE0;                            // Enable USART0 TXD/RXD
     UCTL0 |= CHAR;                                   // 8-bit character
     UTCTL0 |= SSEL0;                                 // UCLK = ACLK
     UBR00 = 0x03;                                    // 32kHz 9600
     UBR10 = 0x00;                                    // 32kHz 9600
     UMCTL0 = 0x03;                                   // modulation
     UCTL0 &= ~SWRST;                                 // Initialize USART state machine
     P2DIR |= 0x10;                                   // P2.4 output direction
     
	 }

	  
//************************************************
// Daten versenden(USART)
//************************************************ 
void SendUSART0(char Senden[])                        // Einen string �ber die serielle Schnittstelle (USART0) senden
     { 
     
	 unsigned int i = 0;
     while (Senden[i] != 0)
     {
     while (!(IFG1 & UTXIFG0));                       // Warten, bis USART0 TX-buffer sendebereit
     TXBUF0 = Senden[i];
	 i++;
     }
	 printf("\r\n");
	 
	 }
	 

//************************************************
// Durchflusssensorwerte versenden
//************************************************  
void Send_Durchflusssensor()                          // Einen string �ber die serielle Schnittstelle (USART0) senden
     { 
     
	 sprintf(Daten,"%ld",Time);                        // Werte in einen String umwandeln
	 printf("E");
	 SendUSART0(Daten);                               // Daten versenden
	 sprintf(Daten,"%u",m);
	 printf("F");
	 SendUSART0(Daten);

	 }
	 	 	 
//************************************************	 	 
// Hauptschleife
//************************************************
void main(void)
{
	 
	 WDTCTL = WDTPW + WDTHOLD;                        // Stop watchdog timer
         Init_Clock();                                    // Clock
	 Init_USART();                                    // USART Schnittstelle
	 Init_Timer();                                    // Timer
	 Init_ADC();                                      // ADC Initialiesierung
	 
	 _EINT();                                         // Interrupts enable
	 
	 
	 
	 while(1)
	 {
         Send_Durchflusssensor();
	 
         }
}

//************************************************	
// Interrupt bei steigender Flanke	 
//************************************************
#pragma interrupt_handler timer_handler:TIMERA0_VECTOR
void timer_handler(void)
  {
 
       if(TAIV== 0x0A)                                     // Abfrage ob Overflow Interrupt
	   {
	   Time = TAR;
	   m++;
	   }
	   else
	   {
	   Time = TAR;                                     // Z�hlwert speichern
	   TAR = 0;                                        // Z�hlregister auf null setzen
	   }
  }  


 

Hello,

I have a problem with my Timer. I want to measure the frequence of a square wave signal with the capture mode of my Timer (Msp430 F449).

It works good until i get a Overflow. When i get a Overflow my hole program stopps!

My questions are:

Why do my program stopp?

How can i sove this problem?

Thanks for help

Maik

  • Maik Hof said:
    Why do my program stopp

    Since there is no such thing like a 'stop the program' function in the timer module, it would be a great help for anyone who wants to help you, to see the code you wrote.

    'the truth is out there', but it cannot be found in the scarce information you provided.

  • Maik,

    The interrupts for CCR1, CCR2, and the rollover fall into a different interrupt handler.

    These all fall under the TIMERA1_VECTOR. Take a look at fet410_ta_03.c:

    #pragma vector=TIMERA1_VECTOR 

    __interrupt void Timer_A(void)

    {

    switch( TAIV )

    {

    case 2: break; // CCR1 not used

    case 4: break; // CCR2 not used

    case 10: P5OUT ^= 0x02; // overflow

    break;

    }

    }

    When you hit case 10, you would want to add the full count to your variable that is being used to keep track of the signal.

     

    -Jason

     

**Attention** This is a public forum