Hot!RTCC no increment PIC16F19186

Author
Riki89d
Starting Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2017/07/03 00:35:12
  • Location: 0
  • Status: offline
2018/01/08 05:59:33 (permalink)
0

RTCC no increment PIC16F19186

Hi everyone and happy new year btw :), i trying to program internal module RTCC of this PIC, but i don't get that SECONDS registers increment! It's like doens't work, why?¿ this is my code:
 

typedef struct t {
 int sec;
 int min;
 int hour;
 int mday;
 int mon;
 int year;
 int wday;
 int yday;
 int isdst;
} temps_RTCC;

temps_RTCC tempsConfig;
temps_RTCC visorTemps;

void main(void)
{

RTCWREN(= 1;
    RTCCONbits.RTCEN = 0;
    RTCCONbits.RTCCLKSEL = 0; //SOSC
    RTCCONbits.HALFSEC = 0;


       YEAR = 0x17; // year
        MONTH = 0x11; // month
        WEEKDAY = 0x05; // weekday
        DAY = 0x17; // day
        HOURS = 0x08; // hours
        MINUTES = 0x19; // minutes
        SECONDS = 0x44; // seconds
    
    ALRMCONbits.ALRMEN = 0;
    ALRMRPT = 0x00; // repetiotions
    ALRMMTH = 0x11; // month
    ALRMWD = 0x05; // weekday
    ALRMDAY = 0x17; // day
    ALRMHR = 0x08; // hours
    ALRMMIN = 0x19; // minutes
    ALRMSEC = 0x44; // seconds

    ALRMCONbits.ALRMEN = 1; // Re-enable the alarm

    ALRMCON = 0xA4;
    RTCCAL = 0x00; // calibration register
 
    RTCCONbits.RTCEN = 1;
    RTCWREN = 0;

    PIR8bits.RTCCIF = 0; // Clear the RTCC interrupt flag
    PIE8bits.RTCCIE = 1; //Enable RTCC interrupt

tempsConfig.hour = 0x00;
    tempsConfig.min = 0x00;
    tempsConfig.sec = 0x01;
    tempsConfig.mon = 0x01;
    tempsConfig.year = 0x18;
    tempsConfig.mday = 0x03;
    tempsConfig.isdst = 0x02;
    tempsConfig.yday = 0x02;

    RTCC_TimeSet(&tempsConfig); //Configuracio del temps

 while (1)
    {
        CLRWDT(); //No watchadog
        
        RTCC_TimeGet(&visorTemps);

        sendIntegerToLcd(0,2, visorTemps.sec);

     }
}

 
 
This code is from MCC, and i should display the increment seconds, but it doens't work
 
 
Thanks
#1

18 Replies Related Threads

    rodims
    Super Member
    • Total Posts : 1266
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: online
    Re: RTCC no increment PIC16F19186 2018/01/08 08:37:14 (permalink)
    0
    From your description "but i don't get that SECONDS registers increment!" I conclude that NOTHING increments, not only the seconds ?
     
    Do you have a 32 kHz crystal mounted and do you have SOSC enabled ?
    See chapter 26.4 of your FRM.
    You could also test Timer 0 with SOSC as input to see whether your problem is related to the RTC or the clock source.
    #2
    Riki89d
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2017/07/03 00:35:12
    • Location: 0
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/08 12:01:45 (permalink)
    0
    Thanks for answer, yes, i have mounted crystal 32 khz, and SOSC's enabled too, i've tried to toogle led on timer1 interrupt, clocked from SOSC, and LED look like fast blink, but i can see it perfectly blink.
    SECONDS register doesn't increment, and any register work.
    #3
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2412
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/10 15:30:12 (permalink)
    0
    You have to unlock the clock hardware.
    Write the time data and enable to start.
     
    I have some code in 16bit where you can see the clock hardware unlocked.
    .include "xc.inc"
    .include "UtilityLib2.inc"
    .global _setinternalclock
    .section utilitycode,code
    ;----------------------------------------------------
    .equ DT,    w0    ;DateTime_t *

    _setinternalclock:  ;void setinternalclock(DateTime_t *DT);  bcd
        mov     #0x55,w0
        mov     w0,NVMKEY
        mov     #0xAA,w0
        mov     w0,NVMKEY
        bset    RCFGCAL,#RTCWREN        ;Set RTCWREN bit
        bclr    RCFGCAL,#RTCEN
        mov     RCFGCAL,w0
        ior     #0x300,w0            ;all
        mov     w0,RCFGCAL
        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ;set date
        mov     [DT+DT_Year],w0        ;get year
        mov     w0,RTCVAL            ;set year
        mov     [DT+DT_DateMonth],w0    ;get date/month
        mov     w0,RTCVAL            ;set month/date
        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ;set time
        mov     [DT+DT_HourDay],w0        ;get hour/day
        mov     w0,RTCVAL            ;set hour/day
        mov     [DT+DT_SecondMinute],w0    ;get sec/min
        mov     w0,RTCVAL            ;set min/sec
        bset    RCFGCAL,#RTCEN
        bclr    RCFGCAL,#RTCWREN        ;Set RTCWREN bit
        return
    ;----------------------------------------------------
    .end

    Using this structure
    typedef struct{
        union{
            struct{
                unsigned char   Second;
                unsigned char   Minute;
            };
            unsigned int    SecondMinute;
        };
        union{
            struct{
                unsigned char   Hour;
                unsigned char   Day;
            };
            unsigned int    HourDay;
        };
        union{
            struct{
                union{
                    struct{
                        unsigned char   Date;
                        unsigned char   Month;
                    };
                    unsigned int    DateMonth;
                };
                unsigned int    Year;
            };
            unsigned long   TotalSeconds;
        };
    }DateTime_t;


    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #4
    Riki89d
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2017/07/03 00:35:12
    • Location: 0
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/11 01:15:51 (permalink)
    0
    but is not true for PIC16F... if i add:
     
    NVMCON2 = 0x55;
    NVMCON2 = 0xAA;
     
    it doesn't work still.
    #5
    qɥb
    Monolothic Member
    • Total Posts : 2510
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/11 02:18:40 (permalink)
    +1 (1)
    Which version of the compiler?
    Which mode (Free, Std, Pro ?)
    Did you check the assembly language that sequence produced?
     

    PicForum "it just works"
    #6
    Riki89d
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2017/07/03 00:35:12
    • Location: 0
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/11 02:37:28 (permalink)
    0
    Thanks for answer, my version is 1.42, free mode.
    I'm working C lenguage and i don't make anything in asm, but what I find in the
    assembly??
     
     
    #7
    Riki89d
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2017/07/03 00:35:12
    • Location: 0
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/11 02:40:52 (permalink)
    0
    I check the works of SOSC by configuring the TIMER1 and works, so the problem can are the SOSC not connecting with the RTCC.. but what is my mistake ??? thanks 
     
    #8
    qɥb
    Monolothic Member
    • Total Posts : 2510
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/11 02:55:07 (permalink)
    +1 (1)
    Riki89d
    Thanks for answer, my version is 1.42, free mode.
    I'm working C lenguage and i don't make anything in asm, but what I find in the
    assembly??

    XC8 compiles your C code into assembly language.
    You can see what it did in the .lst file it outputs, which will be where your hex file is.
     

    PicForum "it just works"
    #9
    qɥb
    Monolothic Member
    • Total Posts : 2510
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/11 03:01:55 (permalink)
    +1 (1)
    Riki89d
    but is not true for PIC16F... if i add:
     
    NVMCON2 = 0x55;
    NVMCON2 = 0xAA;
     
    it doesn't work still.

    As I suspected, that is a known problem in Free mode, that was fixed in XC8 version 1.44
    The current version is 1.45, so you should update.
    This is from the "Readme_XC8.htm" file that comes with v1.45

    Unruly unlock sequences (XC8E-101) Source code which performed unlocking of peripherals, such as EEPROM or PPLSOCK unlock sequences, were not output in strict accordance with the device data sheet, resulting in the correct registers being written but not with the correct timing. This occurred most commonly in Free mode. Optimization of such sequences are no longer performed, and C source which performs the sequence should work as expected.

     

    PicForum "it just works"
    #10
    Riki89d
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2017/07/03 00:35:12
    • Location: 0
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/11 03:21:06 (permalink)
    0
    I read datasheet, but in the RTCC Section, there is not anything about "must write tahat sequence" for use RTCC Registers.
    #11
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2412
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/11 05:00:33 (permalink)
    0
    RTCCON
    RTCWREN must be set first.  (write enable)
    RTCCONbits.RTCWREN = 1;
    Then you can set/clr RTCEN and all the other registers.
     
    Looking at the datasheet, no unlock sequence is required.
     
    You nearly had it:
    RTCWREN(= 1;
     
    RTCCONbits.RTCWREN = 1;   //unlock
    RTCCONbits.RTCEN = 0;       //disable
    Set the time
    RTCCONbits.RTCEN = 1;       //enable or a write to seconds will enable this
    RTCCONbits.RTCWREN = 0;  //lock
    Read back the time over a 10 second period to see if it is updating.
     
     
    post edited by Gort2015 - 2018/01/11 05:04:00

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #12
    mbrowning
    Just a Member
    • Total Posts : 912
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/11 05:19:54 (permalink)
    +1 (1)
    I checked some old RTC code for a pic18f66k22 and it required the unlock sequence to set RTCWREN, but you are correct that the pic16f19xxx datasheet does not mention such a requirement.
     
    You've enabled RTC interrupt, but don't show an ISR. Are you handling potential interrupts?
     
    RTCCONbits.HALFSEC = 0; is wasted effort. HALFSEC is read only.
     
    How are you determining that SECONDS isn't changing? Because your LCD doesn't change? I would want to look at the actual SECONDS register in the debugger. Perhaps there's a bug in the LCD code, or in the timeget function. or a bug in how you are using those MCC functions.
     
     

    Can't remember. I've slept since then - Mark
    #13
    davekw7x
    Entropy++
    • Total Posts : 1394
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/11 14:45:28 (permalink)
    +4 (4)
    Riki89d

        RTCCONbits.RTCEN = 1;
        RTCWREN = 0;



    I believe there is a hardware bug that prevents this from working.  When I put in a delay here (a little more than the tick of the clock), it works.  Otherwise: no go.  Note that, for this test I am using the internal clock (RTCCONbits.RTCCLKSEL = 0b01) since I wanted to make absolutely sure the problem was not related to SOSC or XTAL or anything else.


        printf("1: RTCCON = 0x%02X\n", RTCCON);
        RTCCONbits.RTCEN = 1;
        __delay_us(50);
        RTCWREN = 0;
        printf("2: RTCCON = 0x%02X\n", RTCCON);


    Results from my PIC16F19156 (same RTCC module as your chip), using XC8 version 1.44 (in Free mode):
    1: RTCCON = 0x21
    2: RTCCON = 0x81
    This shows that RTCEN (the msb) is set, and it starts counting.  (Taa-daa)
    For my test I just checked the seconds register in a loop and printed out the value when it changed from the previous reading.  (Of course, since my test is using the internal clock rather than a crystal, it's not accurate, but it does count.)
     
    On the other hand...
    When I comment out the delay, I get
    1: RTCCON = 0x21
    2: RTCCON = 0x01
    This shows that the RTCEN bit has not been set. (And it does not count.)

    Note that I have tested this enough to believe that it's not an artifact of printing; RTCEN really doesn't get set unless I put in a delay before clearing RTCWREN
     
    This delay seems to be necessary only after setting or clearing RTCEN immediately before clearing RTCWREN. I haven't seen any problems with other bits or other registers in the RTCC.

    Note that there is almost surely a similar sequence at the end of the RTCC_TimeSet() function, so, if you call that function it will probably end up with RTCEN not set.  For starters, why not comment out the call to RTCC_TimeSet() in your initialization code and see if it can get started?
     
    A quick test (instead of changing your initialization code and the code in RTCC_TimeSet() might to put something like the following after your initialization code:
     

        // Make dang sure it's enabled
        RTCCONbits.RTCWREN = 1;
        RTCCONbits.RTCEN = 1;
        // For now, leave RTCWREN set so that you can begin testing.



    I also suggest that if there are further difficulties, start with the internal oscillator so that we won't have to bother you again and again about SOSC, crystals, etc.

    If it works then you can dig a little deeper.

    Oh, and, by the way, I would also put off trying to use interrupts until you have the basic functionality underway.  We don't know what the heck you intend to do with the interrupt, and we can't see your ISR, so:

        //PIR8bits.RTCCIF = 0; // Clear the RTCC interrupt flag
        //PIE8bits.RTCCIE = 1; //Enable RTCC interrupt


    I will mention in passing that I looked at MCC version 3 to examine some of its functions, and it uses the tm structure from <time.h> instead of your temps_RTCC definitions.  Is there any reason you decided to roll your own, or did your MCC actually generate them?  I mean, my MCC's RTCC_SetTIme() and RTCC_GetTime() functions operate on pointers to struct tm
     
    Bottom line: It's hard to help someone debug by remote control (especially when part of their code "comes from MCC") since I can't see all of your code, but the thing about delaying after setting or clearing RTCEN before clearing RTCWREN seems to be a necessary first step.  At least that's my experience.
     

    Regards,

    Dave
    post edited by davekw7x - 2018/01/11 16:05:18

    Sometimes I just can't help myself...
    #14
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2412
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/11 16:47:09 (permalink)
    0
    I prefer an external rtc such as the Maxim Integrated DS3231 for accuracy over time.  Tuned xtal built in.
     
    Microchip make a nice rtc including built in eeprom and ram.
    MCP79410      1K eeprom and 64B sram.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #15
    Riki89d
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2017/07/03 00:35:12
    • Location: 0
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/12 01:50:47 (permalink)
    +1 (1)
    Thanks, problem has been fix! as say davekw7x, there is a bug in to hardware, RTCC require a delay intended increment time instruction of clock, otherwise, RTC doesn't enable.
    #16
    du00000001
    Just Some Member
    • Total Posts : 1797
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/12 02:24:36 (permalink)
    0
    Seems this HW bug should be documented in the Errata Sheets of ALL PICs implementing this RTCC module.
    Looks a bit as if RTCEN becoming effective (then readable) is synchonized to some RTCC-internal state.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #17
    davekw7x
    Entropy++
    • Total Posts : 1394
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/12 07:46:13 (permalink)
    0
    Riki89d
    Thanks, problem has been fix!

    I am glad you were able to get it going!

    I had submitted a ticket to Microchip along with a complete project that shows the problem and its software fix.  Past experience shows they don't update documentation/errata very quickly.
     
    I also put another item on the ticket that could affect some users:
    The description of the RTCCON Register (Register 24-1 in the Data Sheet) very carefully points out that RTCWENA must be set in order to change the value of RTCEN.  It does not indicate the same is true for the RTCCLKSEL bits, but, in fact they also can't be changed unless RTCWENA is set.  The changes to RTCCLKSEL are immediate, and do not require the synchronization delay necessary for RTCEN to take effect.
     
    Regards,
     
    Dave
     
     
     
    post edited by davekw7x - 2018/01/12 07:47:23

    Sometimes I just can't help myself...
    #18
    du00000001
    Just Some Member
    • Total Posts : 1797
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: RTCC no increment PIC16F19186 2018/01/12 11:49:51 (permalink)
    0
    Hi Dave,
    for all "settings" of the RTCC one would expect having to set the RTCWEN.
    For setting/clearing the RTCEN bit, this necessity is not expected (as many other EN/DIS work without such a mechanism). I guest this is the reason why they emphasize the necessity for RTCEN. 

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #19
    Jump to:
    © 2018 APG vNext Trial Version 4.5