您可以嘗試類似的東西(注: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