把一个二进制转成BCD码,使用逻辑分析仪抓的数据,输入的数据最大为189975,加个60000后最大249975,平时这个数据是不断变化的,最大会有正负1000左右的跳动。现在的问题是:假如输入为100000,那么正确的输出应该是1、6、0,让我想不明白的是,最终输出的三个数据很不固定,会来回变。另外,程序中明明将count5限制到最大是9,怎么跑出来个13呀?还有count6,有时候居然会冒出个15,求大牛们给看下,这程序的问题在哪?
附上这一块的程序:
architecture behave of D_BCD is
signal count1,count2,count3,count4,count5,count6: integer range 0 to 9:=0;
signal cnt:integer range 0 to 3500000:=0;
begin
process(datain,clk)
-- variable cnt:integer range 0 to 350000;
begin
if clk'event and clk='1' then
if cnt<=conv_integer(datain)+60000 then
cnt<=cnt+1;
if count1=9 then
count1<=0;
if count2=9 then
count2<=0;
if count3=9 then
count3<=0;
if count4=9 then
count4<=0;
if count5=9 then
count5<=0;
count6<=count6+1;
else
count5<=count5+1;
end if;
else
count4<=count4+1;
end if;
else
count3<=count3+1;
end if;
else
count2<=count2+1;
end if;
else
count1<=count1+1;
end if;
else
dataout3<=conv_std_logic_vector(count6,4);
dataout2<=conv_std_logic_vector(count5,4);
dataout1<=conv_std_logic_vector(count4,4);
cnt<=0;
count1<=0;
count2<=0;
count3<=0;
count4<=0;
count5<=0;
count6<=0;
end if;
end if;
end process; |