Showing posts with label VHDL. Show all posts
Showing posts with label VHDL. Show all posts

8/03/2013

Hướng dẫn Tạo Project FPGA từ code VHDL sang Altium và Nanoboard 3000

Download Code Here
-----------------------------------------------------------------------------------------------------------
Chào các bạn hôm nay mình sẽ viết 1 bài để hướng dẫn 
các bạn tạo 1 Project FPGA trong Altium để nạp nào Nanoboard 3000.
1.những phần mềm cần có:
- Active HDL
- Altium
2. Viết chương trình bằng ngôn ngữ VHDL trên Active HDL (bài D3_C2 trên Blog).
3. Vẽ mạch. ( Bài D3_C2).
3.1. Một số linh kiện cần dùng và thư viện chứa chúng.
    - FPGA NB3000 Port-Plugin.IntLib
LEDS_RGB
     - FPGA Instruments.IntLib
CLKGEN
     - FPGA NB2DSK01 Port-Plugin.IntLib
CLOCK_REFERENCE
TEST_BUTTON
3.2. Tạo Project trong altium


- Lưu Project vào máy.


- Add thêm File VHDL


 - Copy code từ bên active HDL sang.


- Paste code vào file VHDL bên altium.


- Lưu file VHDL lại


- Biên dịch và sửa lỗi code VHDL


- Tạo file sơ đồ nguyên lý mạch.


- Lưu sơ đồ nguyên lý lại.


- Lấy linh kiện mới tạo ra bằng code VHDL


- Chọn linh kiện vừa tạo và nhấn OK ta sẽ có kinh kiện.


- Linh kiện đã được đặt trong sơ đồ nguyên lý.


- Lấy LEDS_RGB 3 màu trong thư viện của Nanoboard 3000.


- Lấy CLKGEN ( bộ này để chỉnh xung nhịp khi kết nối với nanoboard 3000)


- CLOCK_REFERENCE lấy xung CLOCK.



- Lấy BUTTON để làm nút RESET


- Mạch vẽ xong!


- Kiểm tra sơ đồ nguyên lý và lưu lại lần nữa.


- Kiểm tra Project xem có lỗi không! nếu không có lỗi ta chuyển sang giai đoạn kết nối với Nanoboard 3000.


Các bạn có thể xem video hướng dẫn ở dưới!




---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

8/02/2013

Bộ ghi dịch vào nối tiếp ra nối tiêp (Serial in serial out "SISO")

Download Code Here
-----------------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity nt_nt is
port(
clk : in std_logic;
SI : in BIT;
SO : out BIT
    );
end nt_nt;

architecture nt_nt of nt_nt is
signal tmp: bit_vector(7 downto 0);
begin
    process (clk)
      begin
if (clk'event and clk='1') then
          tmp <= tmp(6 downto 0)& SI;
        end if;
    end process;
    SO <= tmp(7);
end nt_nt;
--clk=20Mhz; SI= random 10ns;
---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

6.2. Chương trình sử dụng 4 button làm đầu vào, đầu ra là LED0, LED1, LED2, LED3 sáng tương ứng khi bấm button 0,1,2,3

Download Code Here
-----------------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity D6_C2 is
port(
SI : in STD_LOGIC_VECTOR(3 downto 0);
SO : out STD_LOGIC_VECTOR(3 downto 0)
    );
end D6_C2;

architecture D6_C2 of D6_C2 is
begin
process(SI)
begin
SO<=SI;
end process;
end D6_C2;
-- clk=1Mhz
---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

6.1. Thiết kế và mô phỏng bộ đếm từ 0 tới 99 có chức năng lựa chọn đếm tiến hoặc đếm lùi và hiển thị kết quả đếm trên LED 7 thanh.

Download Code Here
-----------------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all;

entity D6_C1 is
port(
rst : in STD_LOGIC;
sel : in STD_LOGIC;
clk : in STD_LOGIC;
seg1 : out STD_LOGIC_VECTOR(7 downto 0);--hang don vi
seg2 : out STD_LOGIC_VECTOR(7 downto 0)--hang chuc
    );
end D6_C1;

architecture D6_C1 of D6_C1 is
begin
process(rst,clk,sel)
variable temp1:integer range 0 to 10;
variable temp2:integer range 0 to 10;
begin
if (rst='1') then
temp1:=0;
temp2:=0;
elsif (rising_edge(clk)) then
if (sel='1') then
if (temp1=10) then
temp1:=0;
temp2:=temp2+1;
if (temp2=10) then temp2:=0;
end if;
else temp1:=temp1+1;
end if;
elsif (sel='0') then
if(temp1=0) then
temp1:=9;
temp2:=temp2-1;
if (temp2=0) then temp2:=9;
end if;
else temp1:=temp1-1;
end if;
end if;
end if;

case temp1 is
                when 0 => seg1<= x"C0";
                when 1 => seg1<= x"F9";
                when 2 => seg1<= x"A4";
                when 3 => seg1<= x"B0";
                when 4 => seg1<= x"99";
                when 5 => seg1<= x"92";
                when 6 => seg1<= x"82";
                when 7 => seg1<= x"F8";
when 8 => seg1<= x"80";
                when 9 => seg1<= x"90";
when others =>NULL;
end case;
case temp2 is
                when 0 => seg2<= x"C0";
                when 1 => seg2<= x"F9";
                when 2 => seg2<= x"A4";
                when 3 => seg2<= x"B0";
                when 4 => seg2<= x"99";
                when 5 => seg2<= x"92";
                when 6 => seg2<= x"82";
                when 7 => seg2<= x"F8";
when 8 => seg2<= x"80";
                when 9 => seg2<= x"90";
when others =>NULL;
end case;
end process;
end D6_C1;
-- rst= 10kHz; sel=50Khz; clk=20Mhz;
---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

5.2. Chương trình điều khiển 8 led đơn trên Nanoboad sáng theo quy luật: LED0,1,2,3 sáng màu xanh, LED 4,5,6,7 tắt – LED0,1,2,3 tắt, LED 4,5,6,7 sáng màu đỏ

Download Code Here
-----------------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity D5_C2 is
port(
clk : in STD_LOGIC;
seg : out STD_LOGIC_VECTOR(7 downto 0)
    );
end D5_C2;

architecture D5_C2 of D5_C2 is
begin

process(clk)
begin
  if(clk='1') then seg<="00001111";
  else seg<="11110000";
  end if;
end process;
end D5_C2;
-- clk=10Mhz;  
---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

5.1. Thiết kế và mô phỏng thanh ghi dịch với số bit có thể thay đổi được và có thể lựa chọn được chức năng thực hiện: vào nối tiếp ra nối tiếp hoặc vào nối tiếp ra song song.

Download Code Here
-----------------------------------------------------------------------------------------------------------

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity D5_C1 is
generic (n:integer:=8);
port(
clk : in STD_LOGIC;
sel : in STD_LOGIC;
SI : in bit;
Q : out bit_VECTOR(n-1 downto 0)
    );
end D5_C1;

--}} End of automatically maintained section

architecture D5_C1 of D5_C1 is
signal temp:bit_vector(n-1 downto 0);
  begin
    process (clk,SI)
      begin
        if (clk'event and clk='1') then
          temp <= temp(n-2 downto 0)& SI;
        end if;
    end process;
process(sel,clk)
begin
if (rising_edge(clk))then
if (sel='1') then Q(0)<=temp(n-1);
else
if (sel='0') then Q<=temp;
end if;
end if;
end if;
end process;
end D5_C1;

---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

4.2. Chương trình điều khiển 8 led đơn sáng lan theo quy luật LED0 sáng, LED1 và LED0 sáng, LED2, LED1 và LED0 sáng,…, 7 LED cùng sáng

Download Code Here
-----------------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity D4_C2 is
port(
rst : in STD_LOGIC;
clk : in STD_LOGIC;
seg : out STD_LOGIC_VECTOR(7 downto 0)
    );
end D4_C2;

architecture D4_C2 of D4_C2 is
begin
process(rst,clk)
variable dem:integer range 0 to 8;
begin
if (rst='1') then dem:=0;
elsif (rising_edge(clk)) then
if (dem=8) then dem:=0;
else dem:=dem+1;
end if;
end if;
case dem is
when 0=> seg <="00000000";
when 1=> seg <="00000001";
when 2=> seg <="00000011";
when 3=> seg <="00000111";
when 4=> seg <="00001111";
when 5=> seg <="00011111";
when 6=> seg <="00111111";
when 7=> seg <="01111111";
when others=> seg <="11111111";
end case;
end process;

end D4_C2;
--rst=0.5Mhz; clk=20Mhz;
---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

4.1. Thiết kế và mô phỏng bộ đếm 9 và hiển thị kết quả đếm trên LED 7 thanh theo phương pháp máy trạng thái

Download Code Here
-----------------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity D4_C1 is
port(
rst : in STD_LOGIC;
clk : in STD_LOGIC;
seg : out STD_LOGIC_VECTOR(7 downto 0)
    );
end D4_C1;
architecture D4_C1 of D4_C1 is
type state is (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9);
signal s:state;
begin

next_state:process(rst,clk)
begin
if (rst='1') then s<=s0;
else
if (rising_edge(clk)) then
case s is
when s0 => s <=s1;
when s1 => s <=s2;
when s2 => s <=s3;
when s3 => s <=s4;
when s4 => s <=s5;
when s5 => s <=s6;
when s6 => s <=s7;
when s7 => s <=s8;
when s8 => s <=s9;
when s9 => s <=s0;
end case;
end if;
end if;
end process;
output_state:process(s)
begin
case s is
                when s0 => seg<= x"C0";
                when s1 => seg<= x"F9";
                when s2 => seg<= x"A4";
                when s3 => seg<= x"B0";
                when s4 => seg<= x"99";
                when s5 => seg<= x"92";
                when s6 => seg<= x"82";
                when s7 => seg<= x"F8";
                when s8 => seg<= x"80";
                when s9 => seg<= x"90";
end case;
end process;
end D4_C1;
-- rst=0.5Mhz; clk=20Mhz;
---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

8/01/2013

3.2. Chương trình điều khiển 8 led đơn sáng lần lượt theo quy luật: LED0 sáng – LED1 sáng – ….- LED7 sáng.

Download Code Here
-----------------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity D3_C2 is
port(
rst : in STD_LOGIC;
clk : in STD_LOGIC;
seg : out STD_LOGIC_VECTOR(7 downto 0)
    );
end D3_C2;

architecture D3_C2 of D3_C2 is
begin
process(rst,clk)
variable dem:integer range 0 to 9;
begin
if (rst='1') then dem:=0;
elsif (rising_edge(clk)) then
if (dem=8) then dem:=0;
else dem:=dem+1;
end if;
end if;
case dem is
when 0=> seg <="00000000";
when 1=> seg <="00000001";
when 2=> seg <="00000010";
when 3=> seg <="00000100";
when 4=> seg <="00001000";
when 5=> seg <="00010000";
when 6=> seg <="00100000";
when 7=> seg <="01000000";
when others=> seg <="10000000";
end case;
end process;
end D3_C2;
-- rst=500Khz; clk=10Mhz;
---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

3.1. Thiết kế và mô phỏng bộ đếm 9 có chức năng lựa chọn đếm tiến hoặc đếm lùi và hiển thị kết quả đếm trên LED 7 thanh.

Download Code Here
-----------------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity D3_C1 is
port(
rst : in STD_LOGIC;
sel : in STD_LOGIC;
clk : in STD_LOGIC;
seg : out STD_LOGIC_VECTOR(7 downto 0)
    );
end D3_C1;

architecture D3_C1 of D3_C1 is
begin
process(rst,clk,sel)
variable dem:integer range 0 to 9;
begin
if (rst='1') then dem:=0;
elsif (rising_edge(clk)) then
if (sel='1') then
if (dem=9) then dem:=0;
else dem:=dem+1;
end if;
elsif (sel='0') then
if(dem=0) then dem:=9;
else dem:=dem-1;
end if;
end if;
end if;
case dem is
                when 0 => seg<= x"C0";
                when 1 => seg<= x"F9";
                when 2 => seg<= x"A4";
                when 3 => seg<= x"B0";
                when 4 => seg<= x"99";
                when 5 => seg<= x"92";
                when 6 => seg<= x"82";
                when 7 => seg<= x"F8";
                when 8 => seg<= x"80";
                when others => seg<= x"90";
end case;
end process;
end D3_C1;
-- rst=500Khz; sel=1Mhz; clk=20Mhz;
---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

2.2. Chương trình đếm tiến theo mã nhị phân Kđ = 128, đầu ra hiển thị trên 8 LED đơn

Download Code Here
-----------------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_ARITH.all;

entity D2_C2 is
port(
rst : in STD_LOGIC;
clk : in STD_LOGIC;
seg : out STD_LOGIC_VECTOR(7 downto 0)
    );
end D2_C2;

--}} End of automatically maintained section

architecture D2_C2 of D2_C2 is
begin
process(rst,clk)
variable dem:integer range 0 to 127;
begin
if (rst='1') then dem:=0;
else
if (rising_edge(clk)) then
if(dem=127) then dem:=0;
else dem:=dem+1;
end if;
end if;
end if;
seg<=conv_std_logic_vector(dem,8);
end process;

end D2_C2;
-- rst=0 or 78Khz; clk=25Mhz;


---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

2.1. Thiết kế và mô phỏng bộ đếm BCD và hiển thị kết quả đếm trên LED 7 thanh theo phương pháp máy trạng thái.

Download Code Here
-----------------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity D2_C1 is
port(
rst : in STD_LOGIC;
clk : in STD_LOGIC;
Q : out STD_LOGIC_VECTOR(7 downto 0)
    );
end D2_C1;

architecture D2_C1 of D2_C1 is
type state is (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9);
signal s:state;
begin

next_state:process(rst,clk)
begin
if (rst='1') then s<=s0;
else
if (rising_edge(clk)) then
case s is
when s0 => s <=s1;
when s1 => s <=s2;
when s2 => s <=s3;
when s3 => s <=s4;
when s4 => s <=s5;
when s5 => s <=s6;
when s6 => s <=s7;
when s7 => s <=s8;
when s8 => s <=s9;
when s9 => s <=s0;
end case;
end if;
end if;
end process;
output_state:process(s)
begin
case s is
when s0=> Q<="00000000";
when s1=> Q<="00000001";
when s2=> Q<="00000010";
when s3=> Q<="00000011";
when s4=> Q<="00000100";
when s5=> Q<="00000101";
when s6=> Q<="00000110";
when s7=> Q<="00000111";
when s8=> Q<="00001001";
when s9=> Q<="00001010";
end case;
end process;
end D2_C1;
-- rst = 0.5Mhz, clk=10Mhz
---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

1.2. Chương trình điều khiển 2 led : LED0 và LED7 sáng nhấp nháy theo chu kỳ 1s.

Download Code Here
-----------------------------------------------------------------------------------------------------------


library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity D1_C2 is
port(
clk:in std_logic;
s0,s7 : out STD_LOGIC
    );
end D1_C2;

--}} End of automatically maintained section

architecture D1_C2 of D1_C2 is
begin

process(clk)
begin
 if(clk='1') then s0<='1';s7<='1';
 else s0<='0';s7<='0';
 end if;
end process;

end D1_C2;
-- clk=0.5hz


---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân

1.1. Thiết kế và mô phỏng bộ đếm BCD có chức năng lựa chọn đếm tiến hoặc đếm lùi và hiển thị kết quả đếm trên LED 7 thanh.

Download Code Here
-----------------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity D1_C1 is
port(
clk : in STD_LOGIC;
sel : in STD_LOGIC;
rst : in STD_LOGIC;
seg : out STD_LOGIC_VECTOR(7 downto 0)
    );
end D1_C1;

architecture D1_C1 of D1_C1 is
signal dem:integer range 0 to 9;
begin
process(rst,clk,sel)
variable dem:integer range 0 to 9;
begin
if (rst='1') then dem:=0;
elsif (rising_edge(clk)) then
if (sel='1') then
if (dem=9) then dem:=0;
else dem:=dem+1;
end if;
elsif (sel='0') then
if(dem=0) then dem:=9;
else dem:=dem-1;
end if;
end if;
end if;
case dem is
when 0=>seg<="00000000";
when 1=>seg<="00000001";
when 2=>seg<="00000010";
when 3=>seg<="00000011";
when 4=>seg<="00000100";
when 5=>seg<="00000101";
when 6=>seg<="00000110";
when 7=>seg<="00000111";
when 8=>seg<="00001000";
when others=>seg<="00001001";
end case;
end process;
end D1_C1;
-- rst:500Khz, sel:1Mhz, clk:20Mhz
---------------------------------------------------------------------------------------------------------
Chi tiết xin liên hệ:
Nguyễn Duy Tân
Email: nguyenduytan1909@gmail.com hoặc duytandhdt3k5@gmail.com
Yahoo: nguyenduytan1909
Skype: Tannd1909
FaceBook:Nguyễn Duy Tân