微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > ROM读指令失败

ROM读指令失败

时间:10-02 整理:3721RD 点击:
各位,本人最近在编写一款CISC MCU,采用12M时钟依次读取ROM中的4个字节的指令,然后用1M时钟(由12M时钟分频)将4字节合并,交给MCU处理。
    据此,编写了一个module用于实例化ROM IP,并实现上述功能。读取指令实现,但合并时
失败,求指点:
下面是上板后的波形截图:
上图中clk_osc为12M,clock为1M。
q表示从ROM读出的一个字节,用inst接收,最后在1M时钟上升沿赋给输出inst_o。
可见,q的数据并未存入inst。
下面附上该模块代码,考考各位大神的眼力:



[code][/code]module oc8051_rom_top(clk_osc,
                                                   clock,
                                                        rst,
                                                        addr,
                                                        inst_o);
input                         clk_osc,clock,rst;
input   [15:0] addr;
output  [31:0] inst_o;
reg           [31:0] inst_o,inst;
reg     [15:0] addr_r;
reg          [2:0]        cnt;

//实例化ROM IP
rom_64k oc8051_rom1( .clock(clk_osc),
                                                        .address(addr_r),
                                                        .q(q));
                                       
//计数
always@(posedge ~clk_osc or posedge rst)
begin
        if(rst)       
                cnt <= 3'h0;
        else if(clock&cnt<3'h6)
                        cnt <= cnt +3'h1;
        else        
                        cnt <= 3'h0;
end
//计算地址偏移量
always@(posedge ~clk_osc or posedge rst)
begin
        if(rst)       
                addr_r<= 16'h0;
        else        if(cnt<3'h4)
                addr_r                 <= addr+ cnt;
end

       
//将读取的4个字节依次存入buffer
always@(posedge clk_osc or posedge rst)
begin
        if(rst)
                inst <= 32'h0;
        else if(clock)
          case(cnt)
                3'h0:inst[31:24] <= q;
                3'h1:inst[23:16] <= q;
                3'h2:inst[15:8]  <= q;
                3'h3:inst[7:0]          <= q;
        endcase
end
//将buffer中的指令合并、输出
always@(posedge clock or posedge rst)
begin
        if(rst)
                inst_o <= 32'h0;
        else
                inst_o <= inst;       
end
endmodule

先跑仿真吧。而且这编码风格闻所未闻

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top