单片机类毕业设计外文翻译内容摘要:

0, 3, ADC_CTL_CH1)。 ADCSequenceStepConfigure(ADC_BASE, 0, 4, ADC_CTL_CH1)。 ADCSequenceStepConfigure(ADC_BASE, 0, 5, ADC_CTL_CH1)。 ADCSequenceStepConfigure(ADC_BASE, 0, 6, ADC_CTL_CH1)。 ADCSequenceStepConfigure(ADC_BASE, 0, 7, (ADC_CTL_CH1 | ADC_CTL_END))。 // // Configure sequence steps for sequencer 1 // ADCSequenceStepConfigure(ADC_BASE, 1, 0, ADC_CTL_CH1)。 ADCSequenceStepConfigure(ADC_BASE, 1, 1, ADC_CTL_CH1)。 ADCSequenceStepConfigure(ADC_BASE, 1, 2, ADC_CTL_CH1)。 ADCSequenceStepConfigure(ADC_BASE, 1, 3, (ADC_CTL_CH1 | ADC_CTL_END))。 // // Configure sequence steps for sequencer 2 // ADCSequenceStepConfigure(ADC_BASE, 2, 0, ADC_CTL_CH1)。 ADCSequenceStepConfigure(ADC_BASE, 2, 1, ADC_CTL_CH1)。 ADCSequenceStepConfigure(ADC_BASE, 2, 2, ADC_CTL_CH1)。 ADCSequenceStepConfigure(ADC_BASE, 2, 3, (ADC_CTL_CH1 | ADC_CTL_IE \ | ADC_CTL_END))。 In Code Segment , the interrupt handler must gather the data from the FIFOs and perform the averaging calculation. The ADC Sequence Data Get function is not used here since the desired results are obtained without having to deal with the function overhead, so direct register reads are used to empty the sequencer FIFOs. Using ADC Sequence Data Get requires the function to define an extra 8entry sample buffer. Even with direct register reads, there is still putational overhead from the sum and average calculations performed in the interrupt handler. Code Segment . ADC Interrupt Handler void ADCIntHandler(void) { unsigned long ulIdx。 unsigned long ulSum = 0。 // // Clear the interrupt // ADCIntClear(ADC_BASE, 2)。 // // Get the data from sequencer 0 // for(ulIdx = 8。 ulIdx。 ulIdx) 9 { ulSum += HWREG(ADC_BASE + ADC_O_SSFIFO0)。 } // // Get the data from sequencers 1 and 2 // for(ulIdx = 4。 ulIdx。 ulIdx) { ulSum += HWREG(ADC_BASE + ADC_O_SSFIFO1)。 ulSum += HWREG(ADC_BASE + ADC_O_SSFIFO2)。 } // // Average the oversampled data // g_ulAverage = ulSum 4。 // // Placeholder for ADC processing code // } Before initiating the conversion process, the sample sequencers and interrupts are enabled (see Code Segment ). Code Segment . Enabling the ADC and Interrupts // // Enable the sequencers and interrupt // ADCSequenceEnable(ADC_BASE, 0)。 ADCSequenceEnable(ADC_BASE, 1)。 ADCSequenceEnable(ADC_BASE, 2)。 ADCIntEnable(ADC_BASE, 2)。 IntEnable(INT_ADC2)。 // // Enable the timer and start conversion process // TimerEnable(TIMER0_BASE, TIMER_A)。 Example 3. 16x Oversampling Using a Timer Running at fOS Another way to over sample (without consuming a large portion of the ADC sequencer resources) is by using a periodic timer that runs at the over sampling frequency. For example, if a conversion must be returned to the main application every 10 ms and is to be over sampled by 16, a timer can be configured to take a single sample every 625 μs. Having the timer trigger a conversion at the over sampling frequency obviously generates additional ADC interrupt traffic, which must 10 be accounted for in the application. The code that configures the ADC and timer to operate like this is shown in Code Segment . Code Segment . ADC Configuration – Timer Running at fOS // // Initialize the ADC to take a single sample on channel 1, sequencer 3 // when a trigger is detected. // ADCSequenceConfigure(ADC_BASE, 3, ADC_TRIGGER_TIMER, 0)。 ADCSequenceStepConfigure(ADC_BASE, 3, 0, (ADC_CTL_CH1 | ADC_CTL_IE \ | ADC_CTL_END))。 // // Initialize Timer 0 to trigger an ADC conversion once every 625 microseconds // TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER)。 TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet() / 1600)。 TimerControlTrigger(TIMER0_BASE, TIMER_A, true)。 Now that the ADC is sampling at the over sampling frequency, the interrupt handler must keep track of the number of samples taken and the overall sum (see Code Segment ). When 16 conversions have been accumulated, the averaging is performed and the global sample count and sum variables are cleared. Code Segment . ADC Interrupt Handler void ADCIntHandler(void) { // // Clear the interrupt // ADCIntClear(ADC_BASE, 3)。 // // Add the new sample to the global sum // g_ulSum += HWREG(ADC_BASE + ADC_O_SSFIFO3)。 // // Increment g_ucOversampleCnt // g_ucOversampleCnt++。 // // If 16 samples have accumulated, average them and reset globals // if(g_ucOversampleCnt == 16) { 11 g_ulAverage = g_ulSum 4。 g_ucOversampleCnt = 0。 g_ulSum = 0。 } // // Placeholder for ADC processing code // } Finally, before enabling the timer, sequencer 3 and its interrupt are enabled, and the global counter and sum variables are cleared (see Code Segment ). Code Segment . Enabling the ADC, Interrupts and Global Variables // // Enable the sequencer and interrupt // ADCSequenceEnable(ADC_BASE, 3)。 ADCIntEnable(ADC_BASE, 3)。 IntEnable(INT_ADC3)。 // // Zero the oversample counter and the sum // g_ucOversampleCnt = 0。 g_ulSum = 0。 // // Enable the timer and start conversion process // TimerEnable(TIMER0_BASE, TIMER_A)。 Over sampling Using a Rolling Average The rolling average approach is useful in situations where the sampling frequency is closer to the maximum sample rate of the ADC. The main ponent of a rolling average application is the sample buffer, which drops/adds data each time a conversion pletes. In Example 4, the ADC is configured to sample once every 100 μs,。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。