Part Number: MSP430F5529
From the code below, the goal is to generate beep based on the timer config function in line. The first value is the timer period, then next is the duty cycle and the third is the number of beep to produce.
So from the existing function, a timer period is set at 32768, duty cycle of 16384 and beep count is 4. But code didn't go as expected on my MSP430F5529 LP.
#include <driverlib.h>
//Tested on MSP430F5529LP
int tCount; dutyCycle;
int beepCount; int counter; int newDutyCycle;
int countval = 0; int
void init();
int timer_config(int newPeriod, int newDutyCycle, int beep);
void stop_timer();
void main(){
init();
timer_config(32768,16384, 4); //Configure timer
while(1){
}
__bis_SR_register(LPM0 + GIE); //Enter Low Power Mode
__no_operation(); //Enter Debugger Mode
}
void init() {
WDT_A_hold(WDT_A_BASE); //Stop Watchdog Timer
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN0); //Set Pin 2.0 as output pin
//Configure Timer
Timer_A_initUpModeParam param = {0};
param.clockSource = TIMER_A_CLOCKSOURCE_ACLK; // ~1045000Hz
param.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; //~18660Hz
param.timerPeriod = 32768;
param.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;
param.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE;
param.timerClear = TIMER_A_DO_CLEAR;
param.startTimer = false;
Timer_A_initUpMode(TIMER_A1_BASE, ¶m);
//Configure Capture Compare Register
Timer_A_initCompareModeParam paramCCR1 = {0};
paramCCR1.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
paramCCR1.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
paramCCR1.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;
paramCCR1.compareValue = 16384;
Timer_A_initCompareMode(TIMER_A1_BASE, ¶mCCR1);
}
int timer_config(int newPeriod, int newDutyCycle, int beep){
Timer_A_setCompareValue(TIMER_A1_BASE,
TIMER_A_CAPTURECOMPARE_REGISTER_0,
newPeriod);
Timer_A_setCompareValue(TIMER_A1_BASE,
TIMER_A_CAPTURECOMPARE_REGISTER_1,
newDutyCycle);
Timer_A_clear(TIMER_A1_BASE);
Timer_A_startCounter(TIMER_A1_BASE, TIMER_A_UP_MODE);
if (countval==beep)
{
countval==0;
stop_timer();
}
}
void stop_timer(){
Timer_A_stop(TIMER_A1_BASE);
Timer_A_disableInterrupt(TIMER_A1_BASE);
}
#pragma vector = TIMER1_A0_VECTOR
__interrupt void timer1_ISR(void) {
GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0);
Timer_A_clearTimerInterrupt(TIMER_A1_BASE);
}
#pragma vector = TIMER1_A1_VECTOR
__interrupt void timer0_ISR(void) {
switch(__even_in_range(TA0IV, TA0IV_TAIFG)) {
case TA0IV_NONE: break;
case TA0IV_TACCR1:
GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0);
countval++;
Timer_A_clearTimerInterrupt(TIMER_A1_BASE);
break;
case TA0IV_TACCR2: break;
case TA0IV_TACCR3: break;
case TA0IV_TACCR4: break;
case TA0IV_5: break;
case TA0IV_6: break;
case TA0IV_TAIFG: break;
default: _never_executed();
}
}
