void shortDelay() { Timer_A_initUpModeParam tParams; tParams.clockSource = TIMER_A_CLOCKSOURCE_ACLK; tParams.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; tParams.timerPeriod = 8196; tParams.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE; tParams.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE; tParams.timerClear = TIMER_A_DO_CLEAR; tParams.startTimer = 0; //start timer Timer_A_clearTimerInterrupt(TIMER_A1_BASE); Timer_A_initUpMode(TIMER_A1_BASE, &tParams); Timer_A_startCounter(TIMER_A1_BASE, TIMER_A_UP_MODE); bDelayDone = 0; while( bDelayDone == 0) LPM3; Timer_A_stop(TIMER_A1_BASE); }
/* * ======== Timer0_A3_graceInit ======== * Initialize Config for the MSP430 A3 Timer 0 */ void Timer0_A3_graceInit(void) { /* Struct to pass to Timer_A_initUpMode */ Timer_A_initUpModeParam initUpParam = {0}; /* USER CODE START (section: Timer0_A3_graceInit_prologue) */ /* User initialization code */ /* USER CODE END (section: Timer0_A3_graceInit_prologue) */ /* Initialize TimerA in up mode */ initUpParam.clockSource = TIMER_A_CLOCKSOURCE_ACLK; initUpParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; initUpParam.timerPeriod = 7; initUpParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_ENABLE; initUpParam.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE; initUpParam.timerClear = TIMER_A_SKIP_CLEAR; initUpParam.startTimer = false; Timer_A_initUpMode(TIMER_A0_BASE, &initUpParam); /* Start TimerA counter */ Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_UP_MODE); /* USER CODE START (section: Timer0_A3_graceInit_epilogue) */ /* User code */ /* USER CODE END (section: Timer0_A3_graceInit_epilogue) */ }
void timerConfiguration(void) { /*TimerA is used to send trigger pulses to sensor. (Used to keep MCU in LPM3). * You may comment out this code if you want to use __delay_cycles(). But I highly recommend you not to do so */ Timer_A_initUpModeParam initTimerAUpParam = {0}; initTimerAUpParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; initTimerAUpParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; initTimerAUpParam.timerPeriod = 40; initTimerAUpParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_ENABLE; initTimerAUpParam.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE; initTimerAUpParam.timerClear = TIMER_A_DO_CLEAR; initTimerAUpParam.startTimer = false; Timer_A_initUpMode(TIMER_A0_BASE, &initTimerAUpParam); //Timer B is used to calculate sensor output pulse duration Timer_B_initUpModeParam initTimerBUpParam = {0}; initTimerBUpParam.clockSource = TIMER_B_CLOCKSOURCE_SMCLK; initTimerBUpParam.clockSourceDivider = TIMER_B_CLOCKSOURCE_DIVIDER_1; initTimerBUpParam.timerPeriod = 80; initTimerBUpParam.timerInterruptEnable_TBIE = TIMER_B_TBIE_INTERRUPT_ENABLE; initTimerBUpParam.captureCompareInterruptEnable_CCR0_CCIE = TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE; initTimerBUpParam.timerClear = TIMER_B_DO_CLEAR; initTimerBUpParam.startTimer = false; Timer_B_initUpMode(TIMER_B0_BASE, &initTimerBUpParam); Timer_A_clearTimerInterrupt(TIMER_A0_BASE); Timer_B_clearTimerInterrupt(TIMER_B0_BASE); }
void Setup1msTimer(void) { //Start timer in continuous mode sourced by SMCLK //Timer_A_initContinuousModeParam initUpParam = {0}; Timer_A_initUpModeParam initUpParam = {0}; initUpParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; initUpParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; initUpParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE; initUpParam.timerClear = TIMER_A_DO_CLEAR; initUpParam.startTimer = false; Timer_A_initUpMode(TIMER_A1_BASE, &initUpParam); //Initiaze compare mode Timer_A_clearCaptureCompareInterrupt(TIMER_A1_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_0); Timer_A_initCompareModeParam initCompParam = {0}; initCompParam.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_0; initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE; initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE; initCompParam.compareValue = UCS_getSMCLK()/1e3; Timer_A_initCompareMode(TIMER_A1_BASE, &initCompParam); Timer_A_startCounter(TIMER_A1_BASE,TIMER_A_UP_MODE); }
void tempSensorModeInit() { *tempSensorRunning = 1; displayScrollText("TEMPSENSOR MODE"); RTC_stop(RTC_BASE); // Stop stopwatch // Check if any button is pressed Timer_A_initUpMode(TIMER_A0_BASE, &initUpParam_A0); }
void initTimer(void) { setTimer_A_Parameters(); //start timer Timer_A_clearTimerInterrupt(TIMER_A0_BASE); Timer_A_initUpMode(TIMER_A0_BASE, &Timer_A_params); Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_UP_MODE); }
void tempSensor() { //Initialize the ADC Module /* * Base Address for the ADC Module * Use Timer trigger 1 as sample/hold signal to start conversion * USE MODOSC 5MHZ Digital Oscillator as clock source * Use default clock divider of 1 */ ADC_init(ADC_BASE, ADC_SAMPLEHOLDSOURCE_2, ADC_CLOCKSOURCE_ADCOSC, ADC_CLOCKDIVIDER_1); ADC_enable(ADC_BASE); //Configure Memory Buffer /* * Base Address for the ADC Module * Use input A12 Temp Sensor * Use positive reference of Internally generated Vref * Use negative reference of AVss */ ADC_configureMemory(ADC_BASE, ADC_INPUT_TEMPSENSOR, ADC_VREFPOS_INT, ADC_VREFNEG_AVSS); ADC_clearInterrupt(ADC_BASE, ADC_COMPLETED_INTERRUPT); // Enable the Memory Buffer Interrupt ADC_enableInterrupt(ADC_BASE, ADC_COMPLETED_INTERRUPT); ADC_startConversion(ADC_BASE, ADC_REPEATED_SINGLECHANNEL); // Enable internal reference and temperature sensor PMM_enableInternalReference(); PMM_enableTempSensor(); // TimerA1.1 (125ms ON-period) - ADC conversion trigger signal Timer_A_initUpMode(TIMER_A1_BASE, &initUpParam_A1); //Initialize compare mode to generate PWM1 Timer_A_initCompareMode(TIMER_A1_BASE, &initCompParam); // Start timer A1 in up mode Timer_A_startCounter(TIMER_A1_BASE, TIMER_A_UP_MODE ); // Delay for reference settling __delay_cycles(300000); //Enter LPM3.5 mode with interrupts enabled while(*tempSensorRunning) { __bis_SR_register(LPM3_bits | GIE); // LPM3 with interrupts enabled __no_operation(); // Only for debugger if (*tempSensorRunning) { // Turn LED1 on when waking up to calculate temperature and update display P1OUT |= BIT0; // Calculate Temperature in degree C and F signed short temp = (ADCMEM0 - CALADC_15V_30C); *degC = ((long)temp * 10 * (85-30) * 10)/((CALADC_15V_85C-CALADC_15V_30C)*10) + 300; *degF = (*degC) * 9 / 5 + 320; // Update temperature on LCD displayTemp(); P1OUT &= ~BIT0; } } // Loop in LPM3 to while buttons are held down and debounce timer is running while(TA0CTL & MC__UP) { __bis_SR_register(LPM3_bits | GIE); // Enter LPM3 __no_operation(); } if (*mode == TEMPSENSOR_MODE) { // Disable ADC, TimerA1, Internal Ref and Temp used by TempSensor Mode ADC_disableConversions(ADC_BASE,ADC_COMPLETECONVERSION); ADC_disable(ADC_BASE); Timer_A_stop(TIMER_A1_BASE); PMM_disableInternalReference(); PMM_disableTempSensor(); PMM_turnOffRegulator(); __bis_SR_register(LPM4_bits | GIE); // re-enter LPM3.5 __no_operation(); } }