Forum Discussion
Altera_Forum
Honored Contributor
9 years agodigital watch
hello every one i have design digital watch second , minute , hour after i execute the code the counter second and minute counter ok work . for 0 to 59 but hour counter form 0 to 99 ?
i have question hour about how make counter to 0 to 24 or 0 to 12 ?
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY SEQ_COUNTER IS
PORT
(
CLK_1, RST : IN STD_LOGIC;
CLK_2 : BUFFER STD_LOGIC;
SEC_1, SEC_2 : BUFFER INTEGER RANGE 0 TO 9;
MIN_1, MIN_2 : BUFFER INTEGER RANGE 0 TO 9;
HR_1, HR_2 : BUFFER INTEGER RANGE 0 TO 9;
Q : BUFFER INTEGER RANGE 0 TO 9
);
END SEQ_COUNTER;
ARCHITECTURE SEQ_COUNTER OF SEQ_COUNTER IS
BEGIN
PROCESS (CLK_1,RST)
VARIABLE S1, S2, M1, M2, H1, H2 :INTEGER RANGE 0 TO 10;
BEGIN
IF ( RST ='0' ) THEN
S1 :=0;
S2 :=0;
M1 :=0;
M2 :=0;
H1 :=0;
H2 :=0;
SEC_1 <=0;
SEC_2 <=0;
MIN_1 <=0;
MIN_2 <=0;
HR_1 <=0;
HR_2 <=0;
Q <=0;
ELSIF ( CLK_1'EVENT AND CLK_1 ='1') THEN
S1 := S1 +1;
IF ( S1 = 10) THEN
S1 :=0;
SEC_1 <=0;
S2 := S2 +1;
IF ( S2 = 6) THEN
S2 :=0;
SEC_2 <=0;
M1 := M1 +1;
IF ( M1 = 10) THEN
M1 :=0;
MIN_1 <=0;
M2 := M2 +1;
IF ( M2 = 6) THEN
M2 :=0;
MIN_2 <=0;
H1 := H1 +1;
IF ( H1 = 10) THEN
H1 :=0;
HR_1 <=0;
H2 := H2 +1;
IF ( H2 = 1 OR H1= 3 ) THEN
H2 :=0;
HR_2 <=0;
END IF;
END IF;
END IF;
END IF;
END IF;
END IF;
END IF;
SEC_1 <= S1;
SEC_2 <= S2;
MIN_1 <= M1;
MIN_2 <= M2;
HR_1 <= H1;
HR_2 <= H2;
END PROCESS;
END SEQ_COUNTER;
11 Replies
- Altera_Forum
Honored Contributor
--- Quote Start --- We all (or most of us) are doing this for fun in our own time, so sometimes we have other things to do, or are working on our own designs. It will help to get replies if you write what you have done and why instead of just dumping code and then expecting others to do your work for you. Having said that: if h1=10 it will never be 3, which you heck in the inner if statement or h1=3, so that idea doesn;t work. but why check on 10 and not 24, or use an extra if statement? --- Quote End --- ok good question if we change h1= 23 the will count over 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 in logic but in physical in board will show until 9 after 0 0 0 0 0 0 0 in board coz one 7 segment but my question is clear i understand the concept second and min but really confuse about hour coz h1=10 is right count 0 to 9 after that h2 = 2 count 0 to 2 result in board 0 1 2 and it will rest to 0 start again will be like that 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29