EDA实验要求

只是参考,实验报告请自行完成,电路图,时序图请自行操作

〇、Quartus软件的安装

https://blog.csdn.net/weixin_43862765/article/details/99305902

一、LED显示

(1)按键K1作输入,LED1作输出;按下K1时,LED1亮,松开时灭。
(2)用文本输入法,编写VHDL文件,完成设计。

LIBRARY ieee;
USE ieee.std_logic_1164.all; 

LIBRARY work;

ENTITY demo011 IS 
	PORT
	(
		k1 :  IN  STD_LOGIC;
		led01 :  OUT  STD_LOGIC
	);
END demo011;

ARCHITECTURE bdf_type OF demo011 IS 



BEGIN 
led01 <= k1;



END bdf_type;

(3)用图形输入法,完成设计。

二、译码器设计

按键K3、K2、K1用作三位编码地址输入(A2、A1、A0),LED8---LED1用作8位译码输出Y7--Y0;完成3—8译码器设计;按键按下时,输入为逻辑‘0’,松开时,为逻辑‘1’,LED亮时,对应有效的译码输出。完成设计。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity decoder3to8 is
	port (
		A: in std_logic_vector (2 downto 0);
		Y: out bit_vector(7 downto 0)
	);
end decoder3to8;

architecture behave of decoder3to8 is
begin
	Y<="00000001" sll conv_integer(A);
end behave;

三、分频器、计数器设计

SYS_CLK0用作时钟源(40MHZ),分频后,作1HZ方波信号。

思路:

SYS_CLK0用作时钟源(40MHZ), 可以理解为每秒钟按动40 000 000次按钮。

因此要达到1秒闪一次的话,就是指定一个范围让其交替亮暗。

例如0 - 40 000 000让 led1 输出 0 ,开发板的led灯是低电平有效, 因此为0时会亮

40 000 000 - 80 000 000 输出 1 , 就是不亮

当达到80 000 000时重置为0,形成了一个循环。

(1)驱动LED1闪烁。闪烁频率为1HZ。

LIBRARY ieee;
USE ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all;


ENTITY twinkle IS 
	PORT
	(
		clk :  IN  STD_LOGIC;
		led01 :  OUT  STD_LOGIC
	);
END twinkle;

ARCHITECTURE bdf_type OF twinkle IS 

signal count :integer range 0 to 80000001;


BEGIN 

	process(clk)
	
	begin
		--if num=40000000 then num:=0; 
		--end if;
		if (clk'event and clk='0') then
			if count=80000000 then 
				count <=0;
			else
				count <=count+1;
			end if;
			if count>40000000 then 
				led01 <='1';
			else
				led01 <='0';
			end if;
		end if;
		
	end process;
END bdf_type;

(2)跑马灯显示:LED1 - LED8循环显示。

LIBRARY ieee;
USE ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all;


ENTITY gall_led IS 
	PORT
	(
		clk :  IN  STD_LOGIC;
		led :  OUT  STD_LOGIC_vector(7 downto 0)
	);
END gall_led;

ARCHITECTURE bdf_type OF gall_led IS 

signal count :integer range 0 to 160000000;
signal tmp :STD_LOGIC_vector(7 downto 0);

BEGIN 

	process(clk)
	
	begin
		if (clk'event and clk='0') then 
			if count=160000000 then 
				count <=0;
			else
				count <=count+1;
			end if;			
			if count>=140000000 then 
			tmp <="01111111";
			elsif count>=120000000 then 
			tmp <="10111111";
			elsif count>=100000000 then 
			tmp <="11011111";
			elsif count>=80000000 then 
			tmp <="11101111";
			elsif count>=60000000 then 
			tmp <="11110111";
			elsif count>=40000000 then 
			tmp <="11111011";
			elsif count>=20000000 then 
			tmp <="11111101";
			else
			tmp <="11111110";
			end if;
			
		end if;
		led<=tmp;
	end process;
END bdf_type;

(3)十进制显示,LED1闪烁十次,LED2闪烁一次,实现LED1对 LED1十分频。

// 这个漏掉了,思路应该和之前的差不多, 大家自己尝试尝试。

LIBRARY ieee;
USE ieee.std_logic_1164.all; 

LIBRARY work;

ENTITY demo01 IS 
	PORT
	(
		clk :  IN  STD_LOGIC;
		led :  OUT  STD_LOGIC_VECTOR(0 to 1)
	);
END demo01;

ARCHITECTURE bdf_type OF demo01 IS 



BEGIN 

process(clk)
variable count1: integer :=0 ;
variable count2: integer :=0 ;
begin

if (clk'event and clk='0') then
	if count1 = 80000000 then
		count1 := 0;
		count2 := count2 + 1;
		if count2 = 10 then 
			count2 := 0;
		end if;
	else
		count1 :=count1+1;
	end if;
end if;

if count1 >=40000000 then led(0)<='1';
	else led(0)<='0';
end if;

if count2 = 9 and count1 <= 40000000 then led(1) <='0';
else led(1)<='1';
end if;
end process;



END bdf_type;

四、步进电机驱动

按下K1,步进电机正转;松开,步进电机静止,按下K2,步进电机反转,松开,步进电机静止。

先确认5V和其相邻的引脚的跳线有没有链接

MA (步进电机端) ---> 46 (FPGA端)

MB (步进电机端) ---> 45 (FPGA端)

MC (步进电机端) ---> 44 (FPGA端)

MD (步进电机端) ---> 43 (FPGA端)

FPGA端只要接到数字引脚就可以,在软件PIN中配置对应的就可以了,

但最好和上面一致, 方便操作

代码思路:

ABCD轮流高电平(例如A为'1' ,其它为'0'), 便能驱动电机

原理:

磁铁同性相斥, 当A通电时和电机中心磁铁相斥, 或者说产生了切向的安培力(我乱说的,大概是这样。。。)

因此轮流高电平,就一直有切向的力!!!

LIBRARY ieee;
USE ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all;


ENTITY stepper_motor2 IS 
	PORT
	(
		k1,k2: IN STD_LOGIC;
	
		clk :  IN  STD_LOGIC;
		
		led :  OUT  STD_LOGIC_vector(3 downto 0)
	);
END stepper_motor2;

ARCHITECTURE bdf_type OF stepper_motor2 IS 
-- 40 000 000   40000
signal count :integer range 0 to 4000000;
signal tmp :STD_LOGIC_vector(3 downto 0);

BEGIN 
	-- 注意每个if间是并行的, 但if里面的elsif是顺序执行的(描述用的是软件的想法)
	process(clk,k1,k2)
	-- 40 000 000 --> 4 000 000  10hz频率
	begin
	if ( clk'event and clk='0'   ) then 
		if count=4000000 then 
				count <=0;
			else
				count <=count+1;
		end if;
			
		if count>=3000000 then 
            if (k1='0' and k2 = '1') then tmp <="0001";  --正转
            elsif (k1='1' and k2 = '0') then tmp <="1000";  --反转
            end if;
		elsif count>=2000000 then 
            if (k1='0' and k2 = '1') then tmp <="0010";
            elsif (k1='1' and k2 = '0') then tmp <="0100";
            end if;
		elsif count>=1000000 then 
            if (k1='0' and k2 = '1') then tmp <="0100";
            elsif (k1='1' and k2 = '0') then tmp <="0010";
            end if;
		else
            if (k1='0' and k2 = '1') then tmp <="1000";
            elsif (k1='1' and k2 = '0') then tmp <="0001";
            end if;
		end if;	

	end if;
	
    led<=tmp;
	
	end process;
	
	
END bdf_type;

五、EDA实验课程设计
(1)学校统一模板。
(2)自主选题。

自己尝试

FPGA芯片型号:Cyclone EP1C12Q240(6Q240兼容)
LED1 PIN_50 K1 PIN_121
LED2 PIN_53 K2 PIN_122
LED3 PIN_54 K3 PIN_123
LED4 PIN_55 K4 PIN_124
LED5 PIN_176 SYS_CLK0 PIN_28
LED6 PIN_47
LED7 PIN_48
LED8 PIN_49

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
	worker_connections 1024;
}
stream{
	map $ssl_preread_server_name $backend_name { 
	lankeren.ltd yixin; 
	admin.lankeren.ltd oracle; 
	# 域名都不匹配情况下的默认值 
	default yixin; 
    } 
    #web,配置转发详情 
    upstream yixin { 
        server 127.0.0.1:44321; 
    } 
    # trojan,配置转发详情 
    upstream oracle { 
        server 127.0.0.1:10110;
    }

    server { 
        listen 443 reuseport; 
        listen [::]:443 reuseport; 
        proxy_pass $backend_name; 
        ssl_preread on; 
    }
}
http {
	log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
				  '$status $body_bytes_sent "$http_referer" '
				  '"$http_user_agent" "$http_x_forwarded_for"';

	access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    gzip  on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 9;
    gzip_types       text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php application/javascript application/json;
    gzip_disable "MSIE [1-6]\.";
    gzip_vary on;


    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    server {
        listen 80;
        server_name admin.lankeren.ltd lankeren.ltd;
        rewrite ^(.*)$ https://${server_name}$1 permanent;
    }

    server {
        listen  10110 ssl;
        server_name  admin.lankeren.ltd;
        ssl_certificate   /root/java/oracle/cert/admin.lankeren.ltd_bundle.crt;         
        ssl_certificate_key  /root/java/oracle/cert/admin.lankeren.ltd.key;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;        
        error_page 497 301 https://$http_host$request_uri;
	

        location / {
            root   /var/www/dist-oracle;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
        
        location /api/ { #用户
           rewrite  ^/api/(.*)$ /$1 break;
           proxy_pass   http://127.0.0.1:9090;
        }

        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {40 000 000
        	root   html;
		}
	}
    server {
        listen  44321 ssl;
        server_name  lankeren.ltd;
        ssl_certificate   /root/java/oracle/cert/lankeren.ltd_bundle.crt;         
        ssl_certificate_key  /root/java/oracle/cert/lankeren.ltd.key;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;        
        error_page 497 301 https://$http_host$request_uri;


        location / {
           root   /var/www/dist;
            index  index.html index.htm;
           try_files $uri $uri/ /index.html;
        }
        location /api/ { #用户
           rewrite  ^/api/(.*)$ /$1 break;
           proxy_pass   http://127.0.0.1:9091;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

{"code":"1","msg":"成功","data":
 {"records":[{"id":6,"studentid":1002,"studentname":"张三","classid":2,"classname":"软件工程"},{"id":8,"studentid":1003,"studentname":"王二","classid":1,"classname":"计算机科学"},{"id":9,"studentid":1004,"studentname":"王五","classid":2,"classname":"软件工程"},{"id":10,"studentid":1005,"studentname":"小明","classid":2,"classname":"软件工程"},{"id":11,"studentid":1006,"studentname":"小王","classid":2,"classname":"软件工程"},{"id":12,"studentid":1007,"studentname":"小龙","classid":2,"classname":"软件工程"},{"id":134,"studentid":1008,"studentname":"小李","classid":2,"classname":"软件工程"},{"id":135,"studentid":1009,"studentname":"小张","classid":3,"classname":"物联网"},{"id":137,"studentid":1011,"studentname":"大胖","classid":3,"classname":"物联网"},{"id":138,"studentid":1012,"studentname":"瘦子","classid":3,"classname":"物联网"}],"total":15,"size":10,"current":1,"orders":[],"optimizeCountSql":true,"hitCount":false,"countId":null,"maxLimit":null,"searchCount":true,"pages":2}}
public void GenericJson(){
    JSON json = new JSON();
    json.k1 = val1;
    getDataFromSql()
    return JSON;
}

更多文章请关注《万象专栏》