산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Industrial programming >> VHDL

VHDL Case-When 문 마스터하기: 효율적 멀티플렉서 설계

Case-When 문은 시그널, 변수, 표현식에 따라 VHDL 프로그램을 여러 경로 중 하나로 이끕니다. 긴 if-then-elsif-else 체인보다 깔끔하고 읽기 쉬운 대안이며, 특히 여러 이산 값을 다룰 때 유용합니다.

많은 프로그래밍 언어가 switch나 case 구문을 쓰는데, VHDL에서 case 구문은 멀티플렉서와 다른 선택 로직 구축의 필수 요소입니다.

이 글은 Basic VHDL Tutorials 시리즈의 일부입니다.

기본 문법

case 문의 정식 구조:

case <expression> is when <choice> => -- code for this branch when <choice> => -- code for this branch ... end case;

<expression>은 보통 시그널이나 변수입니다. 케이스에 많은 when 분기가 있어도 시뮬레이션 중 하나만 실행됩니다.

각 <choice>는 다음 형태가 될 수 있습니다:

실전 예제: 4-to-1 멀티플렉서 만들기

아래는 if-then-elsif와 case 두 방식으로 4-to-1 멀티플렉서를 구현한 완전한 VHDL 코드입니다.

library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity T14_CaseWhenTb is end entity; architecture sim of T14_CaseWhenTb is signal Sig1 : unsigned(7 downto 0) := x"AA"; signal Sig2 : unsigned(7 downto 0) := x"BB"; signal Sig3 : unsigned(7 downto 0) := x"CC"; signal Sig4 : unsigned(7 downto 0) := x"DD"; signal Sel : unsigned(1 downto 0) := (others => '0'); signal Output1 : unsigned(7 downto 0); signal Output2 : unsigned(7 downto 0); begin -- Stimuli for the selector signal process is begin wait for 10 ns; Sel <= Sel + 1; wait for 10 ns; Sel <= Sel + 1; wait for 10 ns; Sel <= Sel + 1; wait for 10 ns; Sel <= Sel + 1; wait for 10 ns; Sel <= "UU"; wait; end process; -- MUX using if-then-else process(Sel, Sig1, Sig2, Sig3, Sig4) is begin if Sel = "00" then Output1 <= Sig1; elsif Sel = "01" then Output1 <= Sig2; elsif Sel = "10" then Output1 <= Sig3; elsif Sel = "11" then Output1 <= Sig4; else Output1 <= (others => 'X'); end if; end process; -- Equivalent MUX using a case statement process(Sel, Sig1, Sig2, Sig3, Sig4) is begin case Sel is when "00" => Output2 <= Sig1; when "01" => Output2 &= Sig2; when "10" => Output2 <= Sig3; when "11" => Output2 <= Sig4; when others => Output2 <= (others => 'X'); end case; end process; end architecture; 

ModelSim에서 시뮬레이션 실행 후 파형은 Output1과 Output2가 동일한 동작을 보임을 보여줍니다. 셀렉터 Sel이 미정의 값(예: "UU")을 가질 때 when others => 절이 'X'를 출력해 알 수 없는 상태를 알립니다.

콘솔 출력에 50ns에서 메타값 비교 경고가 나옵니다:

VSIM 2> run # ** Warning: NUMERIC_STD."=": metavalue detected, returning FALSE # Time: 50 ns Iteration: 1 Instance: /t14_casewhentb # ** Warning: NUMERIC_STD."=": metavalue detected, returning FALSE # Time: 50 ns Iteration: 1 Instance: /t14_casewhentb # ** Warning: NUMERIC_STD."=": metavalue detected, returning FALSE # Time: 50 ns Iteration: 1 Instance: /t14_casewhentb # ** Warning: NUMERIC_STD."=": metavalue detected, returning FALSE # Time: 50 ns Iteration: 1 Instance: /t14_casewhentb

핵심 정리

다음 튜토리얼로 넘어가 더 고급 VHDL 개념을 배우세요.

VHDL

  1. VHDL 프로시저 예제: 표준 로직 벡터 증가시키기
  2. 몰리브덴이 현대 산업을 형성하는 방식: 용도, 이점, 공급 역학
  3. VHDL 문자열 리스트 구현: 모범 사례와 예제
  4. VHDL 테스트벤치 시뮬레이션 우아하게 종료하기
  5. VHDL PWM 컨트롤러 구현: 설계, 시뮬레이션, FPGA 데모
  6. VHDL 난수 생성: 균일 분포부터 OSVVM까지
  7. 프로세스 내 프로시저로 VHDL FSM 설계 깔끔하게 만들기
  8. VHDL 비순수 함수 활용: FSM 가독성과 유지보수성 높이기
  9. VHDL 함수 마스터하기: 효율적 설계를 위한 실전 가이드
  10. 커터 그라인더(Cutter Grinder) 마스터하기: 실전 기술 가이드