[Menu]>[Guide to use the PIC]>[Circuits Gallery]>[Digital Clock]
I found the following improvement point after making an actual circuit and confirming in the operation.
A clock was slow.
There was a mistake in the processing which makes time of 1 second as a result of the investigation. 1 second is made by counting 20 milliseconds 50 times. At first, if being equal to or less than 50, it was doing the processing which updates a counter. In this case, it counts in the extra of 1 count because it is increasing a count after checking. 1 correct second could be made by correcting checking data to 49.
It wasn't possible to have done time setting in the rotary encoder.
The cause was to do the influence being of the capacitor to have put between the encoder circuit and the grounding. 0.1uF was used for the capacitor. When a rotary encoder was turned and A terminal or B terminal was connected with +5V, the electric current flowed through the capacitor rapidly and +5V voltage went down. Therefore, the power of PIC became OFF and was initialized.
A capacitor was put to prevent from the chattering of the rotary encoder. However, because this clock is preventing a chattering by the software, the capacitors aren't necessary. After removing capacitors, PIC became never initialized.
In spite of this change, it wasn't possible to do time setting by the encoder. This cause was to be because the resistance value(10K-ohm) to put between the encoder and the grounding was big. The voltage of the terminal of PIC didn't become an L level in the condition of OFF in the encoder. It became possible to do normal time setting by changing a resistance value into 1K-ohm.
The time setting of units of hour in PM1x was abnormal.
In case of PM1x, only three kinds(0,1 and 3) are made to be able to be set to units of hour. In the previous processing, it judged in the condition which is equal to 2 as the upper limit judgment. Therefore, when units of hour was 9, it was increasing a count simply because it was not 2. As a result, it referred to the data which exceeded 7 segment tables and an abnormally display was done.
It changed the processing into "equal to or more than 2" judgment and it became able to be normally set.
The count-down processing with PM1x was similar too. It wasn't possible to do normal time setting because the units of hour was only the judgment of "0". The normal setting became possible by putting "equal to or more than 3" judgment.
This clock can set to AM1x or PM1x after setting the units of hour to 9(The figure which is not 0, 1, 2). So, the setting of AM19 or PM17 .. has become possible. It isn't checking about this.
The blink interval of time setting was changed into 200 milliseconds.
When changed into the time setting mode, the setting position had become units of hour.
The cause was to be because it didn't set the last look data of RB7. By pressing RB7 continuously for 2 seconds, it becomes a time setting mode. However, when the last look of RB7 was 0, it recognized that RB7 changed and it shifted one setting position. The position gets to shift when RB7 is pressed next if setting the last look of RB7 to 1 when becoming a time setting mode.
When the time setting mode ends, the error occurs to the setting in 0 seconds.
It is delayed about 1 second in a day.
The cause was to do the mistake being of the logic of CPLD which makes 50Hz from 10MHz. The 1/200000 counter is composed of 1/100000 counter and 1/2 counter. I judged 1/100000 count at 100000. The right value is 99999. Therefore, it became the counter of 1/200002. In case of the wrong logic, to be delayed in 1 second is caused by 100000 seconds. Because a day is 86400 seconds, it is delayed 0.86 seconds in a day.
The output of the counter of CPLD becomes 49.9995 Hz in the calculation. According to the detailed measurement, there is possibility to have found a mistake.