On Fri, 13 Feb 1998 04:56:23 +1000 "Paul B. Webster VK2BZC" writes: >Fascinating concept. > > This may have been touched on; but was it proposed that the PIC >perform the gating of the count as well? I suppose it could, either >using a PIC with two timers, or software loop counters. > > If so, then it requires two outputs and two gates, say NAND gates, >the >first for the gating and the second for the "fiddle" count. No >problems >here. Let me reiterate: *No* external hardware. The signal to be counted is simply applied to the TMR0/RA4 pin. The internal selector gate, controlled by the OPTION register, which selects between external and internal clock is used to gate the signal to be counted. The pin is not used in I/O mode, so it works on 16C5X PICs which can only use that pin as a timer input. > Gets hairy if you try to extend the counter to a second (third) byte This is simple. While counting, periodically read the TMR0 register (at least often enough so it can't advance by more than 255 counts since the last read) and subtract the last value read. Add the difference (the number of counts received) to a multi-byte accumulator in RAM, which can be of any size needed. I used a 3-byte (24-bit) accumulator. Combining that with the 8-bit prescaler result, the total count is 32 bits, enough to count a 50 MHz signal for 85 seconds. The gate time was controlled by enclosing the accumulate TMR0 / scan LED processes in a software loop with exactly controlled execution time. On a PIC with 2 timers, the other timer could be used to generate periodic interrupts that add TMR0 to the accumulator register and finally close the gate. The last ISR could be (relatively) rather time-consuming since the process to resolve the prescaler value would need to be carried out. The second timer would need to be the only source of interrupt so that it is always serviced immediately. Within these limitations, a fairly good approximation of counting in the background could be done. > > Obviously we'd use an LCD for the display. I used an 8-digit LED array, of the type once used for calculators. But, it seems to be just about impossible to find these anymore, so an LCD could be a better choice. During the loop that holds the gate open and adds TMR0 counts to the accumulator there is plenty of time to scan the LEDs as well. > > Accuracy is dependent on the crystal; I suspect you'd be best to use >a >separate assembly but it may work satisfactorily and be SUPER simple >with a regulated supply and trimmer on the PIC crystal. It works OK using the PIC oscillator, certainly if the absolute frequency isn't important (i.e. you're looking for changes or drift in frequency). The crystal needs to be a little better than the typical 100ppm grade to be sure that it can be trimmed to the exact required frequency. An accurate oscillator can be used to clock the PIC for greater accuracy. _____________________________________________________________________ You don't need to buy Internet access to use free Internet e-mail. Get completely free e-mail from Juno at http://www.juno.com Or call Juno at (800) 654-JUNO [654-5866]