1426 views|0 replies

2015

Posts

0

Resources
The OP
 

MSP430 MCU timer TA capture program [Copy link]

#include
#include "LCD_Display.h" unsigned int TA_OverflowCnt; // TA overflow times are stored in variables unsigned long int Period; // Pulse width measurement results are stored in variables unsigned int RiseCapVal; // Rising edge capture value is stored in variables unsigned char Edge=0; // Current trigger edge #define RISE 0 #define FALL 1 void main( void ) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog FLL_CTL0 |= XCAP18PF; // Configure crystal load capacitance P1DIR &=~(BIT2); // P1.2(TA1) is set as input (optional) P1SEL |= BIT2; // P1.2 is set as the second function (TA1) TACTL = TASSEL_2 + MC_2 + TAIE + TACLR; // TA counts continuously, starts timing, SMCLK, opens interrupt TACCTL1 = CAP + CM_1 + CCIS_1 + SCS + CCIE; //Capture module 1 starts, selects TA1 (P1.2) pin as the capture source, rising edge capture, synchronous mode, turns on capture interrupt BTCTL=0; LCD_Init(); _EINT(); //General interrupt allows LPM0; // Enter low power mode 3 sleep, all programs are executed in the interrupt } #pragma vector=TIMERA1_VECTOR __interrupt void TA_ISR(void) //Timer_A interrupt { switch( TAIV ) { case 2: // Comparison/capture module 1 interrupt if(Edge==RISE) //If it is a rising edge capture interrupt { RiseCapVal=TACCR1; //Save the capture value at the rising edge TACCTL1 = CAP +CM_2 +CCIS_1 +SCS +CCIE; //Change to falling edge trigger Edge=FALL; //Trigger edge status flag } else //If it is a falling edge capture interrupt { Period=TA_OverflowCnt*65536 + TACCR1 - RiseCapVal;//Calculation period TA_OverflowCnt=0; //Clear overflow times TACCTL1 = CAP +CM_2 +CCIS_1 +SCS +CCIE;//Change to rising edge trigger Edge=FALL; //Trigger edge status flag LCD_DisplayLongNumber(Period); //Display} break; case 4: break; case 10: TA_OverflowCnt++; //TA overflows each time, overflow times variable + 1 break; } }


This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list