PIC16F18446 Timer1 never counts
I'm trying to use the DHCP client part of the TCP/IP Lite library within MPLab and MCC and could not get it to work with my PIC16F18446 discovery board.
Narrowing down the faulty code via debugging, I discovered that Timer1, which is used by TCP/IP Lite, never actually counts anything, and so never triggers its ISR which is required for the "pseudo RTC" that is setup by the library.
So I created a sample project where I simply setup Timer1 and Timer2 using MCC and tried having their respective ISRs to trigger. I set the priority of Timer1 so that it triggers before Timer2.
While Timer2 works "out of the box", I cannot get Timer1 to start counting. Here is the code generated by MCC:
//T1GE disabled; T1GTM disabled; T1GPOL low; T1GGO done; T1GSPM disabled;
T1GCON = 0x00;
T1GATE = 0x00;
T1CLK = 0x04;
// 250ms interval
TMR1H = 0xE1;
TMR1L = 0xBA;
PIR4bits.TMR1IF = 0;
PIE4bits.TMR1IE = 1;
// CKPS 1:1; NOT_SYNC synchronize; TMR1ON enabled; T1RD16 disabled;
T1CON = 0x01;
As I am using pretty much the default values within MCC, I assumed this would work "out of the box", and this is only what AN1921 is talking about.
But clearly, there must be something wrong because the ISR for Timer1 is never triggered and its value is never updated either.
I thus went to the datasheet for my part, and at page 359, the table says that both the ON and GE bits must be set to 1 for the timer to count. However, on page 362, there is this line:
Timer1 can be configured to run freely or the count can be enabled and disabled using Timer1 gate circuitry.
But I don't see how I can do that, which would basically mean not using the Gate Enable feature.
So I went on and tried to see how I could turn Gate Enable on and this means selecting a source for the gate itself. Using the default value means "requiring" an input pin, and because I don't want its value to ever change, I used the WeakPull up on it and the polarity to High.
But even then, I never get any update on Timer1 and I'm a bit lost as to what to try next.
Would you have any suggestion as to what I have missed in the various options for Timer1?