zmenene tlacitko na switch ked sa meni hodnota

This commit is contained in:
Priec
2026-05-08 16:30:05 +02:00
parent 5d2ce073c8
commit 99aea1652c
3 changed files with 33 additions and 48 deletions

2
.gitignore vendored
View File

@@ -31,3 +31,5 @@ Thumbs.db
Desktop.ini Desktop.ini
project_7/hx.exe project_7/hx.exe
**/x.md

View File

@@ -10,8 +10,8 @@ entity clock_logic is
CLK : in STD_LOGIC; CLK : in STD_LOGIC;
RST : in STD_LOGIC; RST : in STD_LOGIC;
CE_1HZ : in STD_LOGIC; -- Enable signal from the divider CE_1HZ : in STD_LOGIC; -- Enable signal from the divider
SW_DIN : in STD_LOGIC_VECTOR (3 downto 0); -- set data on btn_load DIGIT_SEL: in STD_LOGIC_VECTOR (3 downto 0); -- '0001'=M_UNITS, '0010'=M_TENS, atd.
BTN_LOAD : in STD_LOGIC_VECTOR (3 downto 0); BTN_INC : in STD_LOGIC; -- drzanie tlacidla pre inkrement
-- Outputs to the top module/display -- Outputs to the top module/display
S_UNITS : out STD_LOGIC_VECTOR (3 downto 0); S_UNITS : out STD_LOGIC_VECTOR (3 downto 0);
S_TENS : out STD_LOGIC_VECTOR (3 downto 0); S_TENS : out STD_LOGIC_VECTOR (3 downto 0);
@@ -45,31 +45,16 @@ architecture Behavioral of clock_logic is
-- Reset for hours (to handle the 24 reset) -- Reset for hours (to handle the 24 reset)
signal hour_reset : std_logic; signal hour_reset : std_logic;
-- Specific load enable signals that check for boundaries signal inc_m_units : std_logic;
signal load_h_tens, load_h_units : std_logic; signal inc_m_tens : std_logic;
signal load_m_tens, load_m_units : std_logic; signal inc_h_units : std_logic;
signal inc_h_tens : std_logic;
-- Internal signals for the "Safe" load triggers
signal safe_load_su, safe_load_st : std_logic;
signal safe_load_mu, safe_load_mt : std_logic;
signal safe_load_hu, safe_load_ht : std_logic;
begin begin
-- MINUTES CONSTRAINTS (Max 59) inc_m_units <= BTN_INC and DIGIT_SEL(0);
load_m_units <= BTN_LOAD(0) when (SW_DIN <= "1001") else '0'; -- 0-9 inc_m_tens <= BTN_INC and DIGIT_SEL(1);
load_m_tens <= BTN_LOAD(1) when (SW_DIN <= "0101") else '0'; -- 0-5 inc_h_units <= BTN_INC and DIGIT_SEL(2);
-- HOURS CONSTRAINTS (Max 23) inc_h_tens <= BTN_INC and DIGIT_SEL(3);
-- Rule A: Cannot load Tens > 2.
-- Rule B: If Tens is 2, cannot load Units > 3.
-- Rule C: If Units is > 3, cannot load Tens into 2.
load_h_tens <= BTN_LOAD(3) when (
SW_DIN < "0010" or
(SW_DIN = "0010" and sig_h_units <= "0011")
) else '0';
load_h_units <= BTN_LOAD(2) when (
(sig_h_tens < "0010" and SW_DIN <= "1001") or
(sig_h_tens = "0010" and SW_DIN <= "0011")
) else '0';
------------------------------------------------------- -------------------------------------------------------
-- SECONDS SECTION -- SECONDS SECTION
@@ -109,8 +94,8 @@ begin
CLK => CLK, CLK => CLK,
RST => RST, RST => RST,
CE => tc_st, CE => tc_st,
PE => load_m_units, PE => inc_m_units, -- for M_UNITS (bit 0)
DIN => SW_DIN, DIN => "0001",
TC => tc_mu, TC => tc_mu,
COUNT_OUT => sig_m_units COUNT_OUT => sig_m_units
); );
@@ -122,8 +107,8 @@ begin
CLK => CLK, CLK => CLK,
RST => RST, RST => RST,
CE => tc_mu, CE => tc_mu,
PE => load_m_tens, PE => inc_m_tens,
DIN => SW_DIN, DIN => "0010",
TC => tc_mt, TC => tc_mt,
COUNT_OUT => sig_m_tens COUNT_OUT => sig_m_tens
); );
@@ -156,8 +141,8 @@ begin
CLK => CLK, CLK => CLK,
RST => hour_reset, RST => hour_reset,
CE => tc_mt, CE => tc_mt,
PE => load_h_units, PE => inc_h_units,
DIN => SW_DIN, DIN => "0100",
TC => tc_hu, TC => tc_hu,
COUNT_OUT => sig_h_units COUNT_OUT => sig_h_units
); );
@@ -169,8 +154,8 @@ begin
CLK => CLK, CLK => CLK,
RST => hour_reset, RST => hour_reset,
CE => tc_hu, CE => tc_hu,
PE => load_h_tens, PE => inc_h_tens,
DIN => SW_DIN, DIN => "1000",
TC => open, TC => open,
COUNT_OUT => sig_h_tens COUNT_OUT => sig_h_tens
); );

View File

@@ -11,7 +11,8 @@ entity top_modul is
SW_ALARM_SET : in STD_LOGIC; -- '0' = Display Clock, '1' = Set Alarm SW_ALARM_SET : in STD_LOGIC; -- '0' = Display Clock, '1' = Set Alarm
SW_STOP_SET : in STD_LOGIC; -- '0' = Display Clock, '1' = Set Stopky SW_STOP_SET : in STD_LOGIC; -- '0' = Display Clock, '1' = Set Stopky
SW_DIN : in STD_LOGIC_VECTOR (3 downto 0); -- Value to set SW_DIN : in STD_LOGIC_VECTOR (3 downto 0); -- Value to set
BTN_LOAD : in STD_LOGIC_VECTOR (3 downto 0); -- Which digit to set -- BTN_LOAD : in STD_LOGIC_VECTOR (3 downto 0); -- Which digit to set
SW_DIGIT_SEL : in STD_LOGIC_VECTOR (3 downto 0); -- '0001'=M_UNITS, '0010'=M_TENS, '0100'=H_UNITS, '1000'=H_TENS
RST_B : in STD_LOGIC; RST_B : in STD_LOGIC;
RST_C : in STD_LOGIC; RST_C : in STD_LOGIC;
SEGMENTS : out STD_LOGIC_VECTOR (7 downto 0); SEGMENTS : out STD_LOGIC_VECTOR (7 downto 0);
@@ -59,9 +60,7 @@ architecture Behavioral of top_modul is
-- Signals to send to the display -- Signals to send to the display
signal d0, d1, d2, d3 : std_logic_vector(3 downto 0); signal d0, d1, d2, d3 : std_logic_vector(3 downto 0);
signal load_clock : std_logic_vector(3 downto 0); signal btn_inc_pulse : std_logic;
signal load_alarm : std_logic_vector(3 downto 0);
signal load_stopky : std_logic_vector(3 downto 0);
-- stopky ci behaju -- stopky ci behaju
signal stops_running : std_logic := '0'; signal stops_running : std_logic := '0';
@@ -83,17 +82,16 @@ begin
CLK_400_Hz => clk_400_Hz CLK_400_Hz => clk_400_Hz
); );
s_ce_units <= clk_1_Hz and START; s_ce_units <= clk_1_Hz and START and not SW_ALARM_SET;
load_clock <= BTN_LOAD when SW_ALARM_SET = '0' else "0000"; btn_inc_pulse <= clk_1_Hz and SW_ALARM_SET;
load_alarm <= BTN_LOAD when SW_ALARM_SET = '1' else "0000";
-- Clock Engine submodule -- Clock Engine submodule
U_CLOCK_CORE : entity work.clock_logic U_CLOCK_CORE : entity work.clock_logic
port map ( port map (
CLK => CLK, CLK => CLK,
RST => RST, RST => RST,
CE_1HZ => s_ce_units, CE_1HZ => s_ce_units,
SW_DIN => SW_DIN, DIGIT_SEL=> SW_DIN,
BTN_LOAD => load_clock, BTN_INC => btn_inc_pulse,
S_UNITS => sig_s_units, S_UNITS => sig_s_units,
S_TENS => sig_s_tens, S_TENS => sig_s_tens,
M_UNITS => sig_m_units, M_UNITS => sig_m_units,
@@ -108,8 +106,8 @@ begin
CLK => CLK, CLK => CLK,
RST => RST, RST => RST,
CE_1HZ => '0', CE_1HZ => '0',
SW_DIN => SW_DIN, DIGIT_SEL=> SW_DIN,
BTN_LOAD => load_alarm, BTN_INC => btn_inc_pulse,
S_UNITS => alrm_s_units, S_UNITS => alrm_s_units,
S_TENS => alrm_s_tens, S_TENS => alrm_s_tens,
M_UNITS => alrm_m_units, M_UNITS => alrm_m_units,
@@ -126,8 +124,8 @@ begin
CLK => CLK, CLK => CLK,
RST => stops_reset, RST => stops_reset,
CE_1HZ => stops_running, CE_1HZ => stops_running,
SW_DIN => "0000", DIGIT_SEL => "0000",
BTN_LOAD => "0000", BTN_INC => '0',
S_UNITS => stop_s_units, S_UNITS => stop_s_units,
S_TENS => stop_s_tens, S_TENS => stop_s_tens,
M_UNITS => stop_m_units, M_UNITS => stop_m_units,