您可以尝试类似的东西(注:CLK改变每单集为5毫秒,取决于函数调用的时间,输出会发生变化,所以除了看到CLK的实时表示外)。
#include <iostream>
#include <ctime>
#define PASSED_MS (int(float(now)/CLOCKS_PER_SEC*1000))
using namespace std;
class DFF
{
public:
DFF(bool D):D(D),CLK(0),Q(0),QN(1),start(clock()),now(start){}
~DFF();
bool DFF_Q();
void DFF_ALL(bool& clk,bool& q,bool& qn); //To return all Parameters at once
private:
bool D,CLK,Q,QN;
const clock_t start;
clock_t now;
};
DFF::~DFF()
{
delete &D;
delete &CLK;
delete &Q;
delete &QN;
delete &start;
delete &now;
}
bool DFF::DFF_Q()
{
now=clock()-start;
if((PASSED_MS/5)%2!=0 && PASSED_MS!=0) //if an odd period of 5ms passed change else keep it as its
{
CLK=CLK?0:1;
if(CLK)
{
Q=D;
QN=D?0:1;
}
}
return Q;
}
void DFF::DFF_ALL(bool& clk,bool& q,bool& qn)
{
DFF_Q();
clk=CLK;
q=Q;
qn=QN;
}
int main()
{
DFF a(1);
bool clk,q,qn;
int c=30;
cout<<"CLK "<<"DFF-Q "<<"DFF-QN "<<endl;
while(c!=0)
{
c--;
a.DFF_ALL(clk,q,qn);
cout<<clk<<" "<<q<<" "<<qn<<endl<<endl;
}
return 0;
}
你是什么意思的C++包装?你的意思是类似C++中这种逻辑的软件模拟吗? – 2013-04-30 16:07:03
你是否通过VHPI与模拟器交互?还是你的模拟器建立在gcc上,就像ghdl是? (顺便说一句,我强烈建议修复该时钟检测:“如果rising_edge(clk)then”是首选) – 2013-04-30 16:26:15
是否确定您的DFF逻辑正确? – 4pie0 2013-04-30 16:50:54