• AVR Freaks

AnsweredHot!PIC16F18446 Timer1 never counts

Author
obones
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2006/03/06 08:15:09
  • Location: 0
  • Status: offline
2019/09/10 08:36:36 (permalink)
0

PIC16F18446 Timer1 never counts

Hello,
 
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;

//GSS T1G_pin;
T1GATE = 0x00;

//CS LFINTOSC;    
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?
 
Regards
#1
pcbbc
Super Member
  • Total Posts : 1448
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: PIC16F18446 Timer1 never counts 2019/09/10 10:05:53 (permalink) ☼ Best Answerby obones 2019/09/10 12:27:18
+2 (2)
Timer2 is also set to run from the LFINTOSC?
DatasheetThe LFINTOSC is enabled through one of the following methods:
• Programming the RSTOSC bits of Configuration Word 1 to enable LFINTOSC.
• Write to the NOSC bits during run-time.

 
Without a complete example it's very hard to say what is wrong.
#2
obones
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2006/03/06 08:15:09
  • Location: 0
  • Status: offline
Re: PIC16F18446 Timer1 never counts 2019/09/10 12:27:08 (permalink)
0
You are right, Timer2 is from HFINTOSC, the same source as the system clock.
Enabling LFINTOSC in the OSCEN register makes Timer1 properly, so clearly, it was an error from me and you gave me a very good answer.
 
That being said, the datasheet is quite misleading. I mean, at page 116, the description for the LFOEN bit says that a value of 0 means "LFINTOSC is only enabled if requested by a peripheral". To me, the configuration above says that Timer1 requires LFTINTOSC so the phrase in the datasheet leads me to believe that it will be automatically activated by Timer1 configuration.
Obviously, this is not the case and I'll keep that in mind in future projects.
 
Once again, thank you for your answer.
#3
pcbbc
Super Member
  • Total Posts : 1448
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: PIC16F18446 Timer1 never counts 2019/09/10 12:43:53 (permalink)
0
Happy I could help. Just a guess as to where to start looking really, based on a cursory read of the datsheet. Lucky it was the right answer!

Agree the datasheet perhaps isn’t the clearest, especially the wording you mention on page 116.

Perhaps by “peripheral” it means one of the functions mentioned in:
Datasheet9.2.2.5 LFINTOSC
The Low-Frequency Internal Oscillator (LFINTOSC) is a factory-calibrated 31 kHz internal clock source.
The LFINTOSC is the frequency for the Power-up Timer (PWRT), Windowed Watchdog Timer (WWDT) and Fail-Safe Clock Monitor (FSCM).

But again, I’m just guessing.
#4
obones
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2006/03/06 08:15:09
  • Location: 0
  • Status: offline
Re: PIC16F18446 Timer1 never counts 2019/09/10 13:08:17 (permalink)
0
That's an interesting guess indeed.
FSCM is enabled in my configuration, but because I'm using the internal HF oscillator, it means it is of no use, so may well be disabled after all, thus leading to LFINTOSC being disabled as well.
Anyway, I got this sorted, I can now move on to the other parts.
#5
obones
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2006/03/06 08:15:09
  • Location: 0
  • Status: offline
Re: PIC16F18446 Timer1 never counts 2019/09/11 00:25:33 (permalink)
0
Well, I found another way for any Timer not to function at all on this part, and it's via the PMD1 register.
I'm posting this message here just in case someone runs into this as well.
#6
Jump to:
© 2020 APG vNext Commercial Version 4.5