This question is about understanding the functionality of RTCC alarm registers within one PIC family. While I am using 16LF19176, I believe this question relates to all RTCC modules in this family. I also should mention that I am maintaining someone else's code, I did not originally write it.
I am using the RTCC clock and it works properly. I have set up an alarm, giving me an interrupt, properly as expected, every 10 minutes.
The issue comes, when I want to change it to alarm every hour. I am sure it is my problem not understanding the documentation (which is quite short for this by the way).
I am first showing the working code for alarm every 10 minutes:
ALRMMTH = 0x1; // month ALRMWD = 0x2; // weekday // @todo: why is it 0x02? ALRMDAY = 0x1; // day ALRMHR = 0x0; // hours ALRMMIN = 0x09; // minutes ALRMSEC = 0x5A; // seconds (it did not work with errata recommended 0x0A) ALRMCON = 0x40 | (0x04<<2) // repeat indefinitely, alarm every 10 minutes ALRMCONbits.ALRMEN = 1;
I wanted to change that for an alarm every hour. I assumed that just changing two lines of code would do it, but it doesn't:
ALRMHR = 0x01; // hours ALRMMIN = 0x00; // minutes
QUESTION 1: what to write into ALRMxx register(s) for an alarm every hour?
QUESTION 2: why is the weekday set to 0x02, or what does that do?
QUESTION 3: can someone clarify, why is it not a conflict of interest setting an alarm numbers versus telling how often the alarm happens in ALRMCON?
Thank you very much for your time!
UPDATE: I changed the code to @Paul's idea, but still did not wake after 1 hour (I am hoping to wake every whole hour, that is at xx:00:00). I did this code change:
ALRMCONbits.ALRMEN = 0; ALRMRPT = 0xFF; // In order for alarm be 'sounding' repetitively, not just 255 times, remember to set the CHIME bit to '1' (in ALRMCON below). ALRMMTH = 0x01; // month (probably this line does in my case nothing) ALRMWD = 0x02; // weekday (probably this line does in my case nothing) ALRMDAY = 0x01; // day (probably this line does in my case nothing) ALRMHR = 0x00; // hours (probably this line does in my case nothing) ALRMMIN = 0x00; // minutes // was 0x09 originally and woke every x10:00 minutes (10, 20, 30, ...) ALRMSEC = 0x00; // seconds // I have a feeling I should return here my original 0x5A, which worked for every-10-min alarm ALRMCON = 0x40 | (0x05<<2); ALRMCONbits.ALRMEN = 1
UPDATE 2: See my answer, it looks like the Microchip Errata is wrong as well. The seconds alarm register must be set to a weird value of 0x5A in order to get an alarm at :00 seconds