Question: const Timer _ A _ UpModeConfig upModeConfig = { TIMER _ A _ CLOCKSOURCE _ SMCLK , / / SMCLK Clock Source ( use SMCLK

const Timer_A_UpModeConfig upModeConfig ={ TIMER_A_CLOCKSOURCE_SMCLK,// SMCLK Clock Source (use SMCLK for higher frequency) TIMER_A_CLOCKSOURCE_DIVIDER_8,// SMCLK /8(375kHz if SMCLK =3MHz)16384,// Count to 16384(Timer period) TIMER_A_TAIE_INTERRUPT_DISABLE, // Disable Timer ISR TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE, // Disable CCR0 TIMER_A_DO_CLEAR // Clear Timer Counter }; const Timer_A_CompareModeConfig compareConfig ={ TIMER_A_CAPTURECOMPARE_REGISTER_1,// Use CCR1 TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE, // Disable CCR interrupt TIMER_A_OUTPUTMODE_SET_RESET, // Toggle output but 16384//16000 Period }; /* Statics */ static volatile uint_fast16_t resultsBuffer[UINT8_MAX]; static volatile uint8_t resPos; volatile uint32_t latestADCValue; volatile uint8_t sampleCount =0; #define SAMPLING_FREQUENCY 32// Desired ADC sampling frequency (Hz)// Variables for timing measurement volatile uint32_t timerStartValue =0; volatile uint32_t timerEndValue =0; int main(void){// Halting WDT (Watchdog Timer) MAP_WDT_A_holdTimer(); // Initializing ADC module MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1); MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5, GPIO_TERTIARY_MODULE_FUNCTION); MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A0, false); /* Initializing ADC (MCLK/1/1)*/ MAP_ADC14_enableModule(); MAP_ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,0); /* Configuring GPIOs (5.5 A0)*/ MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, GPIO_PIN5, GPIO_TERTIARY_MODULE_FUNCTION); /* Configuring ADC Memory */ MAP_ADC14_configureSingleSampleMode(ADC_MEM0, true); MAP_ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A0, false); /* Configuring Timer_A in continuous mode and sourced from ACLK */ MAP_Timer_A_configureUpMode(TIMER_A0_BASE, &upModeConfig); /* Configuring Timer_A0 in CCR1 to trigger at 16000(0.5s)*/ MAP_Timer_A_initCompare(TIMER_A0_BASE, &compareConfig); /* Configuring the sample trigger to be sourced from Timer_A0 and setting it * to automatic iteration after it is triggered*/ MAP_ADC14_setSampleHoldTrigger(ADC_TRIGGER_SOURCE1, false); /* Enabling the interrupt when a conversion on channel 1 is complete and * enabling conversions */ MAP_ADC14_enableInterrupt(ADC_INT0); MAP_ADC14_enableConversion(); /* Enabling Interrupts */ MAP_Interrupt_enableInterrupt(INT_ADC14); MAP_Interrupt_enableMaster(); /* Starting the Timer */ MAP_Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_UP_MODE); // Start the ADC conversion for the first sample sampleCount =0; // Reset the sample count MAP_ADC14_enableConversion(); // Wait until 10 samples are collected while (sampleCount <10){// Wait for the interrupt handler to collect 10 samples }// Stop Timer_A after collecting 10 samples timerEndValue = MAP_Timer_A_getCounterValue(TIMER_A0_BASE); MAP_Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_UP_MODE);; uint32_t adc_value = ADC14_getResult(ADC_MEM0); printf("%f", adc_value); // Calculate and print the measured sampling frequency uint32_t timeTaken = timerStartValue - timerEndValue; float actualFrequency =10.0/((float)timeTaken /32000.0); // Timer value converted to seconds printf("Measured Sampling Frequency: %.2f Hz
", actualFrequency); printf ("%u
", latestADCValue); // Now enter the control loop while (1){ float voltage =(latestADCValue /16384.0)*1200.0; // Display ADC value and voltage in mV printf("ADC Value: %u, Voltage: %.3f mV
", latestADCValue, voltage); // Delay to slow down the printing (e.g.,500 ms)__delay_cycles(1500000); }}/* This interrupt is fired whenever a conversion is completed and placed in * ADC_MEM0*/ void ADC14_IRQHandler(void){ uint64_t status; // Get the status of enabled interrupts status = MAP_ADC14_getEnabledInterruptStatus(); MAP_ADC14_clearInterruptFlag(status); // Check if the ADC interrupt is for ADC_MEM0(conversion complete) if (status & ADC_INT0){// If this is the first sample, start Timer_A if (sampleCount ==0){ timerStartValue = MAP_Timer_A_getCounterValue(TIMER_A0_BASE); // Timer_A start value }// Update the global variable with the latest ADC result latestADCValue = ADC14_getResult(ADC_MEM0); // Im trying to implement this ,but the adc value keep getting zero instead of. Can you guys help me?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!