This is another Noob question, thanks for your patience.
I'm trying to use a one second timer by attaching a clock crystal to timer1.
This works perfectly on a 16F324 chip, but not on the 16F826 and I can't see what I'm missing.
The interupt is never getting called. It's the exact same circuit, just pop one chip out and the other in.
'#chip 16F18324,32'#define chipno 1#chip 16F18426,32#define chipno 2#config RSTOSC=HFINT32, MCLRE=OFF
#configFEXTOSC=OFF,CLKOUTEN=OFF', WRT=OFF, CPD=onDIRPortA.4IN' 32k crystalDIRPortA.5IN' 32k crystaldirPortA.2out' pulse led once per secondInitTimer1ExtOsc,0' 32768 crystal time keeperOn Interrupt Timer1Overflow Call CheckClockClearTimer 1StartTimer 1do if DoClock then DoClock=0PulseOutPortA.2,100ms' pulse led end ifloopsub CheckClockTMR1H=128'TMR1H = 0x80 'setupforoneseconddelayDoClock=1' time to blink ledend sub
Last edit: Jim giordano 2019-01-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
These are different microcontroller families therefore there is more of a setup required for the 16f18426... T1CK1. This part requires PPS where the other parts may have a T1CK1 default port assignment.
T1CKIPPS=0x05;//RA5->TMR1:T1CKI;
But, you should always add PPS for both parts and I would ensure you understand the need for the port DIRection.
Anobium
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Evan-
I simplified the program as much as possible. I used all the default ports so I wouldn't have to mess with PPS to present the smallest code I could for people to look at. I'm not sure what you were referring to when you said "ensure you understand the need for the port DIRection", any enlightment will be appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think the T1CKIPPS is for a clock pulse on a particular pin and not for an external crystal. The external clock crystal has to be on A.4 and A.5.
You need to set the TMR1CLK register to b'00000111' to select the secondary oscillator(SOCS) directed to timer1. Then set T1CON.0=1 to activate timer 1.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Oops! I got the chip number wrong (that above is for the 16F18426).
For the 18324 you just need to set the T1CON=b'10001001'
To check if the timer is working, but the crystal is not oscillating change to
T1CON=b'11001001' this will select the LFINTOSC (at 31.25 kHz)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
David-
You were right the first time, it was meant for the 16F18426 :)
All it took was TMR1CLK=b'00000111' after doing the InitTimer1.
I printed out TMR1CLK after doing the InitTimer1 and it was set to 3 (b'00000011') which is HFINTOSC rather than SOSC.
I couldn't find anywhere in the chipdata file where the clock sources for the timers are indicated. Perhaps there's something I should be using rather ExtOsc.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is a new timer.h file available that fixes the problem for both the 16F1826 and 16F18324 familys. It is no longer necessary to manually set TMR1CLK.
InitTimer1 SOSC,0 or InitTimer1 ExtOsc,0 is now working properly :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is another Noob question, thanks for your patience.
I'm trying to use a one second timer by attaching a clock crystal to timer1.
This works perfectly on a 16F324 chip, but not on the 16F826 and I can't see what I'm missing.
The interupt is never getting called. It's the exact same circuit, just pop one chip out and the other in.
Last edit: Jim giordano 2019-01-15
These are different microcontroller families therefore there is more of a setup required for the 16f18426... T1CK1. This part requires PPS where the other parts may have a T1CK1 default port assignment.
But, you should always add PPS for both parts and I would ensure you understand the need for the port DIRection.
Anobium
Evan-
I simplified the program as much as possible. I used all the default ports so I wouldn't have to mess with PPS to present the smallest code I could for people to look at. I'm not sure what you were referring to when you said "ensure you understand the need for the port DIRection", any enlightment will be appreciated.
I think the T1CKIPPS is for a clock pulse on a particular pin and not for an external crystal. The external clock crystal has to be on A.4 and A.5.
You need to set the TMR1CLK register to b'00000111' to select the secondary oscillator(SOCS) directed to timer1. Then set T1CON.0=1 to activate timer 1.
Oops! I got the chip number wrong (that above is for the 16F18426).
For the 18324 you just need to set the T1CON=b'10001001'
To check if the timer is working, but the crystal is not oscillating change to
T1CON=b'11001001' this will select the LFINTOSC (at 31.25 kHz)
David-
You were right the first time, it was meant for the 16F18426 :)
All it took was TMR1CLK=b'00000111' after doing the InitTimer1.
I printed out TMR1CLK after doing the InitTimer1 and it was set to 3 (b'00000011') which is HFINTOSC rather than SOSC.
I couldn't find anywhere in the chipdata file where the clock sources for the timers are indicated. Perhaps there's something I should be using rather ExtOsc.
There is a new timer.h file available that fixes the problem for both the 16F1826 and 16F18324 familys. It is no longer necessary to manually set TMR1CLK.
InitTimer1 SOSC,0 or InitTimer1 ExtOsc,0 is now working properly :)