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

相关推荐
aloha_7892 小时前
从零记录搭建一个干净的mybatis环境
java·笔记·spring·spring cloud·maven·mybatis·springboot
dsywws3 小时前
Linux学习笔记之vim入门
linux·笔记·学习
A-超5 小时前
vue3展示pag格式动态图
笔记
u0101526586 小时前
STM32F103C8T6学习笔记2--LED流水灯与蜂鸣器
笔记·stm32·学习
weixin_518285056 小时前
深度学习笔记10-多分类
人工智能·笔记·深度学习
丘狸尾6 小时前
ubuntu【桌面】 配置NAT模式固定IP
笔记
bigbig猩猩6 小时前
FPGA(现场可编程门阵列)的时序分析
fpga开发
王俊山IT6 小时前
C++学习笔记----10、模块、头文件及各种主题(二)---- 预处理指令
开发语言·c++·笔记·学习
慕卿扬7 小时前
基于python的机器学习(二)—— 使用Scikit-learn库
笔记·python·学习·机器学习·scikit-learn
齐 飞8 小时前
MongoDB笔记02-MongoDB基本常用命令
前端·数据库·笔记·后端·mongodb