You are on page 1of 16

PROGRAMMABLE ELECTRONIC (MEE 10203)

PART B Write a Word document discussing the following projects. Submit supporting VHDL projects code. Demonstrate the working projects to the instructor (and class). If you are not able to complete this assignment by the due date, submit a progress report documenting your work to that time. 1. Design and implement a DE2/DE1 project that demonstrates a binary to BCD converter. Use the switches SW[15:0] to define the input binary value and the seven-segment displays to show the resulting decimal equivalent. For example, if the first five switches are on: 0x1F, the sevensegment display should read 31. Answers according to table below

Input

Output

Figure 1.1 : How to convert from binary to BCD.

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

Answers According to the Figure 1.1 to slove the problem is: 1. 2. 3. 4. 5. Define the input is 16 bits and the ouput is 20 bits. Define the variable q is 36 bits. Shift to 3 step to left. The variable q valaue q (18 downto 3) equal to input value.

At this stage (shift 3 to left) if variable q(19 downto 16) is bigger than 4 so q(19 downto 16) will add 3. 6. Shift to left for remain 13 step and check if q(19 downto 16), q(23 downto 20), q(27 downto 24), q(31 downto 28) and q(35 downto 32) is bigger than 4 so plus with 3. 7. Lastly the ouput will get the q (35 downto 16) value.

Binary to BCD Converter


library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_UNSIGNED.all;

entity BintoBCD16 is port ( B: in STD_LOGIC_VECTOR (15 downto 0); BCD1, BCD2, BCD3, BCD4, BCD5: out STD_LOGIC_VECTOR (3 downto 0) ); end BintoBCD16;

architecture soalan1 of BintoBCD16 is begin

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

process (B) variable q : STD_LOGIC_VECTOR (39 downto 0);

begin

for n in 0 to 39 loop -- clear the q to all 0 q(n) := '0'; end loop;

q (18 downto 3) := B (15 downto 0);

for n in 0 to 12 loop if q (19 downto 16) > 4 then

-- shift 13 time according to the table in figure 1.1

q (19 downto 16) := q (19 downto 16) + 3; end if;

if q (23 downto 20) > 4 then q (23 downto 20) := q (23 downto 20) + 3; end if;

if q (27 downto 24) > 4 then q (27 downto 24) := q (27 downto 24) + 3; end if;

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

if q (31 downto 28) > 4 then q (31 downto 28) := q (31 downto 28) + 3; end if;

if q (35 downto 32) > 4 then q (35 downto 32) := q (35 downto 32) + 3; end if;

q(36 downto 1) := q(35 downto 0); -- shift bit end loop; BCD1 <= q (19 downto 16); BCD2 <= q (23 downto 20); BCD3 <= q (27 downto 24); BCD4 <= q (31 downto 28); BCD5 <= q (35 downto 32); end process; end soalan1;

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

Figure 1.2: Compilation without error Binary to BCD

Figure 1.3 : Waveform analysis compare to Figure 1.1.

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

(17 bit) Input

BINARY TO BCD CONVERTER

(20 bit) Output

7 SEGMENT DISPLAY

Figure 1.4 : Blok diagram

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

BCD to 7 Segment Modification


library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_UNSIGNED.all;

entity BintoBCD16 is port ( B: in STD_LOGIC_VECTOR (15 downto 0); unit : out STD_LOGIC_VECTOR (6 downto 0); -- output to 7 segment unit ten : out STD_LOGIC_VECTOR (6 downto 0); -- output to 7 segment ten hundred : out STD_LOGIC_VECTOR (6 downto 0); -- output to 7 segment hundred thousan : out STD_LOGIC_VECTOR (6 downto 0); -- output to 7 segment thousan tthousan : out STD_LOGIC_VECTOR (6 downto 0) -- output to 7 segment unit ten thousan ); end BintoBCD16;

architecture soalan1 of BintoBCD16 is begin

process (B) variable q : STD_LOGIC_VECTOR (39 downto 0); variable BCD1: STD_LOGIC_VECTOR (3 downto 0); variable BCD2: STD_LOGIC_VECTOR (3 downto 0); variable BCD3: STD_LOGIC_VECTOR (3 downto 0);

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

variable BCD4: STD_LOGIC_VECTOR (3 downto 0); variable BCD5: STD_LOGIC_VECTOR (3 downto 0);

begin

for n in 0 to 39 loop q(n) := '0'; end loop;

q (18 downto 3) := B (15 downto 0);

for n in 0 to 12 loop

if q (19 downto 16) > 4 then

-- check if unit large than 4

q (19 downto 16) := q (19 downto 16) + 3; end if;

if q (23 downto 20) > 4 then

-- check if ten large than 4

q (23 downto 20) := q (23 downto 20) + 3; end if;

if q (27 downto 24) > 4 then

-- check if hundred large than 4

q (27 downto 24) := q (27 downto 24) + 3; end if;

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

if q (31 downto 28) > 4 then

-- check if thousand large than 4

q (31 downto 28) := q (31 downto 28) + 3; end if;

if q (35 downto 32) > 4 then

-- check if ten thousand large than 4

q (35 downto 32) := q (35 downto 32) + 3; end if;

q(36 downto 1) := q(35 downto 0); -- shift bit end loop;

BCD1 := q (19 downto 16); BCD2 := q (23 downto 20); BCD3 := q (27 downto 24); BCD4 := q (31 downto 28); BCD5 := q (35 downto 32);

-- output for BCD unit -- output for BCD ten -- output for BCD hundred -- output for BCD thousand -- output for BCD ten thousand

CASE BCD1 IS when "0000" => unit <= "1000000" ; -- 0 when "0001" => unit <= "1111001" ; -- 1 when "0010" => unit <= "0100100" ; -- 2 when "0011" => unit <= "0110000" ; -- 3 when "0100" => unit <= "0011001" ; -- 4 when "0101" => unit <= "0010010" ; -- 5 when "0110" => unit <= "0000010" ; -- 6

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

10

when "0111" => unit <= "1111000" ; -- 7 when "1000" => unit <= "0000000" ; -- 8 when "1001" => unit <= "0010000" ; -- 9 when "1010" => unit <= "0001000" ; -- 10 or A when "1011" => unit <= "0000011" ; -- 11 or B when "1100" => unit <= "1000110" ; -- 12 or C when "1101" => unit <= "0100001" ; -- 13 or D when "1110" => unit <= "0000110" ; -- 14 or E when "1111" => unit <= "0001110" ; -- 15 or F when others => unit <= "1111111" ; -- JUST TURN ON ALL LIGHTS end case;

CASE BCD2 IS when "0000" => ten <= "1000000" ; -- 0 when "0001" => ten <= "1111001" ; -- 1 when "0010" => ten <= "0100100" ; -- 2 when "0011" => ten <= "0110000" ; -- 3 when "0100" => ten <= "0011001" ; -- 4 when "0101" => ten <= "0010010" ; -- 5 when "0110" => ten <= "0000010" ; -- 6 when "0111" => ten <= "1111000" ; -- 7 when "1000" => ten <= "0000000" ; -- 8 when "1001" => ten <= "0010000" ; -- 9 when "1010" => ten <= "0001000" ; -- 10 or A when "1011" => ten <= "0000011" ; -- 11 or B

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

11

when "1100" => ten <= "1000110" ; -- 12 or C when "1101" => ten <= "0100001" ; -- 13 or D when "1110" => ten <= "0000110" ; -- 14 or E when "1111" => ten <= "0001110" ; -- 15 or F when others => ten <= "1111111" ; -- JUST TURN ON ALL LIGHTS end case;

CASE BCD3 IS when "0000" => hundred <= "1000000" ; -- 0 when "0001" => hundred <= "1111001" ; -- 1 when "0010" => hundred <= "0100100" ; -- 2 when "0011" => hundred <= "0110000" ; -- 3 when "0100" => hundred <= "0011001" ; -- 4 when "0101" => hundred <= "0010010" ; -- 5 when "0110" => hundred <= "0000010" ; -- 6 when "0111" => hundred <= "1111000" ; -- 7 when "1000" => hundred <= "0000000" ; -- 8 when "1001" => hundred <= "0010000" ; -- 9 when "1010" => hundred <= "0001000" ; -- 10 or A when "1011" => hundred <= "0000011" ; -- 11 or B when "1100" => hundred <= "1000110" ; -- 12 or C when "1101" => hundred <= "0100001" ; -- 13 or D when "1110" => hundred <= "0000110" ; -- 14 or E when "1111" => hundred <= "0001110" ; -- 15 or F when others => hundred <= "1111111" ; -- JUST TURN ON ALL LIGHTS

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

12

end case;

CASE BCD4 IS when "0000" => thousan <= "1000000" ; -- 0 when "0001" => thousan <= "1111001" ; -- 1 when "0010" => thousan <= "0100100" ; -- 2 when "0011" => thousan <= "0110000" ; -- 3 when "0100" => thousan <= "0011001" ; -- 4 when "0101" => thousan <= "0010010" ; -- 5 when "0110" => thousan <= "0000010" ; -- 6 when "0111" => thousan <= "1111000" ; -- 7 when "1000" => thousan <= "0000000" ; -- 8 when "1001" => thousan <= "0010000" ; -- 9 when "1010" => thousan <= "0001000" ; -- 10 or A when "1011" => thousan <= "0000011" ; -- 11 or B when "1100" => thousan <= "1000110" ; -- 12 or C when "1101" => thousan <= "0100001" ; -- 13 or D when "1110" => thousan <= "0000110" ; -- 14 or E when "1111" => thousan <= "0001110" ; -- 15 or F when others => thousan <= "1111111" ; -- JUST TURN ON ALL LIGHTS

end case;

CASE BCD5 IS when "0000" => tthousan <= "1000000" ; -- 0

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

13

when "0001" => tthousan <= "1111001" ; -- 1 when "0010" => tthousan <= "0100100" ; -- 2 when "0011" => tthousan <= "0110000" ; -- 3 when "0100" => tthousan <= "0011001" ; -- 4 when "0101" => tthousan <= "0010010" ; -- 5 when "0110" => tthousan <= "0000010" ; -- 6 when "0111" => tthousan <= "1111000" ; -- 7 when "1000" => tthousan <= "0000000" ; -- 8 when "1001" => tthousan <= "0010000" ; -- 9 when "1010" => tthousan <= "0001000" ; -- 10 or A when "1011" => tthousan <= "0000011" ; -- 11 or B when "1100" => tthousan <= "1000110" ; -- 12 or C when "1101" => tthousan <= "0100001" ; -- 13 or D when "1110" => tthousan <= "0000110" ; -- 14 or E when "1111" => tthousan <= "0001110" ; -- 15 or F when others => tthousan <= "1111111" ; -- JUST TURN ON ALL LIGHTS

end case;

end process; end soalan1;

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

14

Figure 1.5: Compile the BCD to 7 Segment without error.

Figure 1.6 : Waveform BCD to 7 Segment

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

15

Figure 1.7: Device Setting.

Figure 1.8 : Pin Planner Setting

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

PROGRAMMABLE ELECTRONIC (MEE 10203)

16

Figure 1.9 Download to DE2 board

Figure 1.10 The output result

Mohd Syukur bin Azizan | Mohd Nazimudin bin Ibrahim

You might also like