Cov txheej txheem:

VHDL Basys3: Txuas 4 Game: 5 Kauj Ruam
VHDL Basys3: Txuas 4 Game: 5 Kauj Ruam

Video: VHDL Basys3: Txuas 4 Game: 5 Kauj Ruam

Video: VHDL Basys3: Txuas 4 Game: 5 Kauj Ruam
Video: 36C3 - Open Source is Insufficient to Solve Trust Problems in Hardware - deutsche Übersetzung 2024, Hlis ntuj nqeg
Anonim
VHDL Basys3: Txuas 4 Game
VHDL Basys3: Txuas 4 Game

Taw qhia:

Nov yog Kev Sib Txuas 4 Digital Logic Game tsim hauv VHDL siv Vivado Software thiab programmed rau Basys3 Board. Kev tsim kho thiab tsim qauv ntawm txoj haujlwm no yog theem nrab, tab sis cov neeg tuaj tshiab tuaj yeem luam cov kauj ruam thiab tsim cov game digital.

Qhov kev ua si ua haujlwm zoo li Connect 4 game. Cov neeg ua si tuaj yeem txav lawv tus cursor hla lub vijtsam siv cov nyees khawm sab laug thiab sab xis pom ntawm lub rooj tsavxwm. Nias khawm nruab nrab ntawm lub rooj tsavxwm yuav ua rau cov neeg ua si tso lawv tus cim rau ntawm kab ntawv ntawd thiab tom qab ntawd nws yuav dhau los ua tus neeg sib tw tom ntej no. Thaum ib tus neeg uas ua ntawv yeej, qhov kev ua si tuaj yeem rov pib dua los ntawm nias lub pob nyem ntawm lub rooj tsavxwm.

Kauj Ruam 1: Cov Lus Qhia Ceev thiab Cov Ntaub Ntawv

Cov Lus Qhia Ceev:

  • Siv peb pawg ntawm PMOD kev sib txuas ntawm lub rooj tsavxwm (JA, JB, JC)

    • 8 Pins (Tsis suav nrog Vcc & GND Pins) siv rau txhua tus PMOD txuas
    • JA - Tswj kab
    • JB - Tswj ntawm Kab Ntsuab
    • JC - Tswj ntawm Kab Liab
  • Lub vijtsam moos ua haujlwm ntawm 960Hz

    Tsuas yog 8 LEDs nyob rau ntawm ib lub sijhawm. Lub vijtsam rov ua haujlwm ntawm lub nrawm txaus lub moos nrawm uas qhov ua rau pom tau tias ntau dua 8 LEDs nyob rau ntawm lub sijhawm

  • Khawm moos ua haujlwm ntawm 5Hz; Kev xaiv tuaj yeem raug nplua kho los ntawm kev kho VHDL code.
  • Kev tiv thaiv sab hauv ntawm Darlington Arrays txaus los tiv thaiv LED hlawv tawm

Qhov kev ua si yog tsim los siv cov khoom siv hauv qab no thiab cov cuab yeej:

  • (1) Basys3 Board
  • (2) LED Matrix Bi-color 8x5:
  • (2) ULN2803 - Darlington Transistor Arrays - Cov ntaub ntawv
  • Spools ntawm Hlau
  • Jumper Hlau
  • Hlau Stripper
  • Breadboards (Square loj yuav tsum txaus)
  • Multimeter thiab Cov Khoom Siv Hluav Taws Xob (Teeb meem)

Kauj Ruam 2: Txuas Cov Khoom Kho Vajtse

Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse
Txuas Kev Kho Vajtse

Cov Lus Qhia:

Txoj hlua ntawm txoj haujlwm tuaj yeem ua rau muaj kev sib sau tsis txaus ntseeg, thov siv koj lub sijhawm thiab txheeb xyuas tias txhua qhov kev sib txuas raug ib qho zuj zus.

Txoj haujlwm koom nrog siv ob lub vijtsam LED tab sis ua ke ua ke los ua ib lub vijtsam loj. Qhov no tuaj yeem ua tiav los ntawm kev txuas txhua kab mus rau tib lub ntsiab lus. Vim tias txhua lub vijtsam yog xim ob xim, kab liab thiab ntsuab ntawm ib lub vijtsam yuav tsum raug khi rau kab liab thiab ntsuab ntawm lwm lub vijtsam. Los ntawm kev ua qhov no, peb tuaj yeem tswj hwm txhua kab nrog tsuas yog 8 tus pin. Lwm tus 16 tus pin yog siv los tswj cov kab ntawm cov zaub. 8 tus pin rau tuaj yeem txuas ncaj qha los ntawm cov hlua txuas txuas mus rau cov kab txuas txuas. Pmod kev sib txuas ua ntej mus rau cov tswv yim ntawm ULN2083A thiab cov zis ntawm ULN2083A txuas ncaj qha rau kab lus ntawm lub vijtsam. Vim tias tus qauv tsim yog 8x8, qee kab yuav lub cev tsis txuas nrog.

  • JA: Kab sib txuas: Kab 1 txog JA: 1 txog Kab 8 rau JA: 10.
  • JA: Red Column sib txuas:
  • JC: Green Column txuas

Thov xa mus rau cov duab tshaj tawm kom paub tias cov pins sib raug rau kab twg/kab twg.

Nco tseg: Cov transistors tau tsim hauv kev tawm tsam, yog li cov LEDs tsis xav tau kev tiv thaiv ntxiv kom txuas nrog lawv hauv koob.

Kauj Ruam 3: Kev Piav Qhia: Vijtsam

Lub vijtsam ua haujlwm ntawm qhov tsis pom kev. Lub vijtsam rov ua kom nrawm dua, uas tib neeg lub qhov muag tsis tuaj yeem pom pom tias qee qhov LEDs tau raug kaw sai thiab qhib. Qhov tseeb, los ntawm kev qeeb lub moos tso saib, ib tus tuaj yeem pom qhov flashing.

Cov zaub tig rau tag nrho yim kab raws li cov ntaub ntawv khaws cia rau cov kab ntawd, thiab cov zaub tig rau ntawm ib kab. Tom qab ntawd nws hloov pauv sai sai rau cov ntaub ntawv txuas ntxiv mus rau yim kab thiab tig mus rau kab tom ntej - thaum muaj tag nrho lwm kab tawm. Cov txheej txheem no tseem txuas ntxiv ntawm qhov nrawm txaus lub moos nrawm uas qhov flickering ntawm LED dhau los ua qhov tsis nco qab.

Cov ntaub ntawv khaws cia rau cov zaub yog pib tam sim tom qab tsim hauv VHDL cov ntaub ntawv raws li hauv qab no:

teeb liab RedA, RedB, RedC, RedD, RedE, RedF, RedG, RedH: std_logic_vector (7 downto 0): = "00000000";

teeb liab GreenA, GreenB, GreenC, GreenD, GreenE, GreenF, GreenG, GreenH: std_logic_vector (7 downto 0): = "00000000"; - Cov ntaub ntawv Kab nyob ntawm kab: GREEN

Nram qab no yog cov ntawv me me ntawm cov txheej txheem uas tswj hwm LED zaub matrix.

- Txheej txheem uas Tswj LED zaub matrixdisplay: txheej txheem (ColCLK) - 0 - 16 txhawm rau ob qho tib si 8X8 RED thiab 8x8 GREEn matrix sib txawv RowCount: ntau yam 0 txog 16: = 0; pib yog (nce_edge (ColCLK)) ces yog (RowCount = 0) ces DORow <= RedA; - Cov ntaub ntawv Kab rau kab sib thooj DOCol <= "1000000000000000"; - Cov kab lus- Rov ua dua tus lej no rau txhua txoj hauv kev mus rau "0000000000000001"- Hloov mus rau RedB, RedC … GreenA, GreenB … GreenH

Thaum kawg ntawm GreenH, txoj cai ua ntej cov txheej txheem xaus cov ntawv luv no suav nrog txhawm rau rov pib RowCount rov qab rau xoom.

yog (RowCount = 15) ces - Rov pib dua tshiab los ntawm kab A RowCount: = 0; lwm tus RowCount: = RowCount + 1; - Hloov los ntawm kab kawg yog tias;

Tam sim no, los piav qhia lub moos uas nyob hauv cov npe nkag siab ntawm cov txheej txheem tso saib. Pawg Basys3 muaj lub moos sab hauv ua haujlwm ntawm 100MHz. Rau peb lub hom phiaj, qhov no nrawm dhau ntawm lub moos yog li peb yuav xav faib lub moos no mus rau 960Hz moos siv cov txheej txheem hauv qab no.

- Cov txheej txheem moos ua haujlwm ntawm 960HzCLKDivider: txheej txheem (CLK) sib txawv clkcount: cov lej sib txawv 0 txog 52083: = 0; pib yog (nce_edge (CLK)) ces clkcount: = clkcount + 1; yog (clkcount = 52083) ces ColCLK <= tsis (ColCLK); clkcount: = 0; kawg yog; kawg yog; txheej txheem kawg;

Kauj Ruam 4: Kev Piav Qhia: Hloov Cov Ntaub Ntawv Tso Tawm

Piav Qhia: Hloov Cov Ntaub Ntawv Tso Tawm
Piav Qhia: Hloov Cov Ntaub Ntawv Tso Tawm

Hauv VHDL tus lej, cov ntaub ntawv lossis cov ntaub ntawv uas yuav muab tso tawm rau lub vijtsam yog tswj los ntawm tus txheej txheem tus lej, uas muaj lub moos sib txawv hauv nws cov npe nkag siab. Txoj cai no tau hu ua BtnCLK, lub moos tsim los txo qis kev debouch ntawm cov nyees khawm thaum lawv nias. Qhov no suav nrog yog tias yog lub pob nyem, tus cursor ntawm kab saum toj kawg nkaus tsis txav nrawm heev hla kab.

- Cov txheej txheem moos ua haujlwm ntawm 5 Hz. ButtonCLK: txheej txheem (CLK) sib txawv btnclkcount: cov lej sib txawv 0 txog 10000001: = 0; pib yog (nce_edge (CLK)) ces yog (btnclkcount = 10000000) ces btnclkcount: = 0; BtnCLK <= tsis (BtnCLK); lwm qhov btnclkcount: = btnclkcount + 1; kawg yog; kawg yog; txheej txheem kawg;

Nrog BtnCLK teeb liab tso tawm ntawm cov txheej txheem no, tam sim no peb tuaj yeem piav qhia tus txheej txheem tus cursor. Tus txheej txheem tus cursor tsuas yog muaj BtnCLK hauv nws cov npe rhiab tab sis hauv cov lej thaiv, lub xeev ntawm cov nyees khawm raug tshuaj xyuas thiab qhov no yuav ua rau cov ntaub ntawv rau RedA, RedB… GreenH hloov. Nov yog cov ntawv luv ntawm tus cursor code, uas suav nrog kev rov pib dua thiab thaiv rau thawj kab ntawv.

tus cursor: txheej txheem (BtnCLK) sib txawv OCursorCol: STD_LOGIC_VECTOR (2 downto 0): = "000"; - OCursorCol khaws cov kab yav dhau los sib txawv NCursorCol: STD_LOGIC_VECTOR (2 downto 0): = "000"; -NCursorCol teeb tsa tus cursor kem tshiab pib-RESET xwm txheej (UP Button) --Board raug tshem tawm rau kev ua si kom rov pib dua yog tias (nce_edge (BtnCLK))) ces yog (RST = '1') ces RedA <= "00000000"; RedB <= "00000000"; RedC <= "00000000"; RedD <= "00000000"; RedE <= "00000000"; RedF <= "00000000"; RedG <= "00000000"; RedH <= "00000000"; GreenA <= "00000000"; GreenB <= "00000000"; GreenC <= "00000000"; GreenD <= "00000000"; GreenE <= "00000000"; GreenF <= "00000000"; GreenG <= "00000000"; GreenH yog (Lbtn = '1') ces NCursorCol: = "111"; - Kem H elsif (Rbtn = '1') ces NCursorCol: = "001"; - Kab B elsif (Cbtn = '1') ces NCursorCol: = OCursorCol; - Kab ntawv nyob qis ib yam NTurnState <= tsis (TurnState); - Ua rau lwm tus neeg tig rov los- Txheeb xyuas kab ntawv tam sim no los ntawm hauv qab mus rau saum thiab tig rau thawj LED uas tsis nyob. Xim nyob ntawm tus neeg siv tam sim no tus cursor xim. rau ck hauv 7 downto 1 loop yog tias (RedA (0) = '1') thiab (RedA (ck) = '0') thiab (GreenA (ck) = '0') ces RedA (Ck) <= '1'; RedA (0) <= '0'; Tawm; kawg yog;

yog tias (GreenA (0) = '1') thiab (RedA (ck) = '0') thiab (GreenA (ck) = '0') ces

GreenA (Ck) <= '1'; GreenA (0) - Red Player GreenA (0) <= '0'; yog (NCursorCol = OCursorCol) ces - Yog tsis muaj dab tsi raug nias RedA (0) <= '1'; elsif (NCursorCol = "111") ces - Yog Lbtn raug nias RedH (0) <= '1'; RedA (0) <= '0'; elsif (NCursorCol = "001") ces - Iff Rbtn raug nias RedB (0) <= '1'; RedA (0) - Green Player RedA (0) <= '0'; yog (NCursorCol = OCursorCol) ces GreenA (0) <= '1'; elsif (NCursorCol = "111") ces GreenH (0) <= '1'; GreenA (0) <= '0'; elsif (NCursorCol = "001") ces GreenB (0) <= '1'; GreenA (0) <= '0'; kawg yog; rooj plaub xaus;

Nco tseg, thawj rooj plaub nqe lus hu ua: OCursorCol (uas sawv cev rau Old Cursor Column) yog qhov pib ntawm lub xeev lub tshuab kawg. Txhua kab ntawm cov zaub raug kho raws li nws lub xeev hauv FSM. Muaj 8 kab ntawv yog li 3-ntsis binary tooj teeb tau siv los txheeb xyuas txhua kab ntawv raws li lub xeev. Yuav ua li cas FSM txav ntawm lub xeev yog nyob ntawm lub pob uas raug nias. Hauv cov ntawv me me saum toj no, yog tias khawm sab laug raug nias, FSM yuav txav mus rau "111" uas yuav yog kab ntawv kawg ntawm cov zaub. Yog tias khawm sab xis, FSM yuav txav mus rau "001" uas yuav yog kab thib ob ntawm cov zaub.

Yog tias khawm nruab nrab raug nias, FSM yuav tsis txav mus rau lub xeev tshiab tab sis yuav hloov qhov hloov pauv hauv TurnState teeb liab, uas yog lub cim me me kom nco ntsoov tias tus neeg uas ua ntawv tig nws yog dab tsi. Ib qho ntxiv, khawm nruab nrab yuav khiav txoj cai thaiv kab ntawv uas tshawb xyuas yog tias muaj kab tsis muaj dab tsi nyob hauv qab heev txhua txoj hauv kev mus rau saum. Nws yuav sim tso tus cim rau hauv qis tshaj, tsis ua tiav kab. Nco ntsoov, qhov no yog txuas plaub qhov kev ua si.

Hauv kab lus hais txog zauv hu ua: TurnState, peb hloov pauv tus cursor xim yog dab tsi thiab kab twg ntawm thawj kab peb xav hloov cov ntaub ntawv kom thiaj li tso saib cov txheej txheem tuaj yeem cuam tshuam qhov kev hloov pauv.

Peb rov hais dua txoj cai yooj yim no rau xya qhov seem. Daim duab FSM tuaj yeem pab tau kom nkag siab tias lub xeev tab tom hloov pauv li cas.

Kauj ruam 5: Code

Code
Code

Nov yog tus lej ua haujlwm rau Txuas 4 uas tuaj yeem suav ua ke hauv VHDL siv Vivado Software.

Ib qho kev txwv kuj tau muab los tso cai rau koj kom ua tiav qhov kev ua si thiab khiav.

Peb tau muab daim duab thaiv kab lus uas piav qhia yuav ua li cas cov tswv yim thiab cov txiaj ntsig ntawm txhua cov txheej txheem cuam tshuam nrog.

Pom zoo: