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,为一个较为完整的计数器。

相关推荐
Komorebi.py3 小时前
【Linux】-学习笔记05
linux·笔记·学习
亦枫Leonlew3 小时前
微积分复习笔记 Calculus Volume 1 - 6.5 Physical Applications
笔记·数学·微积分
冰帝海岸8 小时前
01-spring security认证笔记
java·笔记·spring
小二·9 小时前
java基础面试题笔记(基础篇)
java·笔记·python
wusong99912 小时前
mongoDB回顾笔记(一)
数据库·笔记·mongodb
猫爪笔记12 小时前
前端:HTML (学习笔记)【1】
前端·笔记·学习·html
Resurgence0312 小时前
【计组笔记】习题
笔记
pq113_613 小时前
ftdi_sio应用学习笔记 3 - GPIO
笔记·学习·ftdi_sio
爱米的前端小笔记13 小时前
前端八股自学笔记分享—页面布局(二)
前端·笔记·学习·面试·求职招聘
fei_sun15 小时前
【Verilog】第一章作业
fpga开发·verilog