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

Compiler/MSP430F5529: Enabling capture interrupt causes isr_trap.asm to run while application hangs

$
0
0

Part Number:MSP430F5529

Tool/software: TI C/C++ Compiler

Hello,

Please I am trying to measure the period of a signal with an MSP430F5529 launchpad. The signal is fed to the MCU via P1.2. I am using TA0 with the CCR1 register in capture mode. When debugging the program, the main application i.e. the LED blinking part of the code works, but immediately interrupts are enabled, the program below runs (isr_trap.asm). This causes the entire application to hang. Please I need help to fix this issue, thank you.

;******************************************************************************
;* ISR_TRAP.ASM - v15.12.1                                                    *
;*                                                                            *
;* Copyright (c) 2003-2016 Texas Instruments Incorporated                     *
;* http://www.ti.com/                                                         *
;*                                                                            *
;*  Redistribution and  use in source  and binary forms, with  or without     *
;*  modification,  are permitted provided  that the  following conditions     *
;*  are met:                                                                  *
;*                                                                            *
;*     Redistributions  of source  code must  retain the  above copyright     *
;*     notice, this list of conditions and the following disclaimer.          *
;*                                                                            *
;*     Redistributions in binary form  must reproduce the above copyright     *
;*     notice, this  list of conditions  and the following  disclaimer in     *
;*     the  documentation  and/or   other  materials  provided  with  the     *
;*     distribution.                                                          *
;*                                                                            *
;*     Neither the  name of Texas Instruments Incorporated  nor the names     *
;*     of its  contributors may  be used to  endorse or  promote products     *
;*     derived  from   this  software  without   specific  prior  written     *
;*     permission.                                                            *
;*                                                                            *
;*  THIS SOFTWARE  IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS     *
;*  "AS IS"  AND ANY  EXPRESS OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT     *
;*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR     *
;*  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT     *
;*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     *
;*  SPECIAL,  EXEMPLARY,  OR CONSEQUENTIAL  DAMAGES  (INCLUDING, BUT  NOT     *
;*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     *
;*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     *
;*  THEORY OF  LIABILITY, WHETHER IN CONTRACT, STRICT  LIABILITY, OR TORT     *
;*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE     *
;*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.      *
;*                                                                            *
;******************************************************************************


;-----------------------------------------------------------------------------
;-- default ISR handler if user does not supply
;-- simply puts device into lpm0
;-----------------------------------------------------------------------------

   	.sect	".text:_isr:__TI_ISR_TRAP"
	.align	2
	.global	__TI_ISR_TRAP
__TI_ISR_TRAP:
        BIS.W     #(0x0010),SR
        JMP __TI_ISR_TRAP

        NOP                     ; CPU40 Compatibility NOP

;******************************************************************************
;* BUILD ATTRIBUTES                                                           *
;*    HW_MPY_INLINE_INFO=1:  file does not have any inlined hw mpy            *
;*    HW_MPY_ISR_INFO   =1:  file does not have ISR's with mpy or func calls  *
;******************************************************************************
        .battr "TI", Tag_File, 1, Tag_HW_MPY_INLINE_INFO(1)
        .battr "TI", Tag_File, 1, Tag_HW_MPY_ISR_INFO(1)

Please this is the program I am debugging:

/**
 * Section: Included Files
 */

#include <stdio.h>
#include <stdint.h>
#include "driverlib.h"
#include "LCD_driver.h"

/**
 * Section: Global Variables Definitions
 */

uint16_t period_raw = 0;
uint16_t captured_value;
uint16_t previous_capture;
float period_old;
float period_new;
float period_change;
float calibrated_capacitance;
float measured_capacitance;

/**
 * Section: Macro Declarations
 */

#define RA 1000								// value of resistor RA in ohms
#define RB 10000							// value of resistor RB in ohms
#define K  (1.44 / ((RA) + (2 * RB)))		// constant for determining the capacitance
#define P  1								// value of one timer tick in seconds (redefine this value)

/**
 * Section: Function Prototypes
 */

void capture_config(void);
inline void capture_interrupt(void);

/**
 * Section: Main Application
 */

int main(void)
{
    WDT_A_hold(WDT_A_BASE);								// Stop watchdog timer
    GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);

    capture_config();									// configure timerA for capture mode

    delay_ms(50);										// allow 555 timer to stabilize?

    char display_data[20];

	while(1)
	{
		if(TIMER_A_CAPTURE_OVERFLOW == Timer_A_getCaptureCompareInterruptStatus\
		(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, TIMER_A_CAPTURE_OVERFLOW))
	    {
			// reset timer?
	    }

		//blink led
		GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);
		delay_ms(1000);
		GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
		delay_ms(1000);
	}
}

/**
 * Section: Function Definitions
 */

void capture_config(void)
{
	// set P1.2 as input
	GPIO_setAsInputPin(GPIO_PORT_P1, GPIO_PIN2);
	// set P1.2 as capture input
	GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN2);

	// initialize timerA for continuous mode operation
	Timer_A_initContinuousModeParam continuous_param = {0};
	continuous_param.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
	continuous_param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
	continuous_param.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;
	continuous_param.timerClear = TIMER_A_DO_CLEAR;
	continuous_param.startTimer = false;
	Timer_A_initContinuousMode(TIMER_A0_BASE, &continuous_param);

	// initialize timerA capture mode
	Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_0);
	Timer_A_initCaptureModeParam capture_param = {0};
	capture_param.captureRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
	capture_param.captureInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
	capture_param.captureMode = TIMER_A_CAPTUREMODE_RISING_EDGE;
	capture_param.captureInputSelect = TIMER_A_CAPTURE_INPUTSELECT_CCIxA;
	capture_param.synchronizeCaptureSource = TIMER_A_CAPTURE_SYNCHRONOUS;
	capture_param.captureOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE;
	Timer_A_initCaptureMode(TIMER_A0_BASE, &capture_param);

	Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_CONTINUOUS_MODE);

	// enable interrupts
	__bis_SR_register(GIE);
}

inline void capture_interrupt(void)
{
	static uint8_t interrupt_number = 0;
	interrupt_number++;
	// get captured value
	captured_value = Timer_A_getCaptureCompareCount(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1);
	if(interrupt_number == 1)
	{
		previous_capture = captured_value;
	}
	if(interrupt_number == 2)
	{
		period_raw = captured_value - previous_capture;
		interrupt_number = 0;
	}
}

/**
 * Section: Interrupt Service Routine
 */

#pragma vector=TIMER1_A1_VECTOR
__interrupt void TIMER_A0_ISR(void)
{
	switch(__even_in_range(TA0IV, 14))
	{
		case 0:							// none
			break;
		case 2:							// CCR1 IFG
			capture_interrupt();
			break;
		case 4:							// CCR2 IFG
			break;
		case 6:							// CCR3 IFG
			break;
		case 8:							// CCR4 IFG
			break;
		case 10:						// CCR5 IFG
			break;
		case 12: 						// CCR6 IFG
			break;
		case 14:						// TAOIFG
			break;
		default: 						// never executed
			break;
	}
}

Although the application hangs, viewing the CCR1 register in the watches window confirmed that the capture mode of the timer was at work when fed with a 1KHz signal from a signal generator. A screenshot of this is shown below:


Viewing all articles
Browse latest Browse all 22179

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>