03.08.2013 Views

Embedded Software and Motor Control Libraries for PXR40xx

Embedded Software and Motor Control Libraries for PXR40xx

Embedded Software and Motor Control Libraries for PXR40xx

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Function GDFLIB_FilterIIR1_F32<br />

main difference between DF-I <strong>and</strong> DF-II implementations of an IIR filter is in the number<br />

of delay buffers <strong>and</strong> in the number of guard bits required to h<strong>and</strong>le the potential overflow.<br />

The DF-II implementation requires less delay buffers than DF-I, hence less data memory<br />

is utilized. On the other h<strong>and</strong>, since the poles come first in the DF-II realization, the<br />

signal entering the state delay-line typically requires a larger dynamic range than the<br />

output signal y(k). There<strong>for</strong>e, overflow can occur at the delay-line input of the DF-II<br />

implementation, unlike in the DF-I implementation.<br />

Because there are two delay buffers necessary <strong>for</strong> both DF-I <strong>and</strong> DF-II implementation of<br />

the first order IIR filter, the DF-I implementation was chosen to be used in the<br />

GDFLIB_FilterIIR1_F32 function.<br />

Figure 4-1. Direct Form 1 first order IIR filter<br />

The coefficients of the filter depicted in Figure 4-1 can be designed to meet the<br />

requirements <strong>for</strong> the first order Low (LPF) or High Pass (HPF) filters. Filter coefficients<br />

can be calculated using various tools, <strong>for</strong> example, the Matlab butter function. In order to<br />

avoid overflow during the calculation of the GDFLIB_FilterIIR1_F32 function, filter<br />

coefficients must be divided by eight. The coefficient quantization error due to finite<br />

precision arithmetic can be neglected in the case of a first order filter. There<strong>for</strong>e, the<br />

calculation of coefficients can be done using Matlab as follows:<br />

freq_cut = 100;<br />

T_sampling = 100e-6;<br />

[b,a]=butter(1,[freq_cut*T_sampling*2],'low');<br />

sys=tf(b,a,T_sampling);<br />

bode(sys)<br />

f32B0 = b(1)/8;<br />

f32B1 = b(2)/8;<br />

f32A1 = a(2)/8;<br />

disp('Coefficients <strong>for</strong> GDFLIB_FilterIIR1 function:');<br />

disp(['f32B0 = FRAC32 (' num2str(f32B0) ')']);<br />

disp(['f32B1 = FRAC32 (' num2str(f32B1) ')']);<br />

disp(['f32A1 = FRAC32 (' num2str(f32A1) ')']);<br />

Note<br />

The filter delay line includes two delay buffers which should be<br />

reset after filter initialization. This can be done by assigning to<br />

the filter instance a GDFLIB_FILTER_IIR1_DEFAULT_F32<br />

<strong>Embedded</strong> <strong>Software</strong> <strong>and</strong> <strong>Motor</strong> <strong>Control</strong> <strong>Libraries</strong> <strong>for</strong> <strong>PXR40xx</strong>, Rev. 1.0<br />

170 Freescale Semiconductor, Inc.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!