数电EDA实验报告
交通灯设计
姓名:
班级:1302031
学号:
一、实验要求:
分两个方向(1、2),每个方向各有红(R)、绿(G)、黄(Y)三个交通灯。有自动、手动两种控制方式。在自动方式下,控制器的状态转移表为:
状态亮灯停留时间
S0 R1,G2 2秒
S1 R1,Y2 1秒
S2 G1,R2 2秒
S3 Y1,R2 1秒
在手动方式下,按下按钮K0~ K3时直接进入对应序号的状态,随后即转入自动方式。
2.设计提示:
▲交通灯、按钮分别利用实验板上的发光二极管、按钮;
▲可参考流水灯(SC)的设计。
二、实验器材:
PC机一台、FPGA教学实验板一块
三、实验原理与内容:
1原理
(1)本题中交通灯的状态可用有限状态机模型描述。根据输出与输入之间的关系,有限状态机可以分为两种类型:Moore和Mealy型。这两种状态机的区别在于:Mealy型状态机的输出由状态机的输入和状态机的状态共同决定;Moore型状态机的输出仅与状态机的状态有关,而与状态机的输入无关。本题中的输出由六个发光二级光显示,其状态仅与当前状态机的状态有关,故该题为Moore模型的状态机。下图为状态机的状态表:
状态表
状态转移图:
K3=0/
K3=0/
2.程序设计
组件一:实体jiaotongdeng 的程序 library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity jiaotongdeng is port(
clk :in std_logic; k0 :in std_logic; k1 :in std_logic; k2 :in std_logic;
k3 :in std_logic;
r1,g1,y1,r2,g2,y2 :out std_logic
);
end jiaotongdeng;
architecture behavior of jiaotongdeng is
type state_type is(s0,s1,s2,s3);
signal current_state,next_state:state_type;
signal counter:std_logic_vector(6 downto 0);
begin
synch:process begin
wait until clk'event and clk='1';
counter<=counter;
if counter<5 then
counter<=counter+1;
else
counter<=(others=>'0');
end if;
end process;
process
begin
wait until clk'event and clk='1';
current_state<=next_state;
end process;
state_trans:process(current_state,k0,k1,k2,k3)
begin
case current_state is
when s0 =>
if k0='0' then
next_state<=s0;
else
if k1='0' then
next_state<=s1;
else
if k2='0' then
next_state<=s2;
else
if k3='0' then
next_state<=s3;
else
if counter<1 then
next_state<=s0;
else
end if;
end if;
end if;
end if;
end if;
when s1 =>
if k0='0' then
next_state<=s0;
Else
if k1='0' then
next_state<=s1; else
if k2='0' then
next_state<=s2; else
if k3='0' then
next_state<=s3; else
if counter<2 then
next_state<=s1; else
next_state<=s2; end if;
end if;
end if;
end if;
end if;
when s2=>
if k0='0' then
next_state<=s0; else
if k1='0' then
next_state<=s1; else
if k2='0' then
next_state<=s2; else
if k3='0' then
next_state<=s3; else
if counter<4 then
next_state<=s2; else
end if;
end if;
end if;
end if;
end if;
when s3=>
if k0='0' then
next_state<=s0;
else
if k1='0' then
next_state<=s1;
else
if k2='0' then
next_state<=s2;
else
if k3='0' then
next_state<=s3;
Else
if counter<5 then
next_state<=s3;
Else
next_state<=s0;
end if;
end if
end if;
end if;
end if;
end case;
end process;
ouput:process(current_state)
begin case current_state is
when s0=>
r1<='0';
g1<='1';
y1<='1';
r2<='1';
g2<='0';
y2<='1';
when s1=>
r1<='0';
g1<='1';
y1<='1';
r2<='1';
g2<='1';
y2<='0';
when s2=>
r1<='1';
g1<='0';
y1<='1';
r2<='0';
g2<='1';
y2<='1';
when s3=>
r1<='1';
g1<='1';
y1<='0';
r2<='0';
g2<='1';
y2<='1';
end case;
end process;
end behavior;
组件二:分频器实体devide的程序
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity devide is
port(
clk :in std_logic;
clk_out :out std_logic
);
end devide;
architecture arc_devide of devide is
signal count:std_logic_vector(26 downto 0); begin
process
begin
wait until clk'event and clk='1';
if(count<49999999)then
count<=count+1;
clk_out<='0';
else
count<=(others=>'0');
clk_out<='1';
end if;
end process;
end architecture arc_devide;
3.实验连接图
如上图所示,该交通灯控制系统由两个实体组成。实体clk为50M的时钟分频器,clk是输入口,接的是FPGA产生的时钟信号,clk_out是输出口,输出分频后的时钟脉冲。主实体jiaotongdeng则实现状态机的状态转换逻辑控制。其k0~k3口是输入口,为手动方式的控制按钮,r1,r2,g1,g2,y1,y2为六个输出,控制六个发光二极管的亮灭。六个发光二级管的亮灭代表六个状态机的状态,从而实现交通灯控制的功能。
4.时序波形分析
(k0,k1,k2,k3=1)
上图为4个状态进行转换的时序波形。可见(r1,g1,y1,r2,g2,y2)的状态转换符合011101》011110》101011》110011》011101》……的顺序循环。
(k0=0)
(k1=0)
(k2=0)
(k3=0)
上图为k3=0时的输出状态s3,输出恒为110011。即亮灯为R1,G2。保持时间1S。
四、心得体会
通过这次实验了解和学习到了EDA在实际设计中的应用,通过对这门课程相关理论的学习,我掌握了EDA的一些基本的的知识,用自己学到的东西尽可能的去完成老师布置的实验。通过实验使我更加深刻的认识和理解了EDA。不过在做实验的时候带来的不仅仅只是收获,也会有很多的困难。例如,当在画实验原理图的时候需要一个元件,但是怎么找都找不到这个元件。还有就是当你用VHDL 语言时,在仿真的时候会出现许多错误,但你却不知道到底错在哪,该怎么改。还好有同学和老师的帮助才能使这些问题得以解决。在编译过程中我了解到很多在书本上没有理解的知识。
在学习这门课的时候我觉得实验真的很重要,而且只有经过实验课我们才能更好的掌握所学的理论知识,才能更好的应用他们,同样也是实验课激发了学习的兴趣,所以我希望以后再学习这门课的时候可以多安排一些实验课,通过实验
将知识消化,不仅能够理解透彻更会有更高的效率。