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.
Part Number: MSP432P401R
Tool/software: Code Composer Studio
I been struggling implementing multiple capture registers for Timer A0. I am able to initialize one of the capture registers, but initializing multiple captures has either given errors or one of the registers didn't work. I am attempting to use capture modes for sonar reading, and I need multiple registers in order to read multiple sonars being triggered. They would be triggered in order (first sonar triggered, then wait, after sonar 1 data is back and processed, then trigger next sonar, etc.).
#include "msp.h"
#include "driverlib.h"
#include <stdint.h>
char measure1[40] = {0};
/* Timer_A Continuous Mode Configuration Parameter */
const Timer_A_ContinuousModeConfig continuousModeConfig =
{
TIMER_A_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
TIMER_A_CLOCKSOURCE_DIVIDER_1, // SMCLK/1 = 3MHz
TIMER_A_TAIE_INTERRUPT_DISABLE, // Disable Timer ISR
TIMER_A_SKIP_CLEAR // Skup Clear Counter
};
/* Timer_A Capture Mode Configuration Parameter */
const Timer_A_CaptureModeConfig captureModeConfig =
{
TIMER_A_CAPTURECOMPARE_REGISTER_1,// || TIMER_A_CAPTURECOMPARE_REGISTER_2, // CC Register 2
TIMER_A_CAPTUREMODE_RISING_AND_FALLING_EDGE, // Rising Edge and falling
TIMER_A_CAPTURE_INPUTSELECT_CCIxA, // CCIxA Input Select
TIMER_A_CAPTURE_SYNCHRONOUS, // Synchronized Capture
TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE, // Enable interrupt
TIMER_A_OUTPUTMODE_OUTBITVALUE // Output bit value
};
static void Delay(uint32_t loop)
{
volatile uint32_t i;
for (i = 0 ; i < loop ; i++);
}
int meas1 = 0;
int meas2 = 0;
int meas3 = 0;
int meas4 = 0;
int time1 = 0;
int time2 = 0;
int distance1 = 0;
int distance2 = 0;
int main(void)
{
/* Stop watchdog timer */
MAP_WDT_A_holdTimer();
CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_24); // 24MHz
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // 24000000 Hz
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_64); // attempt 375,000 Hz
//CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8); // 3000000 Hz
/* Configuring P2.4 as peripheral input for capture */
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2, GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2, GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION);
GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN5);
GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN6);
/* Configuring Capture Mode */
Timer_A_initCapture(TIMER_A0_BASE, &captureModeConfig);
/* Timer_A_initCapture(TIMER_A0_BASE,
TIMER_A_CAPTURECOMPARE_REGISTER_2,
TIMER_A_CAPTUREMODE_RISING_AND_FALLING_EDGE,
TIMER_A_CAPTURE_INPUTSELECT_CCIxA,
TIMER_A_CAPTURE_SYNCHRONOUS,
TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE,
TIMER_A_OUTPUTMODE_OUTBITVALUE
);*/
/* Configuring Continuous Mode */
Timer_A_configureContinuousMode(TIMER_A0_BASE, &continuousModeConfig);
/* Enabling interrupts */
Timer_A_enableCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1);
Timer_A_enableCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2);
Interrupt_enableInterrupt(INT_TA0_N);
Interrupt_enableMaster();
/* Starting the Timer32 */
Timer32_initModule(TIMER32_0_BASE, TIMER32_PRESCALER_1, TIMER32_32BIT, TIMER32_PERIODIC_MODE);
Timer32_disableInterrupt(TIMER32_0_BASE);
Timer32_setCount(TIMER32_0_BASE, 1);
Timer32_startTimer(TIMER32_0_BASE, true);
/* Starting the Timer_A0 in continuous mode */
Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_CONTINUOUS_MODE);
lcd_init();
while(1)
{
GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN5);
Timer32_setCount(TIMER32_0_BASE, 24 * 10);
while (Timer32_getValue(TIMER32_0_BASE) > 0); // Wait 10us
GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN5); //software delays
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN6);
Timer32_setCount(TIMER32_0_BASE, 24 * 10);
while (Timer32_getValue(TIMER32_0_BASE) > 0); // Wait 10us
GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN6); //software delays
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
Delay(40000);
}
}
void TA0_N_IRQHandler(void)
{
switch(TA0IV) { // switch between capture interrupt pins
case 0x0002: //Pin 2.4 interrupt
{
int rising = 0;
if(P2IN&0x10) rising=1; else rising=0; // checking between rising and falling edge
if(rising) // Start
{
meas1 = Timer_A_getCaptureCompareCount(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1);
Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1);
//lcd_command(0x01);
//__delay_cycles(22000);
//sprintf(measure1, "D = %d", meas1);
//out_string(measure1);
//__delay_cycles(22000);
}
else
{
meas2 = Timer_A_getCaptureCompareCount(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1);
time1 = meas2-meas1;
distance1 = 34400*time1/2/375000;
//lcd_command(0x01);
//__delay_cycles(22000);
//sprintf(measure1, "D = %d", distance);
// __delay_cycles(22000);
// out_string(measure1);
Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1);
}
break;
}
case 0x0004: //Pin 2.5 interrupt
{
int rising = 0;
if(P2IN&0x20) rising=1; else rising=0; //checking between rising and falling edge
if(rising) // Start
{
meas3 = Timer_A_getCaptureCompareCount(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2);
Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2);
}
else
{
meas4 = Timer_A_getCaptureCompareCount(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2);
time2 = meas4-meas3;
distance2 = 34400*time2/2/375000;
//lcd_command(0x01);
//__delay_cycles(22000);
//sprintf(measure1, "D = %d", distance);
// __delay_cycles(22000);
// out_string(measure1);
Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2);
}
break;
}
}
}
**Attention** This is a public forum