Verilog刷题笔记62

题目:

Exams/review2015 fancytimer

This is the fifth component in a series of five exercises that builds a complex counter out of several smaller circuits. You may wish to do the four previous exercises first (counter, sequence recognizer FSM, FSM delay, and combined FSM).

解题:

c 复制代码
module top_module (
    input clk,
    input reset,      // Synchronous reset
    input data,
    output [3:0] count,
    output counting,
    output done,
    input ack );

    parameter s0=0,s1=1,s11=2,s110=3,s1101=4,b1=5,b2=6,b3=7,cnt=8,waitter=9;
    reg [3:0]state,next_state;
    reg [15:0]counter;
    reg [3:0]delay,delay0;
    
    always@(posedge clk)begin
        if(reset)
            state=s0;
        else
            state=next_state;
    end
    always@(*)begin
        case(state)
            s0:next_state=data?s1:s0;
            s1:next_state=data?s11:s0;
            s11:next_state=data?s11:s110;
            s110:next_state=data?s1101:s0;
            s1101:next_state=b1;
            b1:next_state=b2;
            b2:next_state=b3;
            b3:next_state=cnt;
            cnt:next_state=(counter==(delay0+1)*1000-1)?waitter:cnt;
            waitter:next_state=ack?s0:waitter;
        endcase
    end
    always@(posedge clk)begin
        case(state)
            s1101:delay[3:0]={delay[2:0],data};
            b1:delay[3:0]={delay[2:0],data};
            b2:delay[3:0]={delay[2:0],data};
            b3:begin delay[3:0]={delay[2:0],data};delay0=delay;end
            cnt:begin counter=counter+1;
                if(counter==1000)
                    delay=delay-1;
                else if(counter==2000)
                    delay=delay-1;
                else if(counter==3000)
                    delay=delay-1;
                else if(counter==4000)
                    delay=delay-1;
                else if(counter==5000)
                    delay=delay-1;
                else if(counter==6000)
                    delay=delay-1;
                else if(counter==7000)
                    delay=delay-1;
                else if(counter==8000)
                    delay=delay-1;
                else if(counter==9000)
                    delay=delay-1;
                else if(counter==10000)
                    delay=delay-1;
                else if(counter==11000)
                    delay=delay-1;
                else if(counter==12000)
                    delay=delay-1;
                else if(counter==13000)
                    delay=delay-1;
                else if(counter==14000)
                    delay=delay-1;
                else if(counter==15000)
                    delay=delay-1;
                else if(counter==16000)
                    delay=delay-1;
            end
            default:begin counter=0;delay=0;end
        endcase
    end
    assign count=delay;
    assign counting=state==cnt;
    assign done=state==waitter;
    
                    
                
            
                
endmodule

结果正确:

本题结合前面的FSM,为一个较为完整的计数器。

相关推荐
Anin蓝天(北京太速科技-陈)1 小时前
252-8路SATAII 6U VPX高速存储模块
fpga开发
西洼工作室1 小时前
【java 正则表达式 笔记】
java·笔记·正则表达式
初学者7.2 小时前
Webpack学习笔记(2)
笔记·学习·webpack
新手上路狂踩坑3 小时前
Android Studio的笔记--BusyBox相关
android·linux·笔记·android studio·busybox
如何学会学习?3 小时前
2. FPGA基础了解--全局网络
fpga开发
Anin蓝天(北京太速科技-陈)4 小时前
271-基于XC7V690T的12路光纤PCIe接口卡
嵌入式硬件·fpga开发
stm 学习ing4 小时前
HDLBits训练3
c语言·经验分享·笔记·算法·fpga·eda·verilog hdl
尘觉4 小时前
算法的学习笔记—扑克牌顺子(牛客JZ61)
数据结构·笔记·学习·算法
bohu835 小时前
sentinel学习笔记1-为什么需要服务降级
笔记·学习·sentinel·滑动窗口
初学者7.6 小时前
Webpack学习笔记(3)
笔记·学习·webpack