View previous topic :: View next topic |
Author |
Message |
colin382
Joined: 03 Jun 2020 Posts: 37 Location: UK
|
RTCC not incrementing |
Posted: Thu Apr 29, 2021 4:36 am |
|
|
Hi, I'm using the RTCC in an 18F24J11 with the Workshop compiler.
I am running the ex_rtcc.c example with just the chip type and .h files changed, and using the 8MHz internal oscillator.
It compiles and runs, and I can set the date and time with Hyperterminal, but the clock does not increment.
I have tried adding the argument RTC_CLOCK_INT seen in another forum posting:
setup_rtc(RTC_ENABLE,RTC_CLOCK_INT,0);
and setup_rtc(RTC_CLOCK_INT,RTC_ENABLE,0);
but I get "Undefined identifier RTC_CLOCK_INT" error in both cases.
In the wizard, there is the option to set the RTCC clock source as 31KHz internal, but I don't see any statements or fuse setting to do this.
Any help, as always, gratefully received.
Colin382 |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Thu Apr 29, 2021 5:59 am |
|
|
To properly investigate this the compiler version is required and the first 20 or so
lines of your code showing the RTCC setup lines. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
colin382
Joined: 03 Jun 2020 Posts: 37 Location: UK
|
|
Posted: Thu Apr 29, 2021 6:40 am |
|
|
Thanks for the rapid response.
PICCW version 5.0.0.521
Entire code is:
Code: |
#include <18F24J11.h>
#use delay(internal=8mhz)
#pin_select U2TX = PIN_B1
#pin_select U2RX = PIN_B0
#use rs232(baud=300,UART2) //Text through the UART
int8 get_number()
{
char first,second;
do {
first=getc();
} while ((first<'0') || (first>'9'));
putc(first);
first-='0';
do {
second=getc();
} while (((second<'0') || (second>'9')) && (second!='\r'));
putc(second);
if(second=='\r')
return(first);
else
return((first*10)+(second-'0'));
}
void set_clock(rtc_time_t &date_time)
{
printf("\r\nPress ENTER after 1 digit answers.");
printf("\r\nYear 20: ");
date_time.tm_year=get_number();
printf("\r\nMonth: ");
date_time.tm_mon=get_number();
printf("\r\nDay: ");
date_time.tm_mday=get_number();
printf("\r\nWeekday 1-7: ");
date_time.tm_wday=get_number();
printf("\r\nHour: ");
date_time.tm_hour=get_number();
printf("\r\nMin: ");
date_time.tm_min=get_number();
date_time.tm_sec=0;
printf("\r\n\n");
}
void main()
{
rtc_time_t write_clock, read_clock;
setup_rtc(RTC_ENABLE,RTC_CLOCK_INT,0); //enables internal RTCC
set_clock(write_clock);
rtc_write(&write_clock); //writes new clock setting to RTCC
while(1)
{
rtc_read(&read_clock); //reads clock value from RTCC
printf("\r%02u/%02u/20%02u %02u:%02u:%02u",read_clock.tm_mon,read_clock.tm_mday,read_clock.tm_year,read_clock.tm_hour,read_clock.tm_min,read_clock.tm_sec);
delay_ms(250);
}
} |
|
|
|
dluu13
Joined: 28 Sep 2018 Posts: 395 Location: Toronto, ON
|
|
Posted: Thu Apr 29, 2021 8:54 am |
|
|
It looks like the reason why you can't use RTC_CLOCK_INT is because you
don't have that option in your header file.
Reading your device's datasheet, RTC appears to take its clock source from
Timer1, which is unusual to me.
Therefore, maybe you have to enable timer1 and set it to 32.768 kHz. See
p. 227 on your device datasheet.
The timer1 section of the datasheet also references using itself as a clock
source for other peripherals on page 207. In your device's header file,
there's the option T1_ENABLE_T1OSC which I think you can use. As for how
to actually configure it I leave it up to you to look into that :P |
|
|
colin382
Joined: 03 Jun 2020 Posts: 37 Location: UK
|
|
Posted: Thu Apr 29, 2021 10:29 am |
|
|
Yes, in fact there is nothing in the header file to select a clock source for the RTCC. The wizard has, but there is no evidence that it does anything.
Your suggestion of Timer1 was a good one, but I'm reluctant to meddle with the registers directly, particularly since the CCS compiler has so many helper functions. However, I have been unable to get the secondary oscillator running, or get a clock feed from Timer1 to the RTCC. I have a 32.768kHz crystal and 2x 20pF capacitors on the secondary oscillator pins, but it doesnt want to run. I think this is a common problem based on what I see in the Forum.
For my application I really only need one minute and one hour interrupts, so the calendar was only a "nice to have" but I have to abandon attempts to make it work.
Unless someone has a bright idea...? |
|
|
dluu13
Joined: 28 Sep 2018 Posts: 395 Location: Toronto, ON
|
|
Posted: Thu Apr 29, 2021 10:56 am |
|
|
Somewhere in the code library there's a "software RTC" that somebody
coded up that you can just drop in. It's not as accurate as running the RTC
from a 32.768 kHz crystal, but if you can tolerate some error then it's totally
fine...
https://www.ccsinfo.com/forum/viewtopic.php?t=26177
I'd try T1_ENABLE_T1OSC in setup_timer_1 first, but maybe you've already
tried that.
As for your oscillator on the SOSC pins, did you make sure that you are
connected to the T1OSI and T1OSO? I don't see actual SOSC pins on your
chip... You probably have to use the T1_ENABLE_T1OSC in order to activate
the driver of the crystal. Also, make sure that you have thoroughly cleaned
the area around the crystal and the caps since any of that extra capacitance
from left over flux and dirt can seriously screw up your crystal's operation. |
|
|
colin382
Joined: 03 Jun 2020 Posts: 37 Location: UK
|
|
Posted: Thu Apr 29, 2021 1:26 pm |
|
|
Thanks for the pointer to an alternative calendar routine. I have it working after a few adjustments to match my hardware.
This forum is AWESOME! |
|
|
dluu13
Joined: 28 Sep 2018 Posts: 395 Location: Toronto, ON
|
|
Posted: Thu Apr 29, 2021 1:27 pm |
|
|
I find the users here to be very friendly compared to some other online
support forums out there, to name one thing... |
|
|
|