Part Number:MSP430FR2633
Tool/software: Code Composer Studio
Hello,
i am working with Captivate Design Center and tried to write the code to a CapaTouch Sensor to regulate the light of a LED.
While I was succesfull realising to start the PWM signal for the LED with the touchsensor i am not able to realise a timer (in the Code: TIMER_A1_BASE) to make the duty cycle of the PWM signal time-dependent. My idea was to start the timer (like the PWM signal) as the apphandler is running and with every overflow of the counter the dutycycle should increase by 5.
While the PWM signal is running as soon as i use the touchsensor, the timer i started in the line before doesn't seem to run. There isn't even 1 interrupt triggered to increase the duty cycle.
Now my Question is: Did I falsely generate the timer or is the any issue with the interrupt?
My Code:
#include<msp430.h> // Generic MSP430 Device Include
#include"driverlib.h" // MSPWare Driver Library
#include"captivate.h" // CapTIvate Touch Software Library
#include"CAPT_App.h" // CapTIvate Application Code
#include"CAPT_BSP.h" // CapTIvate EVM Board Support Package
#include"timer_a.h"
#include"timer_b.h"
#define TIMER_A_PERIOD 524
#define TIMER_B_PERIOD 1000
//#define DUTY_CYCLE 393
int DUTY_CYCLE = 250;
voidmain(void)
{
//
// Initialize the MCU
// BSP_configureMCU() sets up the device IO and clocking
// The global interrupt enable is set to allow peripherals
// to wake the MCU.
//
WDTCTL = WDTPW | WDTHOLD;
BSP_configureMCU();
__bis_SR_register(GIE);
//
// Start the CapTIvate application
//
CAPT_appStart();
WDT_A_hold(WDT_A_BASE);
//WDT_B_hold(WDT_B_BASE);
//P1.1 as PWM output
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P1,
GPIO_PIN1,
GPIO_SECONDARY_MODULE_FUNCTION
);
//int DUTY_CYCLE = 1;
/*
* Disable the GPIO power-on default high-impedance mode to activate
* previously configured port settings
*/
PMM_unlockLPM5();
//Generate PWM - Timer runs in Up-Down mode
Timer_A_outputPWMParam param = {0};
param.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;
param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
param.timerPeriod = TIMER_A_PERIOD;
param.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
param.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;
//param.dutyCycle = DUTY_CYCLE;
Timer_A_initUpModeParam paramB = {0};
paramB.clockSource = TIMER_A_CLOCKSOURCE_ACLK;
paramB.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
paramB.timerPeriod = TIMER_B_PERIOD;
paramB.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_ENABLE;
paramB.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE;
paramB.timerClear = TIMER_A_DO_CLEAR;
paramB.startTimer =false;
//Enter LPM0
__bis_SR_register(LPM0_bits);
// Background Loop
//
while(1)
{
//
// Run the captivate application handler.
// Set LED1 while the app handler is running,
// and set LED2 if proximity is detected
// on any sensor.
//
LED1_ON;
if(CAPT_appHandler()==true)
{
LED2_ON;
param.dutyCycle = DUTY_CYCLE;
Timer_A_startCounter(TIMER_A1_BASE, ¶mB);
Timer_A_outputPWM(TIMER_A0_BASE, ¶m);
}
else
LED2_OFF;
LED1_OFF;
//Timer_A_stop(TIMER_A1_BASE);
// This is a great place to add in any
// background application code.
//
__no_operation();
//
// End of background loop iteration
// Go to sleep if there is nothing left to do
//
CAPT_appSleep();
} // End background loop
} // End main()
#pragma vector=TIMER0_A1_VECTOR
__interruptvoidTimer_A1 (void)
{
if(DUTY_CYCLE < 500)
DUTY_CYCLE= DUTY_CYCLE+5;
else
DUTY_CYCLE = 0;
}