Peter Moreton wrote... >Hi, I'm playing about with a PIC18F452 and trying to design a very >simple clock circuit, to show both UTC and Sidereal (astronomical) time >on a 2x16 LCD display. Before I start writing code using the C18 >compiler, I'd like to ask for opinions for crystal frequencies that >'make sense' in a clock application. There's a technique you can use to generate your clock ticks that will relieve you of any need to worry about what crystal frequency to use and will also allow you to correct for error, and even temperature shift, in the crystal frequency. Normally we think of counters as hardware gadgets which increment by one on each input pulse; but there's no reason why you can't have a software counter (running on a Timer 2 interrupt, for example) which increments by a fraction each time it is triggered. The required increment value is calculated from the crystal frequency, the Timer 2 period setting, the length of your software counter, and how often you want your ticks (that is, when the counter rolls over) to occur. By making the counter long enough (I've used both 24-bit and 32-bit counters), you can put enough precision into the increment value that it can be used to correct for the crystal frequency tolerance; and if you can measure the ambient temperature, you can also vary the increment value compensate for the crystal's temperature shift as well (either with a lookup table, or a polynomial). I've had good results using this technique both for timing and as a basis for generating digitally tuned sine waves by DDS ("Direct Digital Synthesis"); in the latter case, the counter is used as a phase accumulator and its MSBs are used to index into a table of sine values which are fed to a DAC to generate the analog output. The sine wave frequency is tuned simply by changing the increment value. If you're looking for clock accuracy any better than a second or two a day, this may be the best way to go. Hope this helps... Dave D. -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu