Hello! I really need help fast!..thank you!
I have to implement a clock on a Basys fpga board and then i have to set the clock using the keyboard through HYperterminal using the serial port!
I have the the code for implementing the clock on the board but i don't know how to modify it in order to set the clock from the hyperteminal and not from the board!
this is the code that needs to be modifyed:
entity ElectronicWatch is
Port ( mclk : in STD_LOGIC;
btn0, btn1, btn2: in STD_LOGIC;
anodes : out STD_LOGIC_VECTOR (3 downto 0);
cathodes : out STD_LOGIC_VECTOR (6 downto 0);
led0: out STD_LOGIC);
end ElectronicWatch;
architecture Behavioral of ElectronicWatch is
---------------------------------------------
-- Components Used
---------------------------------------------
component SvnSgmDisplay is
Port ( num16 : in STD_LOGIC_VECTOR (15 downto 0);
specials: in STD_LOGIC_VECTOR (4 downto 0);
clk : in STD_LOGIC;
anodes : out STD_LOGIC_VECTOR (3 downto 0);
cathodes : out STD_LOGIC_VECTOR (6 downto 0));
end component;
component DFF_F is
Port ( D : in STD_LOGIC;
clk : in STD_LOGIC;
Y : out STD_LOGIC);
end component;
component DFF_R is
Port ( D : in STD_LOGIC;
clk : in STD_LOGIC;
Y : out STD_LOGIC);
end component;
---------------------------------------------
-- Signals Used
---------------------------------------------
signal sCounter0 : STD_LOGIC_VECTOR(3 downto 0);
signal sCounter1 : STD_LOGIC_VECTOR(3 downto 0);
signal mCounter0 : STD_LOGIC_VECTOR(3 downto 0);
signal mCounter1 : STD_LOGIC_VECTOR(3 downto 0);
signal hCounter0 : STD_LOGIC_VECTOR(3 downto 0);
signal hCounter1 : STD_LOGIC_VECTOR(3 downto 0);
signal displNumber: STD_LOGIC_VECTOR(15 downto 0);
signal clk_div_counter: STD_LOGIC_VECTOR(25 downto 0);
signal clk_div: STD_LOGIC; -- seconds flag
signal m_clk_div: STD_LOGIC; -- minutes flag
signal auxd: STD_LOGIC; -- helps the display
signal fsig: STD_LOGIC; -- signal between flipflops
signal fsig1: STD_LOGIC; -- signal between flipflops
signal fsig2: STD_LOGIC; -- signal between flipflops
signal sync_btn0: STD_LOGIC; -- synchronous button 0
signal sync_btn1: STD_LOGIC; -- synchronous button 1
signal sync_btn2: STD_LOGIC; -- synchronous button 2
signal setmode: STD_LOGIC; -- active when we are in set mode
signal specials: STD_LOGIC_VECTOR(4 downto 0); -- specifies the current mode for changing the display
signal lpCounter: STD_LOGIC_VECTOR(26 downto 0); -- counts the second needed for the long press to be activated
signal bcntr: STD_LOGIC_VECTOR(1 downto 0); -- changes the blinking element
signal newh1: STD_LOGIC_VECTOR(3 downto 0);
signal newh0: STD_LOGIC_VECTOR(3 downto 0);
signal newm1: STD_LOGIC_VECTOR(3 downto 0);
signal newm0: STD_LOGIC_VECTOR(3 downto 0);
signal news1: STD_LOGIC_VECTOR(3 downto 0);
signal news0: STD_LOGIC_VECTOR(3 downto 0);
-- details for specials signal --
-- specials(0) = '1' => hour < 10
-- specials(1) = '1' => display the seconds (do not show the first two digits)
-- specials(2) = '0' => blink/set hours
-- specials(3) = '1' => blink/set minutes
-- specials(4) = '1' => blink/set seconds
---------------------------------------------
-- Module implementation
---------------------------------------------
begin
SevenSegmentDisplay: SvnSgmDisplay port map(displNumber, specials, mclk,anodes, cathodes);
RisingEdge: DFF_R port map(fsig, mclk, sync_btn0);
FallingEdge: DFF_F port map (btn0, mclk, fsig);
RisingEdge1: DFF_R port map(fsig1, mclk, sync_btn1);
FallingEdge1: DFF_F port map (btn1, mclk, fsig1);
RisingEdge2: DFF_R port map(fsig2, mclk, sync_btn2);
FallingEdge2: DFF_F port map (btn2, mclk, fsig2);
-- Count the seconds by using a clock divider
-- for the 50Mhz internal clock of Spartan 3
process (mclk, setmode, news0, news1)
begin
if setmode = '1' then
sCounter0 <= news0;
sCounter1 <= news1;
elsif mclk'event and mclk = '1' then
--if we had 50M oscillations
if clk_div_counter = "10111110101111000010000000" then
--if clk_div_counter = "1001100010010100" then -- ca sa mearga mai repede
--reset the clock divider
clk_div_counter <= "00000000000000000000000000";
--signal the change of seconds
clk_div <= not clk_div;
--adjust the seconds
--if first digit is 9
if sCounter0 = "1001" then
sCounter0 <= "0000";
--if second digit is 5
if sCounter1 = "0101" then
sCounter1 <= "0000";
else
sCounter1 <= sCounter1 + 1;
end if;
else
sCounter0 <= sCounter0 + 1;
end if;
else
clk_div_counter <= clk_div_counter + 1;
end if;
end if;
end process;
-- Count the minutes
process(clk_div, setmode, newm0, newm1)
begin
-- if we are in setmode then we stop counting and display the new values
if setmode = '1' then
mCounter1 <= newm1;
mCounter0 <= newm0;
-- if we have an even second
elsif clk_div'event and clk_div = '0' then
-- if the seconds configuration is 59
if sCounter1 = "0101" and sCounter0 = "1001" then
--signal the change of minutes
m_clk_div <= not m_clk_div;
--if first digit is 9
if mCounter0 = "1001" then
mCounter0 <= "0000";
--if second digit is 5
if mCounter1 = "0101" then
mCounter1 <= "0000";
else
mCounter1 <= mCounter1 + 1;
end if;
else
mCounter0 <= mCounter0 + 1;
end if;
end if;
end if;
end process;
-- Count the hours
process(m_clk_div, setmode, newh0, newh1)
begin
-- if we are in setmode then we stop counting and display the new values
if setmode = '1' then
hCounter1 <= newh1;
hCounter0 <= newh0;
-- if we have an even minute
elsif m_clk_div'event and m_clk_div = '0' then
-- if the minutes configuration is 59
if mCounter1 = "0101" and mCounter0 = "1001" then
--if first digit is 9
if hCounter0 = "1001" then
hCounter0 <= "0000";
hCounter1 <= hCounter1 + 1;
--elsif the configuration is 23
elsif hCounter0 = "0011" and hCounter1 = "0010" then
hCounter0 <= "0000";
hCounter1 <= "0000";
--else just increment the first digit
else
hCounter0 <= hCounter0 + 1;
end if;
end if;
end if;
end process;
-- decide on what to display: minutes+hours / seconds when not in set mode
process(setmode, sync_btn0, bcntr)
begin
-- what should we display when we are in set mode
if setmode = '1' then
-- if the counter has the hour/minutes values
if bcntr = "00" or bcntr = "01" then
auxd <= '0';
-- else display the seconds
else
auxd <= '1';
end if;
elsif sync_btn0'event and sync_btn0 = '0' then
-- if we didn't enter the set mode
if (lpCounter /= "010111110101111000010000001" and setmode = '0') then
auxd <= not auxd;
end if;
end if;
end process;
-- solve the long push button
process(mclk)
begin
-- we count each clock cycle
if mclk'event and mclk = '1' then
-- if the button is pushed
if sync_btn0 = '1' then
-- increase the counter if it is smaller than 1 second
if lpCounter < "010111110101111000010000000" then
lpCounter <= lpCounter + 1;
-- signal the long press if we reached 1 second
elsif lpCounter = "010111110101111000010000000" then
-- assign to lpCounter a greater value so it doesn't change its value again until we release the button
lpCounter <= "010111110101111000010000001";
-- signal the long press
setmode <= not setmode;
end if;
-- if the button is released reset the counter
elsif sync_btn0 = '0' then
lpCounter <= "000000000000000000000000000";
end if;
end if;
end process;
-- change the item to set: hours/minutes/seconds
process(setmode, sync_btn1, auxd)
begin
-- if we are not in the set mode we shouldn't count
if setmode = '0' then
-- keep it ready for the next setting
if auxd = '0' then
bcntr <= "00";
else
bcntr <= "10";
end if;
-- else if we push B1 count
elsif sync_btn1'event and sync_btn1 = '1' then
if bcntr = "10" then
bcntr <= "00";
else
bcntr <= bcntr + 1;
end if;
end if;
end process;
-- increase the hours/minutes/seconds
process(setmode, sync_btn2, hCounter1, hCounter0, mCounter1, mCounter0, sCounter1, sCounter0)
begin
if setmode = '0' then
newh1 <= hCounter1;
newh0 <= hCounter0;
newm1 <= mCounter1;
newm0 <= mCounter0;
news1 <= sCounter1;
news0 <= sCounter0;
elsif sync_btn2'event and sync_btn2 = '1' then
if bcntr = "00" then
-- increase hours
-- if second digit is nine
if newh0 = "1001" then
newh0 <= "0000";
newh1 <= newh1 + 1;
--elsif the configuration is 23
elsif newh0 = "0011" and newh1 = "0010" then
newh0 <= "0000";
newh1 <= "0000";
--else just increment the first digit
else
newh0 <= newh0 + 1;
end if;
elsif bcntr = "01" then
-- increase minutes
if newm0 = "1001" then
newm0 <= "0000";
--if second digit is 5
if newm1 = "0101" then
newm1 <= "0000";
else
newm1 <= newm1 + 1;
end if;
else
newm0 <= newm0 + 1;
end if;
elsif bcntr = "10" then
-- reset seconds
news1 <= "0000";
news0 <= "0000";
end if;
end if;
end process;
-- change the specials signal accordingly
specials(2) <= '1' when (bcntr = "00" and setmode = '1') else '0';
specials(3) <= '1' when (bcntr = "01" and setmode = '1') else '0';
specials(4) <= '1' when (bcntr = "10" and setmode = '1') else '0';
-- display the seconds or the minutes/hours when the button is pushed
displNumber <= hCounter1 & hCounter0 & mCounter1 & mCounter0 when auxd = '0' else
"00000000" & sCounter1 & sCounter0 when auxd = '1';
led0 <= setmode;
-- We will not display the first digit if the hour is < 10
process(mclk, hCounter1)
begin
if mclk'event and mclk = '1' then
-- if the first digit is zero do not display the first digit
if hCounter1 = "0000" then
specials(0) <= '1';
else
specials(0) <= '0';
end if;
end if;
end process;
-- we will not display the first two digits if we are displaying the seconds
process(mclk, auxd)
begin
if mclk'event and mclk = '1' then
if auxd = '1' then
specials(1) <= '1';
else
specials(1) <= '0';
end if;
end if;
end process;
end Behavioral;
I have to implement a clock on a Basys fpga board and then i have to set the clock using the keyboard through HYperterminal using the serial port!
I have the the code for implementing the clock on the board but i don't know how to modify it in order to set the clock from the hyperteminal and not from the board!
this is the code that needs to be modifyed:
entity ElectronicWatch is
Port ( mclk : in STD_LOGIC;
btn0, btn1, btn2: in STD_LOGIC;
anodes : out STD_LOGIC_VECTOR (3 downto 0);
cathodes : out STD_LOGIC_VECTOR (6 downto 0);
led0: out STD_LOGIC);
end ElectronicWatch;
architecture Behavioral of ElectronicWatch is
---------------------------------------------
-- Components Used
---------------------------------------------
component SvnSgmDisplay is
Port ( num16 : in STD_LOGIC_VECTOR (15 downto 0);
specials: in STD_LOGIC_VECTOR (4 downto 0);
clk : in STD_LOGIC;
anodes : out STD_LOGIC_VECTOR (3 downto 0);
cathodes : out STD_LOGIC_VECTOR (6 downto 0));
end component;
component DFF_F is
Port ( D : in STD_LOGIC;
clk : in STD_LOGIC;
Y : out STD_LOGIC);
end component;
component DFF_R is
Port ( D : in STD_LOGIC;
clk : in STD_LOGIC;
Y : out STD_LOGIC);
end component;
---------------------------------------------
-- Signals Used
---------------------------------------------
signal sCounter0 : STD_LOGIC_VECTOR(3 downto 0);
signal sCounter1 : STD_LOGIC_VECTOR(3 downto 0);
signal mCounter0 : STD_LOGIC_VECTOR(3 downto 0);
signal mCounter1 : STD_LOGIC_VECTOR(3 downto 0);
signal hCounter0 : STD_LOGIC_VECTOR(3 downto 0);
signal hCounter1 : STD_LOGIC_VECTOR(3 downto 0);
signal displNumber: STD_LOGIC_VECTOR(15 downto 0);
signal clk_div_counter: STD_LOGIC_VECTOR(25 downto 0);
signal clk_div: STD_LOGIC; -- seconds flag
signal m_clk_div: STD_LOGIC; -- minutes flag
signal auxd: STD_LOGIC; -- helps the display
signal fsig: STD_LOGIC; -- signal between flipflops
signal fsig1: STD_LOGIC; -- signal between flipflops
signal fsig2: STD_LOGIC; -- signal between flipflops
signal sync_btn0: STD_LOGIC; -- synchronous button 0
signal sync_btn1: STD_LOGIC; -- synchronous button 1
signal sync_btn2: STD_LOGIC; -- synchronous button 2
signal setmode: STD_LOGIC; -- active when we are in set mode
signal specials: STD_LOGIC_VECTOR(4 downto 0); -- specifies the current mode for changing the display
signal lpCounter: STD_LOGIC_VECTOR(26 downto 0); -- counts the second needed for the long press to be activated
signal bcntr: STD_LOGIC_VECTOR(1 downto 0); -- changes the blinking element
signal newh1: STD_LOGIC_VECTOR(3 downto 0);
signal newh0: STD_LOGIC_VECTOR(3 downto 0);
signal newm1: STD_LOGIC_VECTOR(3 downto 0);
signal newm0: STD_LOGIC_VECTOR(3 downto 0);
signal news1: STD_LOGIC_VECTOR(3 downto 0);
signal news0: STD_LOGIC_VECTOR(3 downto 0);
-- details for specials signal --
-- specials(0) = '1' => hour < 10
-- specials(1) = '1' => display the seconds (do not show the first two digits)
-- specials(2) = '0' => blink/set hours
-- specials(3) = '1' => blink/set minutes
-- specials(4) = '1' => blink/set seconds
---------------------------------------------
-- Module implementation
---------------------------------------------
begin
SevenSegmentDisplay: SvnSgmDisplay port map(displNumber, specials, mclk,anodes, cathodes);
RisingEdge: DFF_R port map(fsig, mclk, sync_btn0);
FallingEdge: DFF_F port map (btn0, mclk, fsig);
RisingEdge1: DFF_R port map(fsig1, mclk, sync_btn1);
FallingEdge1: DFF_F port map (btn1, mclk, fsig1);
RisingEdge2: DFF_R port map(fsig2, mclk, sync_btn2);
FallingEdge2: DFF_F port map (btn2, mclk, fsig2);
-- Count the seconds by using a clock divider
-- for the 50Mhz internal clock of Spartan 3
process (mclk, setmode, news0, news1)
begin
if setmode = '1' then
sCounter0 <= news0;
sCounter1 <= news1;
elsif mclk'event and mclk = '1' then
--if we had 50M oscillations
if clk_div_counter = "10111110101111000010000000" then
--if clk_div_counter = "1001100010010100" then -- ca sa mearga mai repede
--reset the clock divider
clk_div_counter <= "00000000000000000000000000";
--signal the change of seconds
clk_div <= not clk_div;
--adjust the seconds
--if first digit is 9
if sCounter0 = "1001" then
sCounter0 <= "0000";
--if second digit is 5
if sCounter1 = "0101" then
sCounter1 <= "0000";
else
sCounter1 <= sCounter1 + 1;
end if;
else
sCounter0 <= sCounter0 + 1;
end if;
else
clk_div_counter <= clk_div_counter + 1;
end if;
end if;
end process;
-- Count the minutes
process(clk_div, setmode, newm0, newm1)
begin
-- if we are in setmode then we stop counting and display the new values
if setmode = '1' then
mCounter1 <= newm1;
mCounter0 <= newm0;
-- if we have an even second
elsif clk_div'event and clk_div = '0' then
-- if the seconds configuration is 59
if sCounter1 = "0101" and sCounter0 = "1001" then
--signal the change of minutes
m_clk_div <= not m_clk_div;
--if first digit is 9
if mCounter0 = "1001" then
mCounter0 <= "0000";
--if second digit is 5
if mCounter1 = "0101" then
mCounter1 <= "0000";
else
mCounter1 <= mCounter1 + 1;
end if;
else
mCounter0 <= mCounter0 + 1;
end if;
end if;
end if;
end process;
-- Count the hours
process(m_clk_div, setmode, newh0, newh1)
begin
-- if we are in setmode then we stop counting and display the new values
if setmode = '1' then
hCounter1 <= newh1;
hCounter0 <= newh0;
-- if we have an even minute
elsif m_clk_div'event and m_clk_div = '0' then
-- if the minutes configuration is 59
if mCounter1 = "0101" and mCounter0 = "1001" then
--if first digit is 9
if hCounter0 = "1001" then
hCounter0 <= "0000";
hCounter1 <= hCounter1 + 1;
--elsif the configuration is 23
elsif hCounter0 = "0011" and hCounter1 = "0010" then
hCounter0 <= "0000";
hCounter1 <= "0000";
--else just increment the first digit
else
hCounter0 <= hCounter0 + 1;
end if;
end if;
end if;
end process;
-- decide on what to display: minutes+hours / seconds when not in set mode
process(setmode, sync_btn0, bcntr)
begin
-- what should we display when we are in set mode
if setmode = '1' then
-- if the counter has the hour/minutes values
if bcntr = "00" or bcntr = "01" then
auxd <= '0';
-- else display the seconds
else
auxd <= '1';
end if;
elsif sync_btn0'event and sync_btn0 = '0' then
-- if we didn't enter the set mode
if (lpCounter /= "010111110101111000010000001" and setmode = '0') then
auxd <= not auxd;
end if;
end if;
end process;
-- solve the long push button
process(mclk)
begin
-- we count each clock cycle
if mclk'event and mclk = '1' then
-- if the button is pushed
if sync_btn0 = '1' then
-- increase the counter if it is smaller than 1 second
if lpCounter < "010111110101111000010000000" then
lpCounter <= lpCounter + 1;
-- signal the long press if we reached 1 second
elsif lpCounter = "010111110101111000010000000" then
-- assign to lpCounter a greater value so it doesn't change its value again until we release the button
lpCounter <= "010111110101111000010000001";
-- signal the long press
setmode <= not setmode;
end if;
-- if the button is released reset the counter
elsif sync_btn0 = '0' then
lpCounter <= "000000000000000000000000000";
end if;
end if;
end process;
-- change the item to set: hours/minutes/seconds
process(setmode, sync_btn1, auxd)
begin
-- if we are not in the set mode we shouldn't count
if setmode = '0' then
-- keep it ready for the next setting
if auxd = '0' then
bcntr <= "00";
else
bcntr <= "10";
end if;
-- else if we push B1 count
elsif sync_btn1'event and sync_btn1 = '1' then
if bcntr = "10" then
bcntr <= "00";
else
bcntr <= bcntr + 1;
end if;
end if;
end process;
-- increase the hours/minutes/seconds
process(setmode, sync_btn2, hCounter1, hCounter0, mCounter1, mCounter0, sCounter1, sCounter0)
begin
if setmode = '0' then
newh1 <= hCounter1;
newh0 <= hCounter0;
newm1 <= mCounter1;
newm0 <= mCounter0;
news1 <= sCounter1;
news0 <= sCounter0;
elsif sync_btn2'event and sync_btn2 = '1' then
if bcntr = "00" then
-- increase hours
-- if second digit is nine
if newh0 = "1001" then
newh0 <= "0000";
newh1 <= newh1 + 1;
--elsif the configuration is 23
elsif newh0 = "0011" and newh1 = "0010" then
newh0 <= "0000";
newh1 <= "0000";
--else just increment the first digit
else
newh0 <= newh0 + 1;
end if;
elsif bcntr = "01" then
-- increase minutes
if newm0 = "1001" then
newm0 <= "0000";
--if second digit is 5
if newm1 = "0101" then
newm1 <= "0000";
else
newm1 <= newm1 + 1;
end if;
else
newm0 <= newm0 + 1;
end if;
elsif bcntr = "10" then
-- reset seconds
news1 <= "0000";
news0 <= "0000";
end if;
end if;
end process;
-- change the specials signal accordingly
specials(2) <= '1' when (bcntr = "00" and setmode = '1') else '0';
specials(3) <= '1' when (bcntr = "01" and setmode = '1') else '0';
specials(4) <= '1' when (bcntr = "10" and setmode = '1') else '0';
-- display the seconds or the minutes/hours when the button is pushed
displNumber <= hCounter1 & hCounter0 & mCounter1 & mCounter0 when auxd = '0' else
"00000000" & sCounter1 & sCounter0 when auxd = '1';
led0 <= setmode;
-- We will not display the first digit if the hour is < 10
process(mclk, hCounter1)
begin
if mclk'event and mclk = '1' then
-- if the first digit is zero do not display the first digit
if hCounter1 = "0000" then
specials(0) <= '1';
else
specials(0) <= '0';
end if;
end if;
end process;
-- we will not display the first two digits if we are displaying the seconds
process(mclk, auxd)
begin
if mclk'event and mclk = '1' then
if auxd = '1' then
specials(1) <= '1';
else
specials(1) <= '0';
end if;
end if;
end process;
end Behavioral;