PDA

View Full Version : Rtcc



Gerd
- 29th October 2012, 16:06
I have not programmed a pic for several years.
I want to use a 18F46J11 and I want to use the
on chip RTCC as a free running 1 sec timer
with the RB1 port giving me every sec an output
(0.5s on 0.5s off). This is from the spec sheets.
In my design I have a 32.768 kHz crystal on the
Timer1 external clock input Pin RC0/RC1.
How do I initiate the timer in PBP?
Any help is greatly appreciated, however my
feedback how things worked out will have to
wait a bit since I am currently laying out the pcb
and I have to know if I have to make changes
to my design.

Thank you for your help

Gerd

mackrackit
- 30th October 2012, 01:07
I am not familiar with that chip, but for the timer I would use DT's Instants
http://darreltaylor.com/DT_INTS-18/home.html

And do you really layout the PCB before testing on a breadboard? You are braver than me :eek:

Gerd
- 30th October 2012, 13:55
thanks for the link but I don't want to use interups since the accuracy is not important.
I just want the 1 sec rtcc output.
I may have written poorly in my initial request but I do breadbord before finishing the
pcb. I do temporary lay-outs to see how everything fits.

Gerd

Bruce
- 4th November 2012, 21:05
This was tested on a PIC18F25J11 running at 3V, but should work on your 46J11. Note it was tested with PBP3, but can easily be modified to work with earlier versions.


#CONFIG
CONFIG OSC = INTOSC
CONFIG LPT1OSC = OFF
CONFIG CP0 = OFF
CONFIG WDTEN = OFF
CONFIG XINST = OFF
CONFIG IOL1WAY = OFF
CONFIG STVREN = OFF
CONFIG T1DIG = OFF
CONFIG FCMEN = OFF
CONFIG WDTPS = 512
CONFIG RTCOSC = T1OSCREF
#ENDCONFIG

' Connect a 32.768 kHz watch crystal between pins 11 & 12 T1CKI & T1OSI
' with caps to match your crystal capacitance.
' 11 12
' |---||---|
' | xtal |
' _|_ _|_
' ___ ___ 2 x 12pF caps
' | |
' gnd gnd

DEFINE OSC 4
OSCCON = %01100000 ' using 4MHz internal osc

' // disable A/D & setup Timer1 for RTCC //
ANCON0 = $ff
ANCON1 = $1f ' disable A/D on all analog pins
T1CON = %10001101 ' ext 32.768 kHz xtal, 1:1 prescale, no synch, 8-bit, timer1 on
TRISB.1 = 0 ' clear TRISB.1 for RTCC 1Hz output
PADCFG1 = %00000010 ' RTCC seconds clock is selected for output on the RTCC pin
RTCCFG.2 = 1 ' set RTCC output enable bit

EECON2 = $55 ' unlock sequence to enable writes to RTCC registers
EECON2 = $AA
RTCCFG.5 = 1 ' set bit 5 for RTCC write enable
RTCCFG.7 = 1 ' set bit 7 for RTCC clock enable

EECON2 = $55 ' lock sequence to disable writes to RTCC registers
EECON2 = $AA
RTCCFG.5 = 0 ' clear bit 5 to lockup & disable RTCC writes

Here:
GOTO Here

END
It produces a very accurate 1Hz clock out on RB1.

This is a working test version of a serial clock & 3 x 10KHz PWM outputs with the same PIC 6729

Hope this helps.

Gerd
- 5th November 2012, 20:15
Bruce

Thank you very much for your help. I had internet problems on my home computer
so could not receive your response over the weekend. I am using now my work computer.
I am going to try it out and I believe the onboard rtcc is the same on all 18F chips.
Thanks again and best regards

Gerd