PIC: 24FJ256GA702 timer counter external pulse counting. - Page 1
Forum section: electronics / general

author: Graffite
author_rank: Contributor
timestamp: March 23, 2022, 02:20:08 pm
content: Hello.Can someone explain what the external timer counter Pin TxCLK and T1CLK, T2CLK, T3CLK mean. T2CLK, T3CLK are mappable and T1CLK seems to be on pin 18 RP9 although the data sheets is marked T1CK? for this pin, is that the correct pin? Why does each timer/counter mention TxCLK? Normally the small 'x' means a number but what is that referring to??I would like one pin to clock all three counters if possible. I can clock 2 and 3 together but when a try 1, 2 and 3 2 stops counting. I am new to this IC and am finding the remapping a little taxing at the moment with more questions than answers.Many thanks for your help.Geoff

author: jpanhalt
author_rank: Super Contributor
timestamp: March 23, 2022, 03:11:54 pm
content: I do not use that chip but have a little experience with Microchip nomenclature.Here's a link to its datasheet (I assume you have it, but others might not.)https://ww1.microchip.com/downloads/en/DeviceDoc/PIC24FJ256GA705-Family-Data-Sheet-DS30010118E.pdfQuoteI think there's a typo. It should be TxCK = Generic timer external clock. That name certainly suggests a generic external clock can be used with almost every timer, but not necessarily the same clock for each. (attachment)

author: Graffite
author_rank: Contributor
timestamp: March 23, 2022, 05:06:05 pm
content: Sorry my bad. I added the L, got used to CLK as a clock line.From the data sheet high lighted in yellow attachment. Two external pins. SOSC from a external watch xtal and LPRC from the internal system clk. Two pins T1CK External is shown on (TDO/C1INC/C2INC/C3INC/TMPRN/RP9/SDA1/ T1CK /CTED4/RB9) and but TxCK! is not clear for me as to what it refers to.Geoff

author: jpanhalt
author_rank: Super Contributor
timestamp: March 23, 2022, 06:50:33 pm
content: Timer1 is a type of clock. It is different than the CLK2/3. I am only an 8-bit'er. But some of those chips have multiple clocks as well. I have often dreamed of going to a PIC24F, but just haven't made that move yet.

author: JPortici
author_rank: Super Contributor
timestamp: March 24, 2022, 12:06:37 pm
content: Don't just look at figures.REGISTER 13-1: TxCON: TIMER2 CONTROL REGISTERthe TECS field, which selects the clock source has a note:"If TCS = 1 and TECS[1:0] = x1, the selected external timer input (TxCK or TyCK) must be configured to anavailable RPn/RPIn pin. For more information, see Section 11.5 “Peripheral Pin Select (PPS)”"so let's look at Section 11.5specifically TABLE 11-6: SELECTABLE INPUT SOURCES (MAPS INPUT TO FUNCTION)you have the registers for T2CK, T3CK and.. TxCKSuppose you want to feed the "generic clock" into RA0/RP26The pin must be configured as an input, digital_TRISA0 = 1;_ANSELA0 = 0;then to assign the PPS function of TXCK to RA0_TXCKR = 26;then you can use TXCK as a clock source for your timers

author: Graffite
author_rank: Contributor
timestamp: March 24, 2022, 01:34:50 pm
content: Hi all. Many thanks for your input. Now a understand the generic clock input. Its just a external mapping pin to connect all external clocks.I still cant get all three working together.If I setup timer 1 and 2 and 3 timer 2 wont count 1 and two are fine.if I setup only timer 2 and 3 they work fine.Its seems very odd to me and I am struggling to see why. This seems to happen regardless of the mapping and clocking methods. I have tried many and now as suggested with TxCk. I cant see what I am missing. I have attached the code, Its still at its bare bones stage.

author: JPortici
author_rank: Super Contributor
timestamp: March 24, 2022, 05:01:51 pm
content: Some notesone thing the XC16 compiler team did that i find awesome is that the device include file also has macros for the actual bit inside a register. this is great for interrupt flags and the like, so i don't have to remember where the hell they areanother thing, you don't need to mess with interrupt priorities unless you really need to. interrupts can be nested (or not)Then, there are peripherals that don't like their configuration to be changed while they're activetry thisCode:void init_timer1(void) {T1CON = 0;T1CONbits.TCS = 1; //Use the extended clock sourceT1CONbits.TECS = 3; //Extended clock source is TxCKTMR1 = 0;PR1 = 0xFF;_T1IF = 0;_T1IE = 1;_T1IP = 3;T1CONbits.TON = 1;}void init_timer2(void) {T2CON = 0;T2CONbits.TCS = 1; //Use the extended clock sourceT2CONbits.TECS = 3; //Extended clock source is TxCKTMR2 = 0;PR2 = 0x200;_T2IF = 0;_T2IE = 1;_T2IP = 5;T2CONbits.TON = 1;}void init_timer3(void) {T3CON = 0;T3CONbits.TCS = 1; //Use the extended clock sourceT3CONbits.TECS = 3; //Extended clock source is TxCKTMR3 = 0;PR3 = 0xFF;_T3IF = 0;_T3IE = 1;_T3IP = 2;T3CONbits.TON = 1;}

author: Graffite
author_rank: Contributor
timestamp: March 24, 2022, 06:19:56 pm
content: OH, Wow that's fixed it. JPortici. I don't know how to thankyou enough.This was turning into quite a headache for me.I will look into the Macros further and I guess your point is not starting the timers running until the other register bits are set.Many thanks again.

author: JPortici
author_rank: Super Contributor
timestamp: March 24, 2022, 06:27:55 pm
content: notice that i just changed the order of operations.. first set up the timer THEN enable it.