資料介紹
一個簡單的匯編程序適合于微處理器實現(xiàn)數(shù)字低通濾波器。
濾波常發(fā)生在模擬世界。不幸的是,在數(shù)字領(lǐng)域,工程師通常主要使用DSP(數(shù)字信號處理器),而不是8位單片機實現(xiàn)濾波。這個情形的發(fā)生,是因為濾波器設(shè)計的算法比大多數(shù)工程師樂于處理的算法更復(fù)雜。而且,數(shù)字濾波需要計算整形數(shù),而不是浮點數(shù)。這引發(fā)了兩個問題。第一,有限位的舍入誤差降低了濾波器響應(yīng),甚至使它不穩(wěn)定。第二,必須用整數(shù)算法處理小數(shù)值。
有幾種方法解決這些問題。例如,可以使用16、32和64位數(shù)的操作,或可以縮放到更好的精度。這些和其他方法通常需要更多的存儲器,造成編程經(jīng)常不適于小型微處理器。文獻研究所示用C語言編寫的數(shù)字濾波固件,與用匯編語言編寫需要更多的存儲器。這個情形對存儲器資源有限的小型微處理器來講,常常是不可接受的。
列表1(程序見英文原文)列出了一個用8位微處理器設(shè)計單極低通數(shù)字濾波器固件的簡單方法。Freescale公司的低端MC68HC908QT2使用匯編編程器,但可以將本設(shè)計方案用于任一型號微處理器,只要其使用的也是標(biāo)準(zhǔn)匯編指令。
將基于廣義Z
變換算法的復(fù)雜設(shè)計方案放在一邊,本方案使用了一種基于遞歸方程的解決辦法。計算每個輸出信號采樣,作為輸入信號和前一個輸出信號帶相關(guān)系數(shù)的總和。遞歸方程定義一個單極低通濾波器為:Y[n]=X[n]×a0+Y[n–1]×b1,在這里X[n]和Y[n]為采樣[n]的輸入輸出值,Y[n–1]為前一采樣[n–1]的輸出值,a0和b1為減少δ控制的權(quán)重系數(shù)。系數(shù)為0《δ《1的值,a0=1–δ且b1=δ。理論上,δ為輸入信號從高電平降到低電平時,鄰近的輸出采樣之間的衰減量??梢灾苯又付é闹祷蛘业綖V波器所需的時間常數(shù)d,其為采樣數(shù)上升到低通濾波器穩(wěn)態(tài)63.2%時的輸出。D和δ之間存在確定的關(guān)系:δ=e–1/d,在這里e為自然對數(shù)基底。前面的公式服從Y[n]=Y[n–1]+(1–δ)×(X[n]–Y[n–1])。
為取代小數(shù)相乘,1–δ對匯編程序而言,用除以倒數(shù)為整數(shù)的方法更方便,F(xiàn)=1/(1–δ): Y[n]=Y[n–1]+(X[n]–Y[n–1])/F。因此,可以按照下面的步驟確定數(shù)字濾波器參數(shù):
1、選擇參數(shù)F。對匯編程序而言,便于用右移實現(xiàn)除法運算。右移就是F值應(yīng)該為2S,在此S為偏移數(shù)。讓F為8,相當(dāng)于右移三位。
2、計算衰減:δ=1–1/F=1–1/8=0.875。
3、計算時間常數(shù)d=–1/lnδ=–1/ln0.875=7.49采樣。
公式Y(jié)[n]=Y[n–1]+(X[n]–Y[n–1])/F決定濾波器的微處理器算法設(shè)計。算法需要三個寄存器:輸入X[n]、輸出Y[n]和一個遞增寄存器保存(X[n]–Y[n–1])/F的值。三個寄存器的大小取決于輸入。應(yīng)用中,內(nèi)置的8位ADC輸出范圍從00到$FF的信號,必須經(jīng)歷低通濾波器。所以輸入和輸出寄存器均為1個字節(jié)。為增加除法精度,增加一半除數(shù)到被除數(shù)。這個處理將遞增寄存器增加到2個字節(jié)。
用數(shù)字方法實現(xiàn)濾波功能提供了一致性的好處,因為器件誤差、溫度漂移和老化不會影響濾波器算法。用微處理器實現(xiàn)數(shù)字濾波器,增加了可調(diào)整濾波器參數(shù)的靈活性優(yōu)勢,因為這個靈活性僅取決于固件。
英文原文:
8-bit microcontroller implements digital lowpass filter
A simple assembler routine fits a digital lowpass filter into a microcontroller.
Abel Raynus, Armatron International, Malden, MA; Edited by Charles H Small and Fran Granville -- EDN, 1/24/2008
Filtering occurs frequently in the analog world. Unfortunately, in the digital world, engineers apply it mainly to the DSPs (digital-signal processors) and not to the small 8-bit microcontrollers that designers commonly use. This situation occurs because the math for the filter design is more complicated than most engineers are willing to deal with. Moreover, digital filtering requires calculations on integers instead of on floating-point numbers. This scenario causes two problems. First, the rounding-off error from the limited number of bits can degrade the filter response or even make it unstable. Second, you must handle the fractional values with integer math.
Several ways exist to solve these issues. For example, you can use operations with 16-, 32-, and 64-bit numbers, or you can scale for better accuracy. These and other methods usually require more memory, and, as a result, the program often does not fit into a small microcontroller. A literature search shows that published digital-filter firmware is written in C. Programs in C need more memory than those written in assembler. This situation often makes them unacceptable for small microcontrollers with limited memory resources.
Listing 1 shows a simple engineering method to design single-pole, lowpass-digital-filter firmware for 8-bit microcontrollers. The low-end Freescale MC68HC908QT2 is the target of the assembler program, but you can apply this Design Idea to any type of microcontroller because it uses only standard assembler instructions.
Leaving aside the sophisticated design methods based on Z transformation with its extensive math, this idea uses another approach based on a recursive equation. You calculate each output-signal sample as the sum of the input signal and the previous output signal with corresponding coefficients. A recursive equation defines a single-pole lowpass filter as: Y[n]=X[n]×a0+Y[n–1]×b1, where X[n] and Y[n] are input and output values of sample [n], Y[n–1] is an output value of the previous sample [n–1], and a0 and b1 are weight coefficients that decrement δ controls. The coefficients have the value of 0《δ《1, a0=1–δ, and b1=δ。 Physically, δ is the amount of decay between adjacent output samples when the input signal drops from a high level to a low level. You can directly specify the value of δ or find it from the desired time constant of the filter, d, which is the number of samples it takes the output to rise to 63.2% of the steady-state level for a lowpass filter. A fixed relationship exists between d and δ: δ=e–1/d, where e is the base of natural logarithms. The preceding equations yield Y[n]=Y[n–1]+(1–δ)×(X[n]–Y[n–1])。
Instead of multiplying a decimal-point number, 1–δ, it is more convenient for assembler programming to divide by the reciprocal integer, F=“1/”(1–δ): Y[n]=Y[n–1]+(
X[n]–Y[n–1])/F. Thus, you can determine the digital filter’s parameters using the following steps:
Choose the parameter F. For assembler, it is convenient to perform division as right shifts. For right shifts, the value of F should be 2S, where S is the number of shifts. Let F equal 8, which you reach after three right shifts.
Calculate the decrement: δ=1–1/F=1–1/8=0.875.
Calculate the time constant as d=–1/lnδ=–1/ln0.875=7.49 samples.
The equation Y[n]=Y[n–1]+(X[n]–Y[n–1])/F determines the design of the microcontroller’s algorithm for the filter. The algorithm needs three registers: input for X[n], output for Y[n], and an increment register to keep the (X[n]–Y[n–1])/F term. The size of these registers depends on the inputs. In this application, the signals from the built-in 8-bit ADC range from 00 to $FF and must go through the lowpass filter. So, the input and the output registers are 1 byte in size. To increase the accuracy of division, add half the divisor to the dividend. This action increases the increment register to 2 bytes.
Numerically performing the filtering function provides the benefit of consistency because component tolerances, temperature drift, and aging do not affect the filter’s algorithm. The implementation of the digital filter in the microcontroller gives the additional benefit of flexibility to adjust the filter’s parameters, because this flexibility depends only on the firmware.
?
濾波常發(fā)生在模擬世界。不幸的是,在數(shù)字領(lǐng)域,工程師通常主要使用DSP(數(shù)字信號處理器),而不是8位單片機實現(xiàn)濾波。這個情形的發(fā)生,是因為濾波器設(shè)計的算法比大多數(shù)工程師樂于處理的算法更復(fù)雜。而且,數(shù)字濾波需要計算整形數(shù),而不是浮點數(shù)。這引發(fā)了兩個問題。第一,有限位的舍入誤差降低了濾波器響應(yīng),甚至使它不穩(wěn)定。第二,必須用整數(shù)算法處理小數(shù)值。
有幾種方法解決這些問題。例如,可以使用16、32和64位數(shù)的操作,或可以縮放到更好的精度。這些和其他方法通常需要更多的存儲器,造成編程經(jīng)常不適于小型微處理器。文獻研究所示用C語言編寫的數(shù)字濾波固件,與用匯編語言編寫需要更多的存儲器。這個情形對存儲器資源有限的小型微處理器來講,常常是不可接受的。
列表1(程序見英文原文)列出了一個用8位微處理器設(shè)計單極低通數(shù)字濾波器固件的簡單方法。Freescale公司的低端MC68HC908QT2使用匯編編程器,但可以將本設(shè)計方案用于任一型號微處理器,只要其使用的也是標(biāo)準(zhǔn)匯編指令。
將基于廣義Z
變換算法的復(fù)雜設(shè)計方案放在一邊,本方案使用了一種基于遞歸方程的解決辦法。計算每個輸出信號采樣,作為輸入信號和前一個輸出信號帶相關(guān)系數(shù)的總和。遞歸方程定義一個單極低通濾波器為:Y[n]=X[n]×a0+Y[n–1]×b1,在這里X[n]和Y[n]為采樣[n]的輸入輸出值,Y[n–1]為前一采樣[n–1]的輸出值,a0和b1為減少δ控制的權(quán)重系數(shù)。系數(shù)為0《δ《1的值,a0=1–δ且b1=δ。理論上,δ為輸入信號從高電平降到低電平時,鄰近的輸出采樣之間的衰減量??梢灾苯又付é闹祷蛘业綖V波器所需的時間常數(shù)d,其為采樣數(shù)上升到低通濾波器穩(wěn)態(tài)63.2%時的輸出。D和δ之間存在確定的關(guān)系:δ=e–1/d,在這里e為自然對數(shù)基底。前面的公式服從Y[n]=Y[n–1]+(1–δ)×(X[n]–Y[n–1])。
為取代小數(shù)相乘,1–δ對匯編程序而言,用除以倒數(shù)為整數(shù)的方法更方便,F(xiàn)=1/(1–δ): Y[n]=Y[n–1]+(X[n]–Y[n–1])/F。因此,可以按照下面的步驟確定數(shù)字濾波器參數(shù):
1、選擇參數(shù)F。對匯編程序而言,便于用右移實現(xiàn)除法運算。右移就是F值應(yīng)該為2S,在此S為偏移數(shù)。讓F為8,相當(dāng)于右移三位。
2、計算衰減:δ=1–1/F=1–1/8=0.875。
3、計算時間常數(shù)d=–1/lnδ=–1/ln0.875=7.49采樣。
公式Y(jié)[n]=Y[n–1]+(X[n]–Y[n–1])/F決定濾波器的微處理器算法設(shè)計。算法需要三個寄存器:輸入X[n]、輸出Y[n]和一個遞增寄存器保存(X[n]–Y[n–1])/F的值。三個寄存器的大小取決于輸入。應(yīng)用中,內(nèi)置的8位ADC輸出范圍從00到$FF的信號,必須經(jīng)歷低通濾波器。所以輸入和輸出寄存器均為1個字節(jié)。為增加除法精度,增加一半除數(shù)到被除數(shù)。這個處理將遞增寄存器增加到2個字節(jié)。
用數(shù)字方法實現(xiàn)濾波功能提供了一致性的好處,因為器件誤差、溫度漂移和老化不會影響濾波器算法。用微處理器實現(xiàn)數(shù)字濾波器,增加了可調(diào)整濾波器參數(shù)的靈活性優(yōu)勢,因為這個靈活性僅取決于固件。
英文原文:
8-bit microcontroller implements digital lowpass filter
A simple assembler routine fits a digital lowpass filter into a microcontroller.
Abel Raynus, Armatron International, Malden, MA; Edited by Charles H Small and Fran Granville -- EDN, 1/24/2008
Filtering occurs frequently in the analog world. Unfortunately, in the digital world, engineers apply it mainly to the DSPs (digital-signal processors) and not to the small 8-bit microcontrollers that designers commonly use. This situation occurs because the math for the filter design is more complicated than most engineers are willing to deal with. Moreover, digital filtering requires calculations on integers instead of on floating-point numbers. This scenario causes two problems. First, the rounding-off error from the limited number of bits can degrade the filter response or even make it unstable. Second, you must handle the fractional values with integer math.
Several ways exist to solve these issues. For example, you can use operations with 16-, 32-, and 64-bit numbers, or you can scale for better accuracy. These and other methods usually require more memory, and, as a result, the program often does not fit into a small microcontroller. A literature search shows that published digital-filter firmware is written in C. Programs in C need more memory than those written in assembler. This situation often makes them unacceptable for small microcontrollers with limited memory resources.
Listing 1 shows a simple engineering method to design single-pole, lowpass-digital-filter firmware for 8-bit microcontrollers. The low-end Freescale MC68HC908QT2 is the target of the assembler program, but you can apply this Design Idea to any type of microcontroller because it uses only standard assembler instructions.
Leaving aside the sophisticated design methods based on Z transformation with its extensive math, this idea uses another approach based on a recursive equation. You calculate each output-signal sample as the sum of the input signal and the previous output signal with corresponding coefficients. A recursive equation defines a single-pole lowpass filter as: Y[n]=X[n]×a0+Y[n–1]×b1, where X[n] and Y[n] are input and output values of sample [n], Y[n–1] is an output value of the previous sample [n–1], and a0 and b1 are weight coefficients that decrement δ controls. The coefficients have the value of 0《δ《1, a0=1–δ, and b1=δ。 Physically, δ is the amount of decay between adjacent output samples when the input signal drops from a high level to a low level. You can directly specify the value of δ or find it from the desired time constant of the filter, d, which is the number of samples it takes the output to rise to 63.2% of the steady-state level for a lowpass filter. A fixed relationship exists between d and δ: δ=e–1/d, where e is the base of natural logarithms. The preceding equations yield Y[n]=Y[n–1]+(1–δ)×(X[n]–Y[n–1])。
Instead of multiplying a decimal-point number, 1–δ, it is more convenient for assembler programming to divide by the reciprocal integer, F=“1/”(1–δ): Y[n]=Y[n–1]+(
X[n]–Y[n–1])/F. Thus, you can determine the digital filter’s parameters using the following steps:
Choose the parameter F. For assembler, it is convenient to perform division as right shifts. For right shifts, the value of F should be 2S, where S is the number of shifts. Let F equal 8, which you reach after three right shifts.
Calculate the decrement: δ=1–1/F=1–1/8=0.875.
Calculate the time constant as d=–1/lnδ=–1/ln0.875=7.49 samples.
The equation Y[n]=Y[n–1]+(X[n]–Y[n–1])/F determines the design of the microcontroller’s algorithm for the filter. The algorithm needs three registers: input for X[n], output for Y[n], and an increment register to keep the (X[n]–Y[n–1])/F term. The size of these registers depends on the inputs. In this application, the signals from the built-in 8-bit ADC range from 00 to $FF and must go through the lowpass filter. So, the input and the output registers are 1 byte in size. To increase the accuracy of division, add half the divisor to the dividend. This action increases the increment register to 2 bytes.
Numerically performing the filtering function provides the benefit of consistency because component tolerances, temperature drift, and aging do not affect the filter’s algorithm. The implementation of the digital filter in the microcontroller gives the additional benefit of flexibility to adjust the filter’s parameters, because this flexibility depends only on the firmware.
?
下載該資料的人也在下載
下載該資料的人還在閱讀
更多 >
- 兆易創(chuàng)新AN013 CLA方波濾波器設(shè)計方案
- 帶通濾波器到低通濾波器的轉(zhuǎn)換公式推導(dǎo)資料合集 45次下載
- 簡易LC濾波器設(shè)計方案 76次下載
- 低通濾波器的設(shè)計與實現(xiàn) 77次下載
- 微波:糖葫蘆低通濾波器的詳細設(shè)計方案
- 典型低通濾波器的設(shè)計方案匯總 55次下載
- 基于CMOS的數(shù)字濾波器的設(shè)計 62次下載
- 基于AVR微處理器的程控濾波器設(shè)計 78次下載
- 有源濾波器中數(shù)字低通濾波器的設(shè)計及其DSP實現(xiàn)
- 用于諧波檢測中的數(shù)字低通濾波器的設(shè)計
- 利用數(shù)字電位器實現(xiàn)數(shù)控低通濾波器
- 利用數(shù)字電位器實現(xiàn)數(shù)控低通濾波器
- 數(shù)字低通濾波器的設(shè)計與應(yīng)用
- 低通濾波器設(shè)計
- 低通濾波器傳遞函數(shù)
- 低通濾波器、高通濾波器、帶通濾波器的簡單介紹 3313次閱讀
- 有源低通濾波器的原理及作用 1820次閱讀
- 高通濾波器和低通濾波器的區(qū)別 2847次閱讀
- 低通濾波器的概念、工作原理及分類 5911次閱讀
- 低通濾波器電路圖分享 3817次閱讀
- 有源低通濾波器設(shè)計原理 有源低通濾波器的截止頻率計算 1827次閱讀
- 低通濾波器的帶寬是指什么 2210次閱讀
- 如何判斷高通濾波器和低通濾波器 3699次閱讀
- 低通濾波器(LPF)的定義及應(yīng)用 3.8w次閱讀
- LTCC低通濾波器的設(shè)計解析 7162次閱讀
- 一文看懂二階lc低通濾波器的設(shè)計及原理 21.7w次閱讀
- 基于MATLAB的理想低通濾波器的設(shè)計 3.4w次閱讀
- 數(shù)字低通濾波器的設(shè)計 1.8w次閱讀
- LC低通濾波器作用及應(yīng)用案例 3.9w次閱讀
- 使用FPGA構(gòu)建的數(shù)字濾波器設(shè)計方案 8724次閱讀
下載排行
本周
- 1電子電路原理第七版PDF電子教材免費下載
- 0.00 MB | 1489次下載 | 免費
- 2單片機典型實例介紹
- 18.19 MB | 91次下載 | 1 積分
- 3S7-200PLC編程實例詳細資料
- 1.17 MB | 27次下載 | 1 積分
- 4筆記本電腦主板的元件識別和講解說明
- 4.28 MB | 18次下載 | 4 積分
- 5開關(guān)電源原理及各功能電路詳解
- 0.38 MB | 9次下載 | 免費
- 6基于AT89C2051/4051單片機編程器的實驗
- 0.11 MB | 4次下載 | 免費
- 7基于單片機和 SG3525的程控開關(guān)電源設(shè)計
- 0.23 MB | 3次下載 | 免費
- 8基于單片機的紅外風(fēng)扇遙控
- 0.23 MB | 3次下載 | 免費
本月
- 1OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234313次下載 | 免費
- 2PADS 9.0 2009最新版 -下載
- 0.00 MB | 66304次下載 | 免費
- 3protel99下載protel99軟件下載(中文版)
- 0.00 MB | 51209次下載 | 免費
- 4LabView 8.0 專業(yè)版下載 (3CD完整版)
- 0.00 MB | 51043次下載 | 免費
- 5555集成電路應(yīng)用800例(新編版)
- 0.00 MB | 33562次下載 | 免費
- 6接口電路圖大全
- 未知 | 30319次下載 | 免費
- 7Multisim 10下載Multisim 10 中文版
- 0.00 MB | 28588次下載 | 免費
- 8開關(guān)電源設(shè)計實例指南
- 未知 | 21539次下載 | 免費
總榜
- 1matlab軟件下載入口
- 未知 | 935053次下載 | 免費
- 2protel99se軟件下載(可英文版轉(zhuǎn)中文版)
- 78.1 MB | 537791次下載 | 免費
- 3MATLAB 7.1 下載 (含軟件介紹)
- 未知 | 420026次下載 | 免費
- 4OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234313次下載 | 免費
- 5Altium DXP2002下載入口
- 未知 | 233045次下載 | 免費
- 6電路仿真軟件multisim 10.0免費下載
- 340992 | 191183次下載 | 免費
- 7十天學(xué)會AVR單片機與C語言視頻教程 下載
- 158M | 183277次下載 | 免費
- 8proe5.0野火版下載(中文版免費下載)
- 未知 | 138039次下載 | 免費
評論
查看更多