티스토리 뷰
1초 생성기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity sec_gen is port( nRst : in std_logic; clk : in std_logic; sec_sig : out std_logic ); end sec_gen; architecture BEH of sec_gen is signal cnt : std_logic_vector(31 downto 0); signal sig : std_logic; begin sec_sig <=sig; -- begin ~ end 문장 -- initial, if, case, always 등을 사용할 때 블록을 지정할때 사용한다. -- C 언어에서 {… }와 같은 개념이다. process(nRst,clk) begin if(nRst = '0') then sig <= '0'; cnt <=(others =>'0'); elsif rising_edge(clk) then -- 입력클럭 50MHz이므로 50% 듀티사이클 펄스는 아래와 같이 구할 수 있다. if(cnt = 24999999) then cnt <= (others =>'0'); sig <= not sig; else cnt <= cnt + 1; end if; end if; end process; end BEH; | cs |
60진 카운터
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity counter_60 is port( -- 60진 카운터에서는 sec, min에 대한 각각의 클럭으로 카운팅이 일어나며 reset을 통해 0으로 리셋된다. -- 또한 FND 디코더에 연결된 4bit의 출력을 내보낸다. 60이 카운팅 되면 다음 단위로 carry가 발생한다. -- 이를 통해 외부 입출력을 정의하면 다음과 같다. nRst : in std_logic; clk : in std_logic; digit_one : out std_logic_vector(3 downto 0); digit_ten : out std_logic_vector(3 downto 0); carry : out std_logic ); end counter_60; architecture BEH of counter_60 is -- 다음은 내부 시그널이다. 위 port는 외부 시그널을 의미하기 때문에 실질적 동작은 아래 기술하게 된다 signal count_one : std_logic_vector(3 downto 0); signal count_ten : std_logic_vector(3 downto 0); signal count_carry : std_logic; begin process(nRst, clk) begin -- reset 동작은 active low라는 점에 유의하자. if(nRst = '0') then count_one <= (others => '0'); count_ten <= (others => '0'); -- clk'EVENT AND clk='1'은 rising edge를 clk'EVENT AND clk='0'을 falling edge를 의미 -- RISING_EDGE(clk), FALLING_EDGE(clk)로 직접 작성하는 방법도 있다. elsif RISING_EDGE(clk) then if(count_carry = '1') then count_carry <= '0'; end if; if(count_one = 9) then -- (others => '0')으로 대체하여 쓸 수 있다. count_one <= "0000"; if(count_ten = 5 ) then -- (others => '0')으로 대체하여 쓸 수 있다. count_ten <= "0000"; count_carry <= '1'; else count_ten <= count_ten + 1; end if; else count_one <= count_one + 1; end if; end if; carry <= count_carry; digit_one <= count_one; digit_ten <= count_ten; end process; end BEH; | cs |
12진 카운터
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity counter_12 is port( -- 12진 카운터에서는 hour에 대한 각각의 클럭으로 카운팅이 일어나며 reset을 통해 12로 리셋된다. -- 또한 FND 디코더에 연결된 4bit의 출력을 내보낸다. 12가 카운팅 되면 carry 없이 1로 돌아간다. -- 이를 통해 외부 입출력을 정의하면 다음과 같다. nRst : in std_logic; clk : in std_logic; digit_one : out std_logic_vector(3 downto 0); digit_ten : out std_logic_vector(3 downto 0) ); end counter_12; architecture BEH of counter_12 is -- 다음은 내부 시그널이다. 위 port는 외부 시그널을 의미하기 때문에 실질적 동작은 아래 기술하게 된다 signal count_one : std_logic_vector(3 downto 0); signal count_ten : std_logic_vector(3 downto 0); begin process(nRst, clk) begin -- reset 동작은 active low라는 점에 유의하자. if(nRst = '0') then -- 12를 표현하기 위해서 아래 값으로 reset count_one <= "0010"; count_ten <= "0001"; -- clk'EVENT AND clk='1'은 rising edge를 clk'EVENT AND clk='0'을 falling edge를 의미 -- RISING_EDGE(clk), FALLING_EDGE(clk)로 직접 작성하는 방법도 있다. elsif RISING_EDGE(clk) then if(count_one = 9) then -- (others => '0')으로 대체하여 쓸 수 있다. count_one <= "0000"; count_ten <= count_ten + 1; else count_one <= count_one + 1; end if; if(count_one = 2 and count_ten = 1) then count_one <= "0001"; count_ten <= "0000"; end if; end if; digit_one <= count_one; digit_ten <= count_ten; end process; end BEH; | cs |
FND Decoder
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity fnd_decoder is port ( data : in std_logic_vector(3 downto 0); fnd_data : out std_logic_vector(6 downto 0) ); end fnd_decoder; architecture beh of fnd_decoder is begin fnd_data <= "1000000" when data = x"0" else "1111001" when data = x"1" else "0100100" when data = x"2" else "0110000" when data = x"3" else "0011001" when data = x"4" else "0010010" when data = x"5" else "0000010" when data = x"6" else "1011000" when data = x"7" else "0000000" when data = x"8" else "0010000" when data = x"9" else "1111111"; end beh; | cs |
Multiplexer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity multiplexer is port( A : in std_logic; B : in std_logic; SEL : in std_logic; Y : out std_logic ); end multiplexer; architecture BEH of multiplexer is begin Y <= A when SEL = '0' else B when SEL = '1' else 'Z'; -- 예외 출력 조건을 다음과 같이 Z로 설정, Z는 대문자 사용 end BEH; | cs |
'프로그래밍 > Quartus 2' 카테고리의 다른 글
[VHDL] 모니터 제어 (0) | 2018.04.17 |
---|---|
[VHDL] 계층구조 연습, MUX 설계 (0) | 2018.04.02 |
[VHDL] COUNTER 설계 (0) | 2018.03.26 |
[VHDL] 논리 게이트 (0) | 2018.03.16 |
[VHDL] VHDL 개요 (0) | 2018.03.16 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- oracle
- gcp
- aws
- Next.js
- vue
- svelte
- REACT
- PostgreSQL
- 이진탐색 #중복
- nuxt.js
- Remix
- Gatsby.js
- MySQL
- alpine.js
- vue.js
- node.js
- JavaScript
- RDBMS
- DevOps
- hoisting
- SQLite
- Angular
- Quasar
- Azure
- nosql
- Cloud
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함