⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iir6.c

📁 硬件设计资料,刚上网查找资料,是个新手,望大家提携了,
💻 C
字号:
/*******************************************************************************
 File: IIR6.c
	Version: 1.0 (Not verified)
	Date:	02.02.20 [yy.mm.dd]
	Author: jllassen

 Target device: AVRs with HW multiplier

 Compiler:
      IAR EWAVR 2.26C

 Describtion: 
      Initialization and call of a 8th order FIR filter. 
      The filter is implementes in assembly. To illustrated to 
      possibility to call the filter in cascade to generate a higher 
      order filter the output or the first filter is feed into the 
      second filter.

 Usage:
		Implemented so that the filter can be called from IAR EWAVR C compiler.
      address to the filter nodes and filter coefficients should be provided
      as first calling argument (will thus be placed in R16:R17) and the new 
      input sample to the filter should be provided as the second calling
      argument (placed in R18:R19).
      
      int FIR_filter(*myFilter, newDataSample);

      The structure for the filter nodes and filter coefficients should be
      as follows:
      
      struct FIR_filter{
	      int filterNodes[FILTER_ORDER];			  //memory nodes required to store x(n-1), x(n-2)
	      int filterCoefficients[(FILTER_ORDER)+1];   //filter coefficients B0, B1, B2
	      }, myFilter = {0, 0, B2, B1, B0} 

      The filter nodes should be initialized prior to the first call of the 
      filter function and the filter coefficients should be scaled to use
      signed 13-bit resolution (max)
      
 Registers usage:
		r0-4, r16-23, Z (all scratch/volatile registers)

 Memory usage for variables and constants:
		4 bytes SRAM for filter nodes (filter memory)
      6 bytes SRAM for filter coefficients

 Stats:
		INIT:  Depending on compiler settings?
		FILTER:  xx instructions; xx cycles (excl. ret)
*******************************************************************************/
#include <inavr.h>
#define FILTER_ORDER 6

/**********************************************************/
//Filter coefficients; LP filter with cut off at 0.4*(fs/2) 
#define B0   4
#define B1   0
#define B2   -5
#define B3   -5
#define B4   4
#define B5   0
#define B6   -5

#define A1  2
#define A2   -5
#define A3   -5
#define A4   4
#define A5   0
#define A6   -5

/**********************************************************/
//Global variables
/**********************************************************/
struct IIR_filter{
	   int filterNodes[FILTER_ORDER*2];			  //memory nodes required to store x(n-0), x(n-1),..., x(n-6),y(n-1),...,y(n-6)
	   int filterCoefficients[(FILTER_ORDER*2)+1];  //filter coefficients B0, B1, B2, ..., B6, A1, A2,...,A6
	   }; 

/**********************************************************/
//Function declarations
/**********************************************************/
extern int IIR6( struct IIR_filter *thisFilter, int newSample );

/**********************************************************/
//Main function
/**********************************************************/
void main(void)
{
  struct IIR_filter 
    filter04_06 = {0,0,0,0,0,0,
      0,0,0,0,0,0, 
      B0,B1,B2,B3,B4,B5,B6,
      A1,A2,A3,A4,A5,A6};          //initialize filter with 0.4 cutoff frequency
  
  int filterInput = 0;
  volatile int filterOutput;
  
  //feed filterInput into filter
  filterOutput = IIR6((struct IIR_filter*)&filter04_06, filterInput);
  
  for(;;)
    __no_operation();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -