CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

can't start RTC with setup_rtc(RTC_ENABLE, 0); on 18F27J53

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Steffe



Joined: 03 May 2011
Posts: 6

View user's profile Send private message

can't start RTC with setup_rtc(RTC_ENABLE, 0); on 18F27J53
PostPosted: Fri Oct 14, 2011 3:52 am     Reply with quote

Hallo,

Can't set the date and time and with
Code:
rtc_read(&read_clock);

I alway read the same time. I to want to use the internal clock and PLL for my USB and A6 /A7 as IO pins. The code I have reduced to check the RTC functionality.

Does have somebody a idea why RTC can't start ?

Great thanks for hints

Steffe
Code:

#include <18F27J53.h>

#FUSES NODEBUG
#FUSES NOXINST       
#FUSES STVREN
#FUSES NOPROTECT
#FUSES NOIESO
#FUSES NOCPUDIV       // no CPU Clock Division ist 00     
#FUSES INTRC_PLL_IO  // use A6 and A7  as IO
#FUSES INTRC_IO        // use A6 and A7  as IO
#fuses PLLEN              // PLL aktivieren
#FUSES PLL2           
#FUSES RTCOSC_INT    // RTC internal clock


// #use delay(clock=48000000)
#use delay(clock=8000000)


#DEFINE LED1   PIN_C2

#ifndef LED_ON
#define LED_ON(x) output_high(x)
#endif

#ifndef LED_OFF
#define LED_OFF(x) output_low(x)
#endif




void main()
{
    rtc_time_t write_clock, read_clock;
    int8 sec_old;
   
    memset(&write_clock, 0, sizeof(rtc_time_t));
    memset(&read_clock, 0, sizeof(rtc_time_t));

    write_clock.tm_year = 11;
    write_clock.tm_mon  = 10;
    write_clock.tm_mday = 13;
    write_clock.tm_wday = 4;
    write_clock.tm_hour = 13;
    write_clock.tm_min  = 6;
    write_clock.tm_sec  = 7;

   
    setup_rtc(RTC_ENABLE, 0);         //enables internal RTCC
    rtc_write(&write_clock);         //writes new clock setting to RTCC
    sec_old = 0;
    rtc_read(&read_clock);        //reads clock value from RTCC
    sec_old = read_clock.tm_sec;
    LED_ON(LED1);
    while(1){
        rtc_read(&read_clock);        //reads clock value from RTCC
        if( sec_old != read_clock.tm_sec ){
            LED_OFF(LED1);
        }
    }
}
Steffe



Joined: 03 May 2011
Posts: 6

View user's profile Send private message

Re: can't start RTC with setup_rtc(RTC_ENABLE, 0); on 18F27J
PostPosted: Fri Oct 14, 2011 7:36 am     Reply with quote

Hi again,

Just for info, I'm using compiler version 4.125
in hope somebody can give me a hint.

great thanks
Steffe
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 14, 2011 1:37 pm     Reply with quote

Quote:
#include <18F27J53.h>

#FUSES NODEBUG
#FUSES NOXINST
#FUSES STVREN
#FUSES NOPROTECT
#FUSES NOIESO
#FUSES NOCPUDIV // no CPU Clock Division ist 00
#FUSES INTRC_PLL_IO // use A6 and A7 as IO
#FUSES INTRC_IO // use A6 and A7 as IO
#fuses PLLEN // PLL aktivieren
#FUSES PLL2
#FUSES RTCOSC_INT // RTC internal clock


// #use delay(clock=48000000)
#use delay(clock=8000000)

The first thing you need to do is to fix your fuses. First you tell the
compiler to use the Internal Oscillator with the PLL, then in the next
line, you tell it to use the Int. Osc. without the PLL. Then you have
two more PLL fuses.

Fix your fuses. Then make a small program that toggles an LED on and
off at 1 Hz. Check it with a stopwatch, or some other method. Make sure
your PIC is really running at the frequency that you specify in the #use
delay() statement.

What frequency do you really want to use for the PIC ?


The RTC module is normally used with the Timer1 oscillator. A 32.768 KHz
watch crystal (and capacitors) is connected externally to the PIC, on the
Timer1 oscillator pins. Do you have that external crystal circuit connected ?

Also, is this project being tested in real hardware or is it Proteus ?
Steffe



Joined: 03 May 2011
Posts: 6

View user's profile Send private message

PostPosted: Fri Oct 14, 2011 3:13 pm     Reply with quote

Hello PCM programmer,

oh oh yes that doesn't work together thank you,

Now I changed the code and circuit using external crystal 32,768kHz on T1OSO and T1OSI.
After the call "setup_rtc(RTC_ENABLE, 0);" the crystal begins to work I can see, but still I can't see with my LED Test the RTC second is counting.

I miss something like write enable because if I write and read to the rtc date and time I can't see some changes on the timer.

I work with my one circuit, made a solid PCB, USB is working with 48MHz, my SPI bus works also. But my RTC,

hope you have a idea ?

Great thanks

Steffe

here is my new code

Code:

#include <18F27J53.h>

#define ADC=10

#FUSES NODEBUG
#FUSES NOXINST       // keine extendet Funktionen
#FUSES NOPROTECT
#FUSES NOIESO
#FUSES NOCPUDIV      // keine CPU Clock Division ist 00     
#FUSES INTRC
#FUSES SOSC_HIGH
#FUSES RTCOSC_T1

#use delay(clock=8000000)

void main()
{
    rtc_time_t write_clock, read_clock;
    int8 i, sec_old;
   
    set_tris_c(0b10111010);
    setup_rtc(RTC_ENABLE, 0);

    sec_old = 0;
    rtc_read(&read_clock);           //reads clock value from RTCC
    sec_old = read_clock.tm_sec;
    output_high(PIN_C2);  // LED ON
    while(1){
        rtc_read(&read_clock);        //reads clock value from RTCC
        if( sec_old != read_clock.tm_sec ){
            output_low(PIN_C2); // LED OFF
        }
        delay_ms(100);
    }
}

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 14, 2011 5:47 pm     Reply with quote

Quote:

Now I changed the code and circuit using external crystal 32,768kHz on T1OSO and T1OSI.

Do you have capacitors on the 32.768 KHz watch crystal pins ?
The PIC data sheet recommends 12pf ceramic capacitors.


Are you using the "F" or the "LF" version of the PIC ? If you have the
"F" version, you must have a 10 uF capacitor, low esr, ceramic cap on
the VCAP/VDDCORE pin of the PIC. Do you have it ? This is it:
http://search.murata.co.jp/Ceramy/image/img/PDF/ENG/GRM21BF50J106ZE01.pdf
Note: The cap listed above is no longer manufactured. See the following
link for replacements:
https://www.digikey.com/en/products/detail/murata-electronics/GRM21BF50J106ZE01L/587391

If you have the "LF" version, there are other instructions given in this section:
Quote:
2.4 Voltage Regulator Pins
(VCAP/VDDCORE)

--------------------------------------------------
Edited to add link for replacement capacitors.


Last edited by PCM programmer on Fri Apr 28, 2023 10:59 am; edited 1 time in total
Steffe



Joined: 03 May 2011
Posts: 6

View user's profile Send private message

PostPosted: Sat Oct 15, 2011 2:55 am     Reply with quote

Hello PCM programmer,
Great thanks for this hints.
Yes I have 2 x SMS Ceramic 10pF on the "F" version.
VCAP/VDDCORE direct connected to VDD.
I can see starting crystal if I call the function:
Code:
setup_timer_1(T1_EXTERNAL|T1_ENABLE_SOSC);

or
Code:
setup_rtc(RTC_ENABLE, 0);

Does the function do the connecting TIMER1 -> RTC?
Does it have something with the INTRC setting ?
Hope we can find why the RTC is not starting.
best
Steffe
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 15, 2011 9:52 am     Reply with quote

Quote:

Yes I have 2 x SMS Ceramic 10pF on the "F" version.
VCAP/VDDCORE direct connected to VDD.

You say you have the "F" version, and that you have
connected the VCAP/VDDCORE pin to Vdd. But that's
wrong. On the "F" version, you should not connect
that pin to Vdd. The PIC data sheet says:
Quote:

2.4 Voltage Regulator Pins
(VCAP/VDDCORE)

On “F” devices, a low-ESR (< 5?) capacitor is required
on the VCAP/VDDCORE pin to stabilize the voltage regulator
output voltage. The VCAP/VDDCORE pin must not be
connected to VDD and must use a capacitor of 10 uF connected
to ground.


If you have the "F" version, and you connected the Vdd voltage to the
VCAP pin, you might have damaged part of the PIC. The data sheet says:
Quote:

31.0 ELECTRICAL CHARACTERISTICS

Voltage on VDDCORE with respect to VSS......... -0.3V to 2.75V


What is your Vdd voltage ? Is it +3.3v ?
Quote:

• Operating Voltage Range of 2.0V to 3.6V
• On-Chip 2.5V Regulator

If your Vdd is 3.3v, this would mean that you connected +3.3 to the
output of the 2.5v regulator. I don't know what that would do, but it
is a violation of the data sheet. It's possible that you damaged the PIC.
Steffe



Joined: 03 May 2011
Posts: 6

View user's profile Send private message

PostPosted: Sat Oct 15, 2011 11:57 am     Reply with quote

Great thanks for your info, yes "F" version needs a cap, huuu....
I made the change on a new PCB with a new 18F27J53.
But still my RTC doesn't work on both, my simple test program and USB test for display the date and time.
I did another test with an external CPU crystal (12MHz) HSPLL, but no success.
I did a another test with RTCC_unlock() like
http://www.ccsinfo.com/forum/viewtopic.php?t=44482&highlight=rtccunlock
but it doesn't help, every rtc_read(..) the same value,

do you have another idea ?

in hope best

Steffe
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 16, 2011 5:56 pm     Reply with quote

I looked at the .LST file. In vs. 4.125, the 18F27J53 has bugs in the
rtc_read() and rtc_write() functions. They are using the wrong addresses
for the RTCVALH and RTCVALL registers. That's why your program
doesn't work.

I will try to write some work-around code to replace the bad functions
but it will take some time and I can't post it until tomorrow at the earliest.
(And I don't work for CCS).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 12:01 am     Reply with quote

Here is a quick substitute function for the CCS built-in function.
I called it "my_rtc_read()". Try using it instead of the CCS function.
See if it works. Sample code is shown below. You should edit the
main() code a little to make it use your loop code with the LED.

Normally I spend some time and make a macro that can be substituted
for the CCS built-in function, and it has the same name as that function,
and it has almost identical ASM code. But I just don't have the time (or
the desire, because CCS will certainly fix this problem in the next
compiler version). I'll email CCS about the bug, unless you want to do it.
Code:

#include <18F27J53.h>

#define ADC=10

#FUSES NODEBUG
#FUSES NOXINST       
#FUSES NOPROTECT
#FUSES NOIESO
#FUSES NOCPUDIV           
#FUSES INTRC
#FUSES SOSC_HIGH
#FUSES RTCOSC_T1
#use delay(clock=8000000)


char bcd2bin(char bcd_value)
{
char temp;

temp = bcd_value;

// Shifting the upper digit right by 1 is
// the same as multiplying it by 8.
temp >>= 1;

// Isolate the bits for the upper digit.
temp &= 0x78;

// Now return: (Tens * 8) + (Tens * 2) + Ones
return(temp + (temp >> 2) + (bcd_value & 0x0f));

}


#byte RTCCFG  = 0xF3F
#byte RTCVALL = 0xF3A
#byte RTCVALH = 0xF3B
#bit RTCPTR0 = RTCCFG.0
#bit RTCPTR1 = RTCCFG.1


void my_rtc_read(rtc_time_t *data)
{
RTCPTR0 = 1;
RTCPTR1 = 1;

data->tm_year = bcd2bin(RTCVALL);
data->tm_yday = bcd2bin(RTCVALH);

data->tm_mday = bcd2bin(RTCVALL);
data->tm_mon  = bcd2bin(RTCVALH);

data->tm_hour = bcd2bin(RTCVALL);
data->tm_wday = bcd2bin(RTCVALH);

data->tm_sec  = bcd2bin(RTCVALL);
data->tm_min  = bcd2bin(RTCVALH);
}


//=====================================
void main()
{
rtc_time_t write_clock, read_clock;
   
setup_rtc(RTC_ENABLE, 0);

my_rtc_read(&read_clock);   

while(1);
}
Steffe



Joined: 03 May 2011
Posts: 6

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 3:35 am     Reply with quote

Hello PCM programmer
it Works! Jubiii ... Laughing
My USB test modified shows the seconds as well.
Great thanks for your professional and quick help and spending time for me on weekend.
So I'll send to CCS a bug report. I learned a little more ASM and register settings

thanx again

best

Steffe
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group