Quantcast
Channel: MSP low-power microcontroller forum - Recent Threads
Viewing all articles
Browse latest Browse all 22466

Input Capture Mode (Timer in Continous Mode )MSP30FR5969

$
0
0

Hi All,

We are working on MSP430FR5969, new to this type of Microcontroller , our application is to count pulses ( four input senors ) also trying to avoid noise if any (any pulse more than 20 ms is taken as valid pulse, less than that will be considered as noise) , with help of driverlib.h file tried programming , but not able to triger the inerrupt , need some help to know what is the mistake in the below code.

In the code:

a)pin p1.1 as input

b)Timer A CaptureMode,rising edge,sync,interrupt enabled,Continuous Mode

#include <msp430.h>
//#include <msp430x14x.h>
#include "driverlib.h"

unsigned int new_cap=0;
unsigned int old_cap=0;
unsigned int cap_diff=0;

unsigned int diff_array[16]; // RAM array for differences
unsigned int capture_array[16]; // RAM array for captures
unsigned char index=0;
unsigned char count = 0;

Timer_A_initCaptureModeParam param = {0};

void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
for (i=0; i<20000; i++) // Delay for crystal stabilization
{
}
GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0);
GPIO_setAsInputPin(GPIO_PORT_P1,GPIO_PIN1);
// P1DIR = 0x01; // Set P1.0 out,1.1 input dir
// P1OUT &= ~0x01; // LED off
// P1SEL = 0x02; // Set P1.1 to TA0

GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1,GPIO_PIN1,GPIO_TERNARY_MODULE_FUNCTION);

// P2DIR = 0x01; // P2.0-ACLK
// P2SEL |= 0x01;
// BCSCTL1 |= DIVA_3; // ACLK/8

// TA1CCTL0 = CM_1 + SCS + CCIS_1 + CAP + CCIE; // Rising edge + CCI0A (P1.1)
// + Capture Mode + Interrupt

GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,GPIO_PIN0,GPIO_PRIMARY_MODULE_FUNCTION);

// TA1CTL = TASSEL_2 + MC_2; // SMCLK + Continuous Mode


param.captureRegister = TIMER_A_CAPTURECOMPARE_REGISTER_0; //P1.1
param.captureMode = TIMER_A_CAPTUREMODE_RISING_EDGE;
param.captureInputSelect = TIMER_A_CAPTURE_INPUTSELECT_CCIxA;
param.synchronizeCaptureSource = TIMER_A_CAPTURE_SYNCHRONOUS;
param.captureInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
param.captureOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE;

Timer_A_initCaptureMode(TIMER_A1_BASE, &param);

//Start timer in continuous mode sourced by ACLK
Timer_A_clearTimerInterrupt(TIMER_A1_BASE);

Timer_A_initContinuousModeParam param = {0};
param.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_3;
param.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_ENABLE;
param.timerClear = TIMER_A_DO_CLEAR;
param.startTimer = false;
Timer_A_initContinuousMode(TIMER_A1_BASE, &param);

Timer_A_startCounter(TIMER_A1_BASE,
TIMER_A_CONTINUOUS_MODE
);

_BIS_SR(LPM0_bits + GIE); // LPM0 + Enable global ints
}

#pragma vector=TIMER0_A1_VECTOR
__interrupt void TimerA1(void)
{
// new_cap = TA1CCR0;

new_cap = Timer_A_getCounterValue(TIMER_A1_BASE);

// TA1CCTL0 ^= CM_3; // change edge //OCY
param.captureMode = TIMER_A_CAPTUREMODE_RISING_AND_FALLING_EDGE;

cap_diff = new_cap - old_cap;

diff_array[index] = cap_diff; // record difference to RAM array
capture_array[index++] = new_cap;
if (index == 16)
{
index = 0;
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
}
old_cap = new_cap; // store this capture value
count ++;
if (count == 32)
{
count = 0;
_NOP(); // SET BREAKPOINT HERE
}

}

thanks in advance,

Regards,

Sanil


Viewing all articles
Browse latest Browse all 22466

Trending Articles