Is there a register that counts the number of clock cycles that occur?
I am working on a basketball scoreboard controlled by an infrared remote. There is a main loop that checks for input pulses from an infrared sensor, and then outputs the necessary displays to 7-segment LEDs. This seems to work okay. However, I am having trouble adding a way to tell how much time has passed, in order to display a clock that counts down. The main loop uses several PULSIN commands, which do not always last the same amount of time. This means that it is difficult to predict how long each execution of the main loop lasts for time counting purposes.
I'd hate to have to go to an assembly level board for this (or add a second board). Is there an easy solution?
I'd hate to have to go to an assembly level board for this (or add a second board). Is there an easy solution?
Comments
1. The easiest to connect to would be a GPS with 1 pps output; sadly, it would cost you tens of dollars. Check to make certain you would not have to program it to supply the output.
2. There are Real Time Clock chips with square wave outputs (the DS1302 is *not* one of them); less than ten dollars for the chip and the crystal. You would have to program it to supply a 1 Hz output.
3. Depending on your power supply, you might be able to obtain a 60 Hz reference. Depending on how fast your main loop runs, you might be able to divide it in software to obtain a 1 Hz reference. Alternately you could divide it externally by 6 or 10 with a single 749x to obtain something you can work with.
4. Do not succumb to the temptation of using a 555 or similar analog timer because you cannot obtain consistent results over temperature and aging. In My Opinion and Experience.