Forum Discussion
digital 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
sure you mean 0 to 23, as 0 to 24 is 25 hours, which is longer than a normal earth day.
Questions: why is everything a variable? you should only be using signals dont use buffer - use an internal reference signal if you need to read it (or use VHDL 2008 and you can read output ports) - Altera_Forum
Honored Contributor
yes bro 0 to 23 but i used this method there many way and work all sec and min but i have problem in condition the hour counter from 0 to 99
- Altera_Forum
Honored Contributor
i want count from 0 to 23
- Altera_Forum
Honored Contributor
I agree with trickys analysis, but I'd like to add two questions.
The hours are basically the same as the seconds and minutes, why do you handle them differently in your code? You say the hour count runs from 0 up to 99, but as I read your code I can't see how H1 gets past 0. Don't you mean it runs from 00 up to 09? - Altera_Forum
Honored Contributor
yes bro when i execution on broad show me hour counter from 00 to 99 but supposed work 00 to 24.....
i change H2= 1 counter will show me counter 00 to 19 after that he rest againIF ( 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;
i change H2= 2 counter will show me counter 00 to 29 after that he rest againIF ( H2 = 1 ) THEN H2 :=0; HR_2 <=0; END IF;
i change H2= 3 counter will show me counter 00 to 39 after that he rest againIF ( H2 = 2 ) THEN H2 :=0; HR_2 <=0; END IF;
so how make counter to 00 to 24 or 00 to 12IF ( H2 = 3 ) THEN H2 :=0; HR_2 <=0; END IF; - Altera_Forum
Honored Contributor
?????????????????
- Altera_Forum
Honored Contributor
So why no one reply ????????
- Altera_Forum
Honored Contributor
take a look at the order and conditions of your if statements
hint:10!=3 - Altera_Forum
Honored Contributor
--- Quote Start --- take a look at the order and conditions of your if statements hint:10!=3 --- Quote End --- thanks for reply bro i try many time
h1 counter hour1 is count 0 1 2 3 4 5 6 7 8 9 when conditionIF ( H1 = 10) THEN H1 :=0; HR_1 <=0; H2 := H2 +1; IF ( H2 = 1 OR H1= 3 ) THEN H2 :=0; HR_2 <=0;
H2 = 1 will show us count from 0 to 1 so in broad show form 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 when i change H2 = 2 will show us count from 0 to 2 so in broad show form 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 so how make counter h2 count to 12 count? 0 1 2 3 4 5 6 7 8 9 10 11 12 or counter h2 count to 24 count? 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24IF ( H1 = 10) THEN H1 :=0; HR_1 <=0; H2 := H2 +1; - Altera_Forum
Honored Contributor
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?