【正文】
L_IE \ | ADC_CTL_END))。 g_ucOversampleCnt = 0。 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, and the sample buffer contains 16 entries. Note that the application does not prefill the sample buffer with valid data, so the first 16 samples must be handled accordingly by software. The ADC is configured to sample on a timer trigger, and interrupts the processor after every conversion. Example 4. Over sampling Using a Rolling Average Every 100 Microseconds Code Segment . ADC Configuration – Rolling Average // 12 // 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)。 // // Replace the oldest value with the new sample value // g_ulSampleBuffer[g_ucOversampleIdx] = HWREG(ADC_BASE + ADC_O_SSFIFO3)。 Issues to Consider The over sampling techniques described in this document have an obvious impact on overall system performance since they require additional code to perform the averaging calculations, additional interrupts, and/or most of the sample sequencer resources. Choosing the technique that best suits the application requires analyzing the tradeoffs between increased interrupt traffic and bulkier interrupt handlers. Conclusion Luminary Micro39。 當(dāng) 提高每一個位的精確度 時 ,信號過采樣系數(shù) 必須為 4, 過采樣頻率 fos和采樣頻率之間的關(guān)系 見公式 2所示 公式 2:過采樣頻率計(jì)算公式 fOS = 4X*fs 圖 1 顯示了過采樣是如何 提高轉(zhuǎn)換結(jié)果 的 精度 的。當(dāng)正常平均的計(jì)算方法應(yīng)用于采樣后,執(zhí)行過后,會丟棄原來的樣本數(shù)據(jù)。 延遲可以 由公式 3計(jì)算 得出。圖示的例子中有 4 組抽樣作為輸入信號,即樣品緩沖區(qū)用 4 來計(jì)算樣品平均值。 這里所有的例子的代碼都 來自 Stellaris 系列驅(qū)動程序庫的 ADC 功能。 例 1 采樣次數(shù)為 8 次的過采樣的驅(qū)動程序 代碼段 . 模數(shù)轉(zhuǎn)換器配置 驅(qū)動程序庫功能 // // Initialize the ADC to oversample channel 1 by 8x using sequencer 0. // Sequencer will be triggered by one of the generalpurpose timers. // 19 ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_TIMER, 0)。記住在每個中斷期間的用于計(jì)算開銷的中斷處理程序。 ADCIntEnable(ADC_BASE, 0)。對于這一水平的過采樣工作,所有這一序列中的定序器必須應(yīng)用同一樣本的模擬輸入,這意味著,使用多個模擬輸入的定序器失去了作用。 ADCSequenceStepConfigure(ADC_BASE, 0, 2, ADC_CTL_CH1)。 ADCSequenceStepConfigure(ADC_BASE, 1, 2, ADC_CTL_CH1)。利用 ADC 的獲取序列數(shù)據(jù)功能來定義一個額外的 8通道樣品緩沖區(qū)。 } // // Get the data from sequencers 1 and 2 // for(ulIdx = 4。 ADCIntEnable(ADC_BASE, 2)。 配置 ADC 和操作定時器的代碼見代碼段 代碼段 A。 ADCSequenceEnable(ADC_BASE, 1)。 ulIdx。 在代碼段 中斷處理程序必須從該先進(jìn)先出 (FIFO) 隊(duì)列收集數(shù)據(jù),并執(zhí)行平均計(jì)算。 // // Configure sequence steps for sequencer 1 // 22 ADCSequenceStepConfigure(ADC_BASE, 1, 0, ADC_CTL_CH1)。 // // Configure sequence steps for sequencer 0 // ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_CH1)。 例 2 運(yùn)用多重定序器情況下采樣次數(shù)為 16 次的過 采樣 靈活的采樣序列生成器允許各種各樣的配置。在定時器開始運(yùn)行(開始計(jì)時)之前, ADC 定序程序與中斷處理程序必須啟用(見代碼段)。 當(dāng)采樣完成時 ADC 的配置中顯示代碼段 發(fā)出中斷指令,意味著中斷處理程序必須執(zhí)行(見代碼段 )。一旦 ADC 轉(zhuǎn)換過程被確定( ADC 采樣頻率、觸發(fā)源、通道等),可以直接寫出代碼。 本章節(jié)介紹了使用 Stellaris 微控制器實(shí)現(xiàn)過采樣的各種方法。如果緩沖區(qū)的填充被軟件清除,說明第 n1個樣品被更改。在這個例子中,應(yīng)用程序完成每一步時都需要一個新的準(zhǔn)備轉(zhuǎn)換價值 t(平均)( t0, t1, t2,等等)。求 轉(zhuǎn)換結(jié)果 的平均值 ,有兩種方法可 使用 :正常平均 和 滾動平均。 過采樣 顧名思義, 過 采樣 就是從 輸入信號 中收集 額外的轉(zhuǎn)換數(shù)據(jù) ,模擬信號采樣的標(biāo)準(zhǔn)公約 表明,采樣頻率 fS至少 為 兩倍 輸入信號的最高的頻率組分 fH, 這 就是 奈奎斯特抽樣定理 (見公式 1) 公式 1:奈奎斯特抽樣定理 fS= 2fH 從以上選定的任何采樣頻率 fS可以看出,當(dāng)過采樣技術(shù)與平均技術(shù)相結(jié)合時 ,會提高有效位數(shù)( ENOB)。 IntEnable(INT_ADC3)。 // // Check g_ucOversampleIdx to make sure that it is within range // if(g_ucOversampleIdx == 16) { g_ucOversampleIdx = 0。 g_ulSum = 0。 // // Increment g_ucOversampleCnt // g_ucOversampleCnt++。 // // Enable the timer and start conversion process // TimerEnable(TIMER0_BASE, TIMER_A)。 ulIdx) { ulSum += HWREG(ADC_BASE + ADC_O_SSFIFO1)。 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。 // // Configure sequence steps for sequencer 1 // ADCSequenceStepConfigure(ADC_BASE, 1, 0, ADC_CTL_CH1)。 // // Configure sequence steps for sequencer 0 // ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_CH1)。g_ulAverage)。 ADCSoftwareOversampleConfigure(ADC_BASE, 0, 8)。 3 bits of accuracy on an individual sample. Note that the averaged values (orange dots) are much closer to the ideal value than most of the single samples. Averaging Averaging acts as a lowpass filter on the input signal, with the pass band of the filter narrowing as the sample size increases. When averaging conversion results, there are two approaches that can be taken: normal average or rolling average. Normal Average Taking n samples, adding them, and dividing the result by n is referred to as a normal average, and is shown in Figure 1. When using normal averaging in an oversampling scenario, after the technique is applied, the sample data used in the calculation is discarded. This process is repeated every time the application needs a new conversion result. Figure 1. Averaged Conversion Results In an application, the normal averaging approach is ideally used in cases where the sampling frequency is low pared to the sampling