117,38 → 117,29 |
|
architecture gtime_a of gtime is |
|
function to_bcd ( bin : std_logic_vector(15 downto 0) ) return std_logic_vector is |
function to_bcd ( bin : std_logic_vector(7 downto 0) ) return std_logic_vector is |
variable i : integer:=0; |
variable mybcd : std_logic_vector(19 downto 0) := (others => '0'); |
variable bint : std_logic_vector(15 downto 0) := bin; |
variable mybcd : std_logic_vector(11 downto 0) := (others => '0'); |
variable bint : std_logic_vector(7 downto 0) := bin; |
begin |
for i in 0 to 15 loop -- repeating 16 times. |
mybcd(19 downto 1) := mybcd(18 downto 0); --shifting the bits. |
mybcd(0) := bint(15); |
bint(15 downto 1) := bint(14 downto 0); |
for i in 0 to 7 loop -- repeating 8 times. |
mybcd(11 downto 1) := mybcd(10 downto 0); --shifting the bits. |
mybcd(0) := bint(7); |
bint(7 downto 1) := bint(6 downto 0); |
bint(0) :='0'; |
|
|
if(i < 15 and mybcd(3 downto 0) > "0100") then --add 3 if BCD digit is greater than 4. |
if(i < 7 and mybcd(3 downto 0) > "0100") then --add 3 if BCD digit is greater than 4. |
mybcd(3 downto 0) := std_logic_vector(unsigned(mybcd(3 downto 0)) + 3); |
end if; |
|
if(i < 15 and mybcd(7 downto 4) > "0100") then --add 3 if BCD digit is greater than 4. |
if(i < 7 and mybcd(7 downto 4) > "0100") then --add 3 if BCD digit is greater than 4. |
mybcd(7 downto 4) := std_logic_vector(unsigned(mybcd(7 downto 4)) + 3); |
end if; |
|
if(i < 15 and mybcd(11 downto 8) > "0100") then --add 3 if BCD digit is greater than 4. |
if(i < 7 and mybcd(11 downto 8) > "0100") then --add 3 if BCD digit is greater than 4. |
mybcd(11 downto 8) := std_logic_vector(unsigned(mybcd(11 downto 8)) + 3); |
end if; |
|
if(i < 15 and mybcd(15 downto 12) > "0100") then --add 3 if BCD digit is greater than 4. |
mybcd(15 downto 12) := std_logic_vector(unsigned(mybcd(15 downto 12)) + 3); |
end if; |
|
if(i < 15 and mybcd(19 downto 16) > "0100") then --add 3 if BCD digit is greater than 4. |
mybcd(19 downto 16) := std_logic_vector(unsigned(mybcd(19 downto 16)) + 3); |
end if; |
|
end loop; |
|
return mybcd; |
158,17 → 149,16 |
-- LED Demo Signals |
-- ---------------- |
|
signal Counter: unsigned(13 downto 0) := "00000000000000"; -- Main Counter 1 Hz, max. 9.999 kHz (binary) |
signal CounterMaxcount: unsigned(14 downto 0) := "000000000000000"; -- Main Counter 10 kHz, max. 327.67 MHz (binary) |
signal Bar: unsigned(7 downto 0) := X"00"; -- Register for Bar output (binary) |
signal Counter: unsigned(15 downto 0) := X"0000"; -- Main Counter (binary) |
signal CounterMaxcount: unsigned(15 downto 0) := X"0000"; -- Main Counter (binary) |
signal Bar: unsigned(7 downto 0) := X"00"; -- Counter for Bar output (binary) |
|
signal FastBlink: std_logic; -- Signal mask for half intensity LED output (several kHz) |
|
-- LED Display |
-- ----------- |
|
signal Number: std_logic_vector(35 downto 0) := X"000000000"; -- LED Display Input |
signal Freq: std_logic_vector(31 downto 0) := X"00000000"; -- Measured Frequency |
signal HalfFreq: std_logic_vector(31 downto 0); |
signal Number: std_logic_vector(31 downto 0) := X"00000000"; -- LED Display Input |
signal MuxCounter: unsigned(31 downto 0) := (others => '0'); -- LED Multiplex - Multiplex Clock Divider |
signal Enable: std_logic; |
signal Digits: std_logic_vector(7 downto 0) := X"01"; -- LED Multiplex - Digit Counter - LED Digit Output |
183,7 → 173,10 |
|
begin |
|
-- Counter |
-- Basic LED Blinking Test |
-- ======================= |
|
-- LED Bar Counter |
process (LO_CLOCK) |
begin |
|
198,8 → 191,8 |
end if; |
end if; |
if (State = 1) then |
Freq(15 downto 0) <= std_logic_vector("00"&Counter); |
Freq(31 downto 16) <= std_logic_vector("0"&CounterMaxcount); |
Number(15 downto 0) <= std_logic_vector(Counter(15 downto 0)); |
Number(31 downto 16) <= std_logic_vector(CounterMaxcount(15 downto 0)); |
end if; |
if (State = 2) then |
CounterMaxcount <= (others => '0'); |
210,15 → 203,13 |
end process; |
|
|
-- Sampling 1PPS signal |
process (LO_CLOCK) |
begin |
if rising_edge(LO_CLOCK) then |
Decko <= B(22); |
Decko <= DIPSW(0); |
end if; |
end process; |
|
-- Automata for controling the Counter |
process (LO_CLOCK) |
begin |
if rising_edge(LO_CLOCK) then |
232,21 → 223,12 |
end if; |
end process; |
|
-- Coding to BCD for LED Display |
|
|
LED <= std_logic_vector(Bar); -- LED Bar Connected to Counter |
|
-- HalfFreq(14 downto 0) <= Freq(15 downto 1); |
-- HalfFreq(15) <= '0'; |
-- HalfFreq(30 downto 16) <= Freq(31 downto 17); |
-- HalfFreq(31) <= '0'; |
-- Number(15 downto 0) <= to_bcd(HalfFreq(15 downto 0))(15 downto 0); |
-- Number(35 downto 16) <= to_bcd(HalfFreq(31 downto 16))(19 downto 0); |
Number(15 downto 0) <= Freq(15 downto 0); |
Number(31 downto 16) <= Freq(31 downto 16); |
-- FastBlink <= Counter(13) and Counter(14) and Counter(15) and Counter(16); -- 1/16 intensity |
|
LED(7) <= Decko; -- Disply 1PPS pulse on LEDbar |
LED(6 downto 4) <= (others => '0'); |
LED(3 downto 0) <= Number(35 downto 32); -- Disply 100-th of MHz on LEDbar |
|
-- LED Display (multiplexed) |
-- ========================= |
|
334,7 → 316,7 |
DIFbuffer1 : IBUFGDS |
generic map ( |
DIFF_TERM => FALSE, -- Differential Termination |
IBUF_DELAY_VALUE => "16", -- Specify the amount of added input delay for buffer, |
IBUF_DELAY_VALUE => "0", -- Specify the amount of added input delay for buffer, |
-- "0"-"16" |
IOSTANDARD => "DEFAULT") |
port map ( |
343,14 → 325,6 |
O => LO_CLOCK -- Buffer output |
); |
|
OBUFDS_inst : OBUFDS |
generic map ( |
IOSTANDARD => "DEFAULT") |
port map ( |
O => SD2AP, -- Diff_p output (connect directly to top-level port) |
OB => SD2AN, -- Diff_n output (connect directly to top-level port) |
I => LO_CLOCK -- Buffer input |
); |
|
-- Output Signal on SATA Connector |
-- SD1AP <= 'Z'; |
359,8 → 333,8 |
SD1BN <= 'Z'; |
|
-- Input Here via SATA Cable |
-- SD2AP <= 'Z'; |
-- SD2AN <= 'Z'; |
SD2AP <= 'Z'; |
SD2AN <= 'Z'; |
SD2BP <= 'Z'; |
SD2BN <= 'Z'; |
|