PIC microcontroller counter

Thread Starter

khatus

Joined Jul 2, 2018
115
The maximum clock frequency at the T0CKI input is limited by the synchronization requirement with the internal clock. Each machine cycle (or instruction cycle) for a PIC microcontroller consists of four clock cycles, which are named as Q1, Q2, Q3, and Q4. The synchronization of T0CKI with the internal clock is accomplished by sampling the prescaler output on the Q2 and Q4 cycles of each machine cycle. Therefore, the external clock signal at T0CKI should remain high or low for at least half of the duration of the machine cycle (which is 2Tosc, Tosc is the period for the main oscillator), plus an additional resistor-capacitor delay of 20 ns. This determines the minimum value of the pulse width that enters through the T0CKI pin. The minimum time period of the input clock pulse is, therefore, 4Tosc + 40 ns, and the maximum frequency will be the reciprocal of this.

I can't understand the line "The synchronization of T0CKI with the internal clock is accomplished by sampling the prescaler output on the Q2 and Q4 cycles of each machine cycle".
Can anybody explain??
 

geekoftheweek

Joined Oct 6, 2013
1,429
Pretty much what it means is when your T0CKI changes state the timer module won't pick it up and count it until the next rising edge of the system clock at either the Q2 or Q4 cycles. Say your system clock is 48MHz and your T0CKI is 2.5MHz. Since the clock edges will only line up one out of how ever many times it takes for it to happen there will be times when the timer counts the T0CKI pulse a little later than others... not normally a big problem unless you're trying to time an exact event (within nanosecods) or create an output based on the timer that needs nanosecond precision. I'm guessing at 48MHz anything lower than 1ms would be more or less an approximation.

To illustrate I did a screenshot of a I2C communication I captured with a home made logic analyzer. If I remember right the I2C is running in the neighborhood of 44kHz and the analyzer a little less than 178kHz. Every once in a while you can see a short looking cycle since the timings are not the same.

ss.jpg
 
Top