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 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(); } }