【作业要求】
1、串联电阻的作用是什么?
分压
2、请画出利用状态机实现1s流水灯的状态转化图并写出详细的代码。
`timescale 1ns / 1ps
module FSMLED(
input sysclk,
input rst_n,
output reg [3:0] led
);
parameter TIME_1s=26'd50_000_000;
reg [25:0] count;
always@(posedge sysclk)
if(!rst_n)
count<=0;
else
if(count<TIME_1s-1)
count<=count+1;
else
count<=0;
parameter IDLE=5'b0000_1,
s1=5'b0001_0,
s2=5'b0010_0,
s3=5'b0100_0,
s4=5'b1000_0;
reg [4:0] cur_state,next_state;
always@(posedge sysclk)
if(!rst_n)
cur_state<=IDLE;
else
cur_state<=next_state;
always@(*)
if(!rst_n)
next_state=IDLE;
else
case(cur_state)
IDLE:next_state=s1;
s1:begin
if(count==2)
next_state=s2;
else
next_state=s1;
end
s2:begin
if(count==1)
next_state=s3;
else
next_state=s2;
end
s3:begin
if(count==1)
next_state=s4;
else
next_state=s3;
end
s4:begin
if(count==1)
next_state=s1;
else
next_state=s4;
end
default:next_state=IDLE;
endcase
always@(posedge sysclk)
if(!rst_n)
led<=4'b1111;
else
case(cur_state)
IDLE:led<=4’1111;
s1:led<=4'b0001;
s2:led<=4'b0010;
s3:led<=4'b0100;
s4:led<=4'b1000;
default:led<=4'b1111;
endcase
endmodule【我的做法】
【结果/时序图/实验现象(可视频)】

评论 0