Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

I can't get Timer1 to count external clock on a PIC18F27Q10

Status
Not open for further replies.

Bob D.

New Member
I must be missing something here, TMR1H:TMR1L is not incrementing in external clock mode from a square wave on RC0 (pin 11).
I'm using MPLAB XC8 C compiler. Here is how I have it initialized:

TRISCbits.TRISC0 = 1; //make RC0 an input
T1CON = 0x07; //1:1 prescaler, not synchronized, 16 bit R/W, enable timer
T1GCON = 0x00; //always counting, gate active high, gate toggle disabled, gate pulse mode disabled
TMR1CLK = 0x00; //set RC0 as the clock input
TMR1GATE = 0x00; //timer gate source, (timer gate is disabled)
TMR1H = 0x00; //clear timer
TMR1L = 0x00; //cleat timer

If I change TMR1CLK to 0x01 (Fosc/4), the timer counts fine. BTW, I'm using a breadboard with a PICkit 4.
Any help will be appreciated.

Bob D.
 
pin RC0 is analog capable (and defaults to analog mode)... be sure to set ANSELC bit 0 (ANSELC0) = 0,
otherwise the pin will always read '0'.
 
pin RC0 is analog capable (and defaults to analog mode)... be sure to set ANSELC bit 0 (ANSELC0) = 0,
otherwise the pin will always read '0'.

Setting it to a peripheral often over-rides that, and he's already said it works fine with the clock source set 'correctly' (presumably).

Only reason I'm aware of timer clock limitations is that I've been playing with PWM :D - and those require Fosc/4 - so presumably this does.
 
pin RC0 is analog capable (and defaults to analog mode)... be sure to set ANSELC bit 0 (ANSELC0) = 0,
otherwise the pin will always read '0'.
Thanks, that fixed the problem! :D This is the first micro I've used that had analog inputs. Another step down the learning curve.
 
Setting it to a peripheral often over-rides that, and he's already said it works fine with the clock source set 'correctly' (presumably).
While the TRIS direction setting may be controlled by the peripheral, the analog/digital mode setting of a pin is never overridden (at least not that I've ever seen). You must set it manually.

So why did it work when you changed the clock to Fosc/4?
Because 'FOSC/4' (the instruction cycle clock) is an internal path, and not taken from a pin.
 
While the TRIS direction setting may be controlled by the peripheral, the analog/digital mode setting of a pin is never overridden (at least not that I've ever seen). You must set it manually.


Because 'FOSC/4' (the instruction cycle clock) is an internal path, and not taken from a pin.
That's rather assuming he had it set to use an external clock? - in which case it still wouldn't work if set that way.
 
TMR1H:TMR1L is not incrementing in external clock mode from a square wave on RC0 (pin 11).
Not much of an assumption.

Most of the timers can be set to use an external pin as the clock source, but that depends on the timer # and device.
On many devices you can even use an external clock for the even-numbered timers used for PWM... you're not stuck with FOSC/4
 
Not much of an assumption.

Most of the timers can be set to use an external pin as the clock source, but that depends on the timer # and device.
On many devices you can even use an external clock for the even-numbered timers used for PWM... you're not stuck with FOSC/4

Ah - I mis-read what he'd put - I see what you mean now, thanks for that.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top