Question: const Timer _ A _ UpModeConfig upModeConfig = { TIMER _ A _ CLOCKSOURCE _ SMCLK , / / SMCLK Clock Source ( use SMCLK
const TimerAUpModeConfig upModeConfig TIMERACLOCKSOURCESMCLK SMCLK Clock Source use SMCLK for higher frequency TIMERACLOCKSOURCEDIVIDER SMCLK kHz if SMCLK MHz Count to Timer period TIMERATAIEINTERRUPTDISABLE, Disable Timer ISR TIMERACCIECCRINTERRUPTDISABLE, Disable CCR TIMERADOCLEAR Clear Timer Counter ; const TimerACompareModeConfig compareConfig TIMERACAPTURECOMPAREREGISTER Use CCR TIMERACAPTURECOMPAREINTERRUPTDISABLE, Disable CCR interrupt TIMERAOUTPUTMODESETRESET, Toggle output but Period ; Statics static volatile uintfastt resultsBufferUINTMAX; static volatile uintt resPos; volatile uintt latestADCValue; volatile uintt sampleCount ; #define SAMPLINGFREQUENCY Desired ADC sampling frequency Hz Variables for timing measurement volatile uintt timerStartValue ; volatile uintt timerEndValue ; int mainvoid Halting WDT Watchdog Timer MAPWDTAholdTimer; Initializing ADC module MAPCSinitClockSignalCSACLK, CSREFOCLKSELECT, CSCLOCKDIVIDER; MAPGPIOsetAsPeripheralModuleFunctionInputPinGPIOPORTP GPIOPIN GPIOTERTIARYMODULEFUNCTION; MAPADCconfigureConversionMemoryADCMEM ADCVREFPOSAVCCVREFNEGVSS ADCINPUTA false; Initializing ADC MCLK MAPADCenableModule; MAPADCinitModuleADCCLOCKSOURCEMCLK ADCPREDIVIDER ADCDIVIDER; Configuring GPIOs A MAPGPIOsetAsPeripheralModuleFunctionInputPinGPIOPORTP GPIOPIN GPIOTERTIARYMODULEFUNCTION; Configuring ADC Memory MAPADCconfigureSingleSampleModeADCMEM true; MAPADCconfigureConversionMemoryADCMEM ADCVREFPOSAVCCVREFNEGVSS ADCINPUTA false; Configuring TimerA in continuous mode and sourced from ACLK MAPTimerAconfigureUpModeTIMERABASE, &upModeConfig; Configuring TimerA in CCR to trigger at s MAPTimerAinitCompareTIMERABASE, &compareConfig; Configuring the sample trigger to be sourced from TimerA and setting it to automatic iteration after it is triggered MAPADCsetSampleHoldTriggerADCTRIGGERSOURCE false; Enabling the interrupt when a conversion on channel is complete and enabling conversions MAPADCenableInterruptADCINT; MAPADCenableConversion; Enabling Interrupts MAPInterruptenableInterruptINTADC; MAPInterruptenableMaster; Starting the Timer MAPTimerAstartCounterTIMERABASE, TIMERAUPMODE; Start the ADC conversion for the first sample sampleCount ; Reset the sample count MAPADCenableConversion; Wait until samples are collected while sampleCount Wait for the interrupt handler to collect samples Stop TimerA after collecting samples timerEndValue MAPTimerAgetCounterValueTIMERABASE; MAPTimerAstartCounterTIMERABASE, TIMERAUPMODE;; uintt adcvalue ADCgetResultADCMEM; printff adcvalue; Calculate and print the measured sampling frequency uintt timeTaken timerStartValue timerEndValue; float actualFrequency floattimeTaken ; Timer value converted to seconds printfMeasured Sampling Frequency: f Hz
actualFrequency; printf u
latestADCValue; Now enter the control loop while float voltage latestADCValue ; Display ADC value and voltage in mV printfADC Value: u Voltage: f mV
latestADCValue, voltage; Delay to slow down the printing eg msdelaycycles; This interrupt is fired whenever a conversion is completed and placed in ADCMEM void ADCIRQHandlervoid uintt status; Get the status of enabled interrupts status MAPADCgetEnabledInterruptStatus; MAPADCclearInterruptFlagstatus; Check if the ADC interrupt is for ADCMEMconversion complete if status & ADCINT If this is the first sample, start TimerA if sampleCount timerStartValue MAPTimerAgetCounterValueTIMERABASE; TimerA start value Update the global variable with the latest ADC result latestADCValue ADCgetResultADCMEM; 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
