📄 cic.cpp
字号:
/*
梳妆滤波器生成程序
v1.2
*/
#include<iostream>
#include<fstream>
#include<cmath>
#include<string>
#include<sstream>
using namespace std;
int main()
{
unsigned int i=6;
unsigned int j;
unsigned int k=8;
stringstream strStream;
cout<<"Please input the length of the cic filter\n";
cin >> i;
cout<<"Please input the wide of the data\n";
cin >> k;
if(i<=1)
cout<<"length must larger than 1\n";
if(i<1)
cout<<"wide must be 1 or larger\n";
strStream << i << '_' << k;
if(k==1) strStream << "bit";
else strStream << "bits";
string file = "cic" + strStream.str() + ".v";
ofstream vfile(file.c_str());
if(!vfile)
{
cout <<"error can not open cic.v";
return 0;
}
vfile << "/*\n";
vfile << " CIC filter\n";
vfile << " length is "<< i <<"\n";
vfile << "*/\n";
vfile << "module cic(input clk,input ["<< k-1 <<":0] in,output reg ["<< k-1<<":0] out);\n";
vfile << " reg ["<<(k-1)<<":0]temp["<< i-1 <<":0];\n";
vfile << " wire ["<< k-1+ ceil(log2((double)i))<<":0] sum;\n";
vfile << " integer i;\n";
vfile << " always@(posedge clk)\n";
vfile << " begin\n";
vfile << " temp[0]<= in;\n";
vfile << " for(i=0;i<"<< i-2 <<";i=i+1)\n";
vfile << " temp[i+1]<=temp[i];\n";
vfile << " out <= sum / "<< i <<";\n" ;
vfile << " end\n";
vfile << " assign sum = in+temp[0]";
for(j=1;j<i-1;j++)
{
vfile<<"+temp["<< j <<"]";
if(j%8==0)vfile<<"\n"<<" ";
}
vfile << ";\n";
vfile << "endmodule\n";
//todo Generate testbench
//ofstream tfile("cic_t.v");
//tfile << "Test bench of cic filter\n";
//tfile << "reg clk";
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -