VHDL:Programmeringstips
From Robin
(Difference between revisions)
(→'''downto''' og '''to''') |
(→'''downto''' og '''to''') |
||
Line 29: | Line 29: | ||
'''downto''' ''har høyeste bitnr som'' '''MSB''' | '''downto''' ''har høyeste bitnr som'' '''MSB''' | ||
'''to''' ''har høyeste bitnr som'' '''LSB''' | '''to''' ''har høyeste bitnr som'' '''LSB''' | ||
+ | '''Når man binder tall sammen''' med ''&'' kommer alltid '''MSB først''' | ||
- | + | Eksempel | |
signal downs : std_logic_vector(7 downto 0); | signal downs : std_logic_vector(7 downto 0); | ||
signal ups : std_logic_vector(0 to 7); | signal ups : std_logic_vector(0 to 7); | ||
- | |||
- | |||
- | |||
- | |||
- | |||
downs <= x"05"; | downs <= x"05"; | ||
- | + | ups <= downs; -- ups = 0x05 | |
- | + | ||
- | ups <= downs; | + | |
- | + | ||
downs <= x"03"; | downs <= x"03"; | ||
- | + | ups(4 to 7) <= downs(3 downto 0); -- ups = 0x03 | |
- | + | ups(4 to ups'high) <= downs(3 downto 0); -- ups = 0x03 | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | ups(4 to ups'high) <= downs(3 downto 0); -- | + | |
- | + | ||
downs <= x"E4"; | downs <= x"E4"; | ||
- | + | ups <= "0000" & downs(3 downto 0); -- ups = 0x04 | |
- | ups <= | + | ups <= (ups'low to ups'high -4 => '1') & downs(3 downto 0); -- ups = 0xF4 |
- | + | ||
- | downs <= " | + | downs <= "1001" & ups(4 to 7); -- downs = 0x94 |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + |
Current revision as of 08:32, 20 May 2008
Contents |
VHDL Programmeringstips
Hvordan teste om alle bit i en std_logic_vector = '1'
if A = (A'range => '1') then ... else ... end if;
Hvordan sette alle bit i en std_logic_vector like
A <= (others => '1'); A_2D <= (others=>(others => '1')); --hvis todimensjonalt array
Hvordan vente på en verdi som skal være stabil en periode
wait until (CLK='1' and CLK'stable(2 ns));
downto og to
downto har høyeste bitnr som MSB to har høyeste bitnr som LSB Når man binder tall sammen med & kommer alltid MSB først
Eksempel
signal downs : std_logic_vector(7 downto 0); signal ups : std_logic_vector(0 to 7);
downs <= x"05"; ups <= downs; -- ups = 0x05 downs <= x"03"; ups(4 to 7) <= downs(3 downto 0); -- ups = 0x03 ups(4 to ups'high) <= downs(3 downto 0); -- ups = 0x03 downs <= x"E4"; ups <= "0000" & downs(3 downto 0); -- ups = 0x04 ups <= (ups'low to ups'high -4 => '1') & downs(3 downto 0); -- ups = 0xF4 downs <= "1001" & ups(4 to 7); -- downs = 0x94