PDA

View Full Version : Help with RTCC Module - 18F26J50



Aussie Barry
- 13th September 2017, 08:40
Hi All,

I am having difficulties getting a 1Hz pulse from the output of the RTCC module on a PIC18F26J50.
I have a 32.768kHz signal being fed directly to the T1CKI input from my signal generator to act as the clock source.
I have a 2Hz signal being generated via the main program look and fed to RB2 to show that the program is alive and running.
RB2 feeds to an LED via a suitable current resistor to ground - this works perfectly and the LED flashes as expected.
I have the same LED/current resistor connected from the RTCC output (RB1) to ground - this this pin is always low!
My program is as follows:



'************************************************* **********************
'* Name : RTCC_18F26J50_Test.pbp *
'* Author : Barry Phillips *
'* Notice : Copyright (c) 2017 Baztronics *
'* : All Rights Reserved *
'* Date : 12/09/2017 *
'* Version : 1.0 *
'* Notes : Program to generate a 1Hz output on RB1 (pin 22) using *
'* : RTCC module on PIC18F26J50. A 32.768kHz signal is fed to *
'* : the T1CKI (pin 11) to drive the RTCC. A 2Hz signal is *
'* : generated in the main program loop and output on RB2 *
'* : (Pin 23) to indicate the program is alive and running. *
'************************************************* **********************

;----[Device Configuration]-----------------------------------------------------
#CONFIG
CONFIG WDTEN = OFF ; Disabled
CONFIG PLLDIV = 1 ; Divide by 1 (4 MHz oscillator input)
CONFIG STVREN = OFF ; Disabled
CONFIG XINST = OFF ; Disabled
CONFIG DEBUG = OFF ; Disabled
CONFIG CPUDIV = OSC1 ; No CPU system clock divide
CONFIG CP0 = OFF ; Program memory is not code-protected
CONFIG OSC = INTOSC ; Internal Oscillator
CONFIG T1DIG = OFF ; Secondary Oscillator clock source may be not selected
CONFIG LPT1OSC = OFF ; High-power operation
CONFIG FCMEN = OFF ; Disabled
CONFIG IESO = OFF ; Disabled
CONFIG WDTPS = 512 ; 1:512
CONFIG DSWDTOSC = INTOSCREF ; DSWDT uses INTRC
CONFIG RTCOSC = T1OSCREF ; RTCC uses T1OSC/T1CKI
CONFIG DSBOREN = OFF ; Disabled
CONFIG DSWDTEN = OFF ; Disabled
CONFIG DSWDTPS = G2 ; 1:2,147,483,648 (25.7 days)
CONFIG IOL1WAY = OFF ; The IOLOCK bit (PPSCON<0>) can be set and cleared as needed
CONFIG MSSP7B_EN = MSK7 ; 7 Bit address masking mode
CONFIG WPFP = PAGE_0 ; Write Protect Program Flash Page 0
CONFIG WPEND = PAGE_WPFP ; Page WPFP<5:0> through Configuration Words erase/write protected
CONFIG WPCFG = OFF ; Configuration Words page not erase/write-protected
CONFIG WPDIS = OFF ; WPFP<5:0>/WPEND region ignored
#ENDCONFIG

;----[DEFINEs]------------------------------------------------------------------
DEFINE OSC 4

;----[Aliases]------------------------------------------------------------------

;----[Variables]----------------------------------------------------------------

;----[Initialize]---------------------------------------------------------------
OSCCON = %01101100 ;4MHz Oscillator
ANCON0 = %11111111 ;All pins configured as a digital I/O
ANCON1 = %00011111 ;Band gap turned off
;All other pins configured as a digital I/O
T1GCON.7 = 0 ;Timer1 gate disabled
TCLKCON.4 = 1 ;Device is clocked by T1OSC/T1CKI
T1CON = %10000101 ;T1CKI Input
;1:1 prescale
;no sync
;8-bit
;Timer1 on
TRISB = 0 ;All PORTB as digital output
PADCFG1 = %00000010 ;RTTC Seconds clock output on the RTCC pin
RTCCFG.2 = 1 ;Enable RTCC output
EECON2 = $55 ;unlock sequence to enable writes to RTCC registers
EECON2 = $AA
RTCCFG.5 = 1 ;Enable RTCC write
RTCCFG.7 = 1 ;Enable RTCC module
EECON2 = $55 ;lock sequence to disable writes to RTCC registers
EECON2 = $AA
RTCCFG.5 = 0 ;Disable RTCC write

;----[Main Program Loop]--------------------------------------------------------
Main:
PORTB.2 = 1
PAUSE 250
PORTB.2 = 0
PAUSE 250
GOTO Main

END




I know the TIMER1 settings are correct and the clock source is operational because I have proven operation using a separate program with DT_INTS-18 and a flashing LED ISR routine.
This only leaves the RTCC register setting which have been copied directly from a previous RTCC post http://www.picbasic.co.uk/forum/showthread.php?t=19210&highlight=RTCC
I have spent days trying to work out what I have done wrong - alas, all to no avail :(

Any assistance to help resolve this problem would be greatly appreciated.

Cheers
Barry
VK2XBP

HenrikOlsson
- 13th September 2017, 09:24
Hi Barry,
I've never used the RTCC module so this is pure speculation on my behalf.
As far as I can see the RTCC module is meant to be clocked from the TMR1 oscillator (or an internal RC oscillator). Clocking TMR1 with an external signal to T1CKI is not the same thing - I don't think. The RTCC doesn't really use TMR1 so the fact that you see TMR1 "running" doesn't mean the RTCC is.

Again, purely speculation and interpretation of the datasheet, no personal experience here.

Happy programmers day!

/Henrik.

richard
- 13th September 2017, 10:00
the data sheet says

If the Timer1 oscillator will be used as the clock source
for the RTCC, make sure to enable it by setting
T1CON<3> (T1OSCEN). The selected RTC clock can
be brought out to the RTCC pin by the
RTSECSEL<1:0> bits in the PADCFG register.


which is missing in your code
T1CON = %10000101
try
T1CON = %10001101

Aussie Barry
- 14th September 2017, 09:39
Thanks Henrik and Richard for responding to my post so quickly.

Henrik - your speculation and my speculation differ. Thanks for offering an opinion.

Richard - I set the T1CON register that way on purpose BUT, I also tried your suggestion. Neither fixed the problem :(

My plan now is to cut my losses and go to a new design using an I2C RTCC with a PIC16F1828.
I will keep you all posted on my progress.

Cheers
Barry
VK2XBP

richard
- 14th September 2017, 14:18
maybe its a mistake to set the !T1SYNC bit.
I notice the example code does not set that bit.
one thing is for sure the Timer1 oscillator will not run if its not enabled ,after that its all guess work for me

richard
- 14th September 2017, 15:02
how is the 32k signal coupled to the t1clk ?

if I recall correctly to sync the t1osc with the ext signal the coupling needs to be a capacitive
one . try about .01uF
make sure the other xtal pin is not loaded up either, or you may need to drive that pin too
can't remember.
why not just put a rock on it anyway, there're cheap

google up using tcxo with pic to get some better info