打印

一个二进制转BCD的问题,请大家分析

[复制链接]
1631|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
qwempty|  楼主 | 2012-12-30 20:49 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
把一个二进制转成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;

相关帖子

沙发
qwempty|  楼主 | 2012-12-30 20:49 | 只看该作者
有什么问题呢

使用特权

评论回复
板凳
GoldSunMonkey| | 2012-12-30 22:16 | 只看该作者
感觉count5不应该啊。有仿真图么?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

10

主题

148

帖子

0

粉丝