Till KTH:s startsida Till KTH:s startsida

Ändringar mellan två versioner

Här visas ändringar i "VHDL for a codelock (en)" mellan 2014-11-04 17:12 av William Sandqvist och 2014-11-04 20:40 av William Sandqvist.

Visa < föregående | nästa > ändring.

VHDL for a codelock (en)

en VHDL föor ett kodlåsa codelock BDeskcrivning av kodlåsmallenption of the codelock template pdf codelockVHDL_eng.pdf

mallstatedia.gif

Kodlåsmallen gäller för ett förenklat lås som öppnar när man trycker på tangenten för "1" och sedan släpper tangenten.¶ Så gott som all digital design sker numera med hjälp av högnivåspråk som VHDL/VERILOG. Vår grundkThe Code Lock template applies to a simplified lock that opens when you press the key "1" and then release the key.¶

Almost all digital designs are now carried out using high-level languages like VHDL/Verilog. Our basic co
urse in digital- teknik ger inte utrymme att lära ut VHDL-språket, däremot kommer Du att kunna omforma "kodlåsmallen" till användbar VHDL-kod inför laborationen.¶ Tycker Du att VHDL-språket verkarchnology does not allow to teach VHDL language, however, you will be able to transform the "template code lock" into useful VHDL code at the lab.¶

If you think that the VHDL language seems
interessant, så har skolan sedan flerating, then the school has several advanced digital tekniska fortsättningskchnology courser.s

lockmall.vhd

library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; entity codelock is port( clk: in std_logic; K: in std_logic_vector(1 to 3); R: in std_logic_vector(1 to 4); q: out std_logic_vector(4 downto 0); UNLOCK: out std_logic ); end codelock; architecture behavior of codelock is subtype state_type is integer range 0 to 31; signal state, nextstate: state_type; begin nextstate_decoder: -- next state decoding part process(state, K, R) begin case state is when 0 => if (K = "001" and R ="0001") then nextstate <= 1; else nextstate <= 0; end if; when 1 => if (K = "001" and R = "0001") then nextstate <= 1; elsif (K = "000" and R = "0000") then nextstate <= 2; else nextstate <= 0; end if; when 2 to 30 => nextstate <= state + 1; when 31 => nextstate <= 0; end case; end process; debug_output: -- display the state q <= conv_std_logic_vector(state,5); output_decoder: -- output decoder part process(state) begin case state is when 0 to 1 => UNLOCK <= '0'; when 2 to 31 => UNLOCK <= '1'; end case; end process; state_register: -- the state register part (the flipflops) process(clk) begin if rising_edge(clk) then state <= nextstate; end if; end process; end behavior;

vhdlfile lockmall.vhd ( text.gif lockmall.txt)

Mooreautomat Kodlåset är utformat som en Moore-atomat.¶ mooremodel.png¶ De olika blocken identifieras i koden med etiketter, machine The code lock is The code lock is designed as a Moore machine.¶

mooremodel.PNG¶

The different blocks in the code are identified with
"labels".

labels.gif

VHDL processer Meds With a "processer" kan myou can bdeskcriva vad ett block ska utföra utan att behövabe what should be performed in a block without having to gåo into the detaljerils omf hur detta skall gå tillow this should be done.

process.pngbmp

VHDL-k coden är skriven som ett antal sådana is written as such processers.

Programmets delararts of the program parts.png

entity architecture next_state_decoder: output_decoder: state_registers:

entity entity.pngbmp

Programmets entity är en beskrivning av kodlåset som en "black box" med insignaler och utsignaler.

Bitar ochs and Bitvekctorers bitvektor.png

Genom att välja datatyper som stämmer överens med problemet, blir det mindre risk för misstag. Man kan tex. anpassaYou can customize the indexeringen av of variablers så att den övereo that it is consistämmer med hur detta anges i datablad, på så sätt minimerar man risken att man "skriver av" fel.ent with the data sheets - less risk of mistakes!

Architecture - egendefinierade suitable datatypers Avsnittet architecture innehåller beskrivningen av blockets beteende.

datatyp.png¶ Vi skapar här en egendefinieradbmp¶

Here we create a new
datatype, state_type som passar för att beskriva Moore-automatens tillstånd. Fördelen med detta är att kompilatorns felutskrifter kan hjälpa oss, om vi råkar använda värden utanför variablernas definitionsområden, that can have integer values between 0 and 31. The compiler then prevents us from (accidentally) use other values. Signals state and nextstate are of this datatype.

Architecture - tillståndsavkodarennext state decoder next_state_decoder.png

Nästa tillstånds avkodaren är programmets centrala del. Genom att användaext statre decoder is the central part of the program. By using the case-statsen kan man skriva kement you can write the code in så att den helt följer tillståndsuch a way that it confirms to the state diagrammet.

Felsökningshjälpmedel - state som visas med fem lysdioder debug.png¶ För att kunna felsöka hårdvaran, labutrustningen, vill vi kunna följa vilket tillstånd automaten befinner sigTroubleshooting help - the state is shown with five LEDs debug.gif¶

To troubleshoot, we want to be able to follow which state the machine is
in. FThe funkctionen conv_std_logic_vector() omvandlar state (ett heltal mellaconverts ,state (an integer between 0...31) till eno to a 5-bitars bitvekctor q, q(4) ... q(0). För att kunna använda denna konverteringsIn order to use this conversion funkction behöver man ta med biblioteketone has to include the library IEEE.std_logic_arith.all.

UtgångsavkodarenOutput decoder output_decoder.gif

Utgångsavkodaren är skriven "rakt på sak" med ett case-uttryck.¶ TillståndsThe output decoder is written "straightforward" by a case-statement.¶

State
registeret stateregister.png

Genom att vi använderBy using the funkctionen rising_edge(clk) "förstår" kompilatorn att vi vill utnyttja vipporna som finns i MAX-kretsen för att bygga ettwe let the compiler "understand" that we want to use the flip-flops inside the MAX-chip in order to build a register.

VidAt laborationen utökar Du denna kod till ett fyrsiffrigt kombinationslås you expand this code to create a four digit code lock! 4digit.png

Visa tidigare händelser (2)