• AVR Freaks
Reply to post

MCP7940 Alarm Unusable

Page: 12 > Showing page 1 of 2
Author
rbuck
Super Member
  • Total Posts : 345
  • Reward points : 0
  • Joined: 2005/04/28 12:48:11
  • Location: Phoenix, AZ
  • Status: offline
2015/07/26 10:15:18 (permalink)
0

MCP7940 Alarm Unusable

Has anyone been successful in using the alarm functions of the MCP7940?

i just want to use it as a simple alarm clock. Just set the alarm hours and minutes to repeat each day. Apparently you can't do that with any of Microchip's RTC chips.
 
I have tested with fake code to set the seconds, minutes, hours, date, month, year, and day of week. But that doesn't result in the alarm triggering.
 
Why should you have to set the month, year, date, and day of week just to set an alarm? And why should you have to write code to track all this even if the alarm did work as described? If I set the alarm for 5am at 10pm tonight, I should not have to track and modify all the date settings at midnight tonight.
 
I can't believe they are selling any of these parts.
 
 

21 Replies Related Threads

    JChristensen
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2014/04/10 16:30:04
    • Location: 0
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 11:16:52 (permalink)
    4 (1)
    rbuck
    Has anyone been successful in using the alarm functions of the MCP7940?

     
    Yes, absolutely.

     
    Why should you have to set the month, year, date, and day of week just to set an alarm?

     
    Because that's the most general case; month, day, year, hour, minute, second are required to define a point in time. Not everyone wants to repeat an alarm every 24 hours. But it's easy enough to do, when the alarm triggers, just note the current time, add 24 hours, and reset the alarm with that value.
     
     
    I can't believe they are selling any of these parts.

     
    Other RTCs that I'm familiar with aren't that much different in this respect. Still, it can sometimes be helpful to read the datasheet before buying in the event that a part just doesn't fit your requirements. Let us know when you bring an improved RTC to market.
    rbuck
    Super Member
    • Total Posts : 345
    • Reward points : 0
    • Joined: 2005/04/28 12:48:11
    • Location: Phoenix, AZ
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 12:19:32 (permalink)
    0
    JChristensen,
     
    If you have gotten it to work, please tell me how to set it so I can have the alarm trigger.
     
    Today is 7/25/2015. Suppose I want it to alarm at 13:05:00. What mask would I use for that? I have tried mask 111 ALM0MSK<2:0>. I have set seconds, minutes, hours, day of week, date. The data sheet shows Alarm0 memory as occupying 0x0A to 0x10. Nowhere do they tell what 0x10 is used for.
     
    I understand setting the month, year, date, day of week for the clock. I can understand it being an option for the alarm. But to make it a requirement for the alarm doesn't make sense. I can add 24 hours to the alarm setting when it triggers. But, what if the day rolls over from 31 to 1? I am now in a different month so my alarm setting is no longer valid. So I also have to write code to handle that.
     
    Not everyone wants to repeat an alarm every 24 hours.
    I work Monday through Friday. The alarm goes off at 5am each day. On Friday night I turn the alarm off. On Sunday night I turn the alarm back on. I dare say this is what 99% of alarm clocks are used for.
     
     
    Let us know when you bring an improved RTC to market
      I have found a drop in replacement. The TI Mr1T81S has a bit you set to tell the alarm to repeat every day. That seems like an improved part.
     
     
    Again, if you can tell me the mask to set to make Alarm0 trigger at a specific hour, min, and sec., please post the mask seting and I will try that.
    JChristensen
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2014/04/10 16:30:04
    • Location: 0
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 13:13:15 (permalink)
    3 (1)
    rbuck
    Today is 7/25/2015. Suppose I want it to alarm at 13:05:00. What mask would I use for that? I have tried mask 111 ALM0MSK<2:0>. I have set seconds, minutes, hours, day of week, date. The data sheet shows Alarm0 memory as occupying 0x0A to 0x10. Nowhere do they tell what 0x10 is used for.

     
    First, exactly which part are you using?  There is no MCP7940.  MCP7940M? MCP7940N? MCP79400?

    That alarm mask sounds right.  It would also be helpful to know what platform you're writing code on.  I usually use a 32-bit integer for the time, expressed as seconds since Jan 1, 1970, like Unix time (time_t). So 7/25/2015 13:05:00 UTC becomes 1437829500. It's also useful to use a tm structure, which has a member for each part of the time, i.e. day, month, year, hour, minute, second. Finally, it's necessary to be able to convert between the two formats.
     
    My datasheets show 0x10 as being reserved.
     

    I understand setting the month, year, date, day of week for the clock. I can understand it being an option for the alarm. But to make it a requirement for the alarm doesn't make sense. I can add 24 hours to the alarm setting when it triggers. But, what if the day rolls over from 31 to 1? I am now in a different month so my alarm setting is no longer valid. So I also have to write code to handle that.

     
    It makes sense because that's the most general case for defining an instant in time. If you want something less than general, then write a function to apply whatever simplifying assumptions you want to make.
     
    When using the 32-bit integer form of the time, adding 24 hours is simply a matter of adding 86,400 seconds. Rollovers of the day or any other part are therefore moot.
     
    I work Monday through Friday. The alarm goes off at 5am each day. On Friday night I turn the alarm off. On Sunday night I turn the alarm back on. I dare say this is what 99% of alarm clocks are used for.

     
    99% of alarm clocks possibly, but RTCs are used for a lot of things other than alarm clocks, so their "alarm" functions need to be as general as possible.
     
    I wrote a Arduino library for the MCP7941X parts that handles alarms as well as pretty much all other functionality, maybe have a look at that:
     
    JChristensen
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2014/04/10 16:30:04
    • Location: 0
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 13:17:55 (permalink)
    0
    Looks like the forum edited out the link to my Arduino library.
    Go to github (dot) com (slash) JChristensen (slash) MCP79412RTC
    ric
    Super Member
    • Total Posts : 22688
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: MCP7940 Alarm Unusable 2015/07/26 13:40:29 (permalink)

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    rbuck
    Super Member
    • Total Posts : 345
    • Reward points : 0
    • Joined: 2005/04/28 12:48:11
    • Location: Phoenix, AZ
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 14:09:15 (permalink)
    0
    Ric,
     
    That link appears to be down.
     
    Ray
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 14:37:05 (permalink)
    0
    Mmmm no, it's ok here...

    GENOVA :D :D ! GODO
    JChristensen
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2014/04/10 16:30:04
    • Location: 0
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 15:28:35 (permalink)
    0
    @ric, thanks for posting the link and also for the workaround tip.
    rbuck
    Super Member
    • Total Posts : 345
    • Reward points : 0
    • Joined: 2005/04/28 12:48:11
    • Location: Phoenix, AZ
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 15:39:42 (permalink)
    3 (1)
    Yes, link is working now. That is a different part. Also, I notice the code for setting the alarm is passing in a value to set the year for the alarm. According to the data sheet, there is no setting for the alarm year.
     
    Since it is not possible to have the MCP9410 trigger on a seconds, minutes, hour match, I wrote code to trigger on a hours and minutes match.
     
    I first set the RTC to trigger on an hours match. When that happens, I set a flag to indicate the hours has triggered. I then send a command to the RTC to tell it to trigger on a minutes match. Once that happens, I set a variable to the current hour. I then send the command 0x71 to ALM0WKDAY. Since the alarm will not trigger on that command the way it should, I don't have to worry about repeated triggering.
     
    Now each second when I come through back the loop, I read the RTC to see what the hour is. Until the hour rolls over to the next hour, I do not change ALM0WKDAY. Once the hour rolls over, I send the command to the RTC to tell it to trigger on the hour. It should retrigger on the same hour tomorrow. I will know 23 hours from now if it does.
     
    In the meantime, I am going to order the TI chip and see if it behaves the way the data sheet says it does. If so, it will be a much cleaner solution than hacking my code to get around the MCP9410 short comings.
    JChristensen
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2014/04/10 16:30:04
    • Location: 0
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 16:46:14 (permalink)
    0
    rbuck
    Yes, link is working now. That is a different part. Also, I notice the code for setting the alarm is passing in a value to set the year for the alarm. According to the data sheet, there is no setting for the alarm year.
     
    Since it is not possible to have the MCP9410 trigger on a seconds, minutes, hour match, I wrote code to trigger on a hours and minutes match.

     
    Would you please carefully type in the part number that we're discussing here, there is no MCP9410, either.
     
    My code will work fine with with MCP79410, 11, or 12. It should also work with MCP79401, 02, 03 as they lack only the 1kb EEPROM. MCP7940M lacks battery backup, MCP7940M and N lack power-fail time stamping and unique ID. I haven't tried my library with the simpler devices, but the memory maps look the same except for the features not implemented. As long as a person didn't call a function for a feature that doesn't exist on a particular device, I'd be inclined to think it would work.
     

    I first set the RTC to trigger on an hours match. When that happens, I set a flag to indicate the hours has triggered. I then send a command to the RTC to tell it to trigger on a minutes match. Once that happens, I set a variable to the current hour. I then send the command 0x71 to ALM0WKDAY. Since the alarm will not trigger on that command the way it should, I don't have to worry about repeated triggering.
     
    Now each second when I come through back the loop, I read the RTC to see what the hour is. Until the hour rolls over to the next hour, I do not change ALM0WKDAY. Once the hour rolls over, I send the command to the RTC to tell it to trigger on the hour. It should retrigger on the same hour tomorrow. I will know 23 hours from now if it does.

     
    That certainly seems like a hard way to go about it.
     

    In the meantime, I am going to order the TI chip and see if it behaves the way the data sheet says it does. If so, it will be a much cleaner solution than hacking my code to get around the MCP9410 short comings.



    I'm not familiar with that chip, but I'll have to check it out.  Let us know how it works out.
    rbuck
    Super Member
    • Total Posts : 345
    • Reward points : 0
    • Joined: 2005/04/28 12:48:11
    • Location: Phoenix, AZ
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 17:27:07 (permalink)
    0
    Sorry for the typo. I am using MCP7940N part. Register 03 contains the power fail bit and the battery enable bit. I have a battery backup on board so I could check that bit but I have no need to. I just reset that bit to 0 each time I update the RTC. I have no need for the unique ID.
     
    That certainly seems like a hard way to go about it.
    I agree. If the part worked properly I wouldn't have to do it that way.
     
     
    I am using a PIC16F1719 and XC8 compiler. I am using epoch time in my time functions for the LCD. The GPS module sends the time in UTC. Using epoch time, time structure, and the builtin XC8 time functions it was easy to convert from UTC to local time. XC8 has builtin functions to convert between epoch time and UTC.
     
    The only reason I put the RTC on the board was for the alarm features. The GPS module provides updated time each second to the LCD. And I don't have to worry about time drift. I plan on updating the RTC every 6 hours with GPS time just to make sure the alarm time doesn't drift too much.
     
    Apparently others have had the same issue:
    http:slash slashwww.microchip.comslash forums slash m709531.aspx
    post edited by rbuck - 2015/07/26 17:32:59
    JChristensen
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2014/04/10 16:30:04
    • Location: 0
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 18:09:57 (permalink)
    0
    I have to believe that the part is working as advertised, and that you are misinterpreting something or looking for a feature that doesn't exist.  It is true that these RTCs do not have a feature that raises an alarm at some given (but arbitrary) time every day.
     
    In order to generate an alarm every 24 hours at the same time, I would:
    (1) Set ALMxMSK<2:0> to B111 (alarm will trigger when second, minute, day of week, date and month match).
    (2) Create a variable alarmTime and set it equal to current epoch time.
    (3) Break alarmTime into a tm struct. Set the struct hour, minute and second to the desired alarm time.
    (4) Convert the struct back into the alarmTime variable.
    (5) If alarmTime is less than the current time, add 24 hours to it.
    (6) Break alarmTime into the struct (again).
    (7) Using the struct members, set all six of the alarm registers (sec, min, hour, wkday, date, month).
    (8) When the alarm triggers, add 24 hours to the alarmTime variable, repeat (6) and (7), clear the RTC's alarm flag, then continue with alarm processing.
     
    I should create an example for my library since this question does arise from time to time.  Not sure if that would be terribly helpful to you though, since you're using a different platform/toolchain.
     
    rbuck
    Super Member
    • Total Posts : 345
    • Reward points : 0
    • Joined: 2005/04/28 12:48:11
    • Location: Phoenix, AZ
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 18:40:20 (permalink)
    0
    (1) Set ALMxMSK to B111 (alarm will trigger when second, minute, day of week, date and month match).

     
    That is the entire problem. If I could get the alarm to trigger when those all matched, I could handle the rest of the steps.  I have even tried setting day of week, date, and month all to 1 in the timekeeping and the alarm registers but the alarm still does not trigger. It will trigger with masks of 000, 001, and 010 when the correct second, minute, or hour is reached.
     
    I have tested setting the timekeeping values and the alarm values in debug mode. I then wait 10 seconds and read those values back from the RTC. They are all correct as I set them except for the timekeeping seconds value. It has incremented by 10 seconds.
     
    I don't know what I could be missing. It seems like a simple process to me.
    JChristensen
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2014/04/10 16:30:04
    • Location: 0
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/26 19:42:36 (permalink)
    0
    Huh. Not sure what to think. MCP79411 and MCP79412 work fine for me. If I had an MCP7940N I could test it easily enough.
    rbuck
    Super Member
    • Total Posts : 345
    • Reward points : 0
    • Joined: 2005/04/28 12:48:11
    • Location: Phoenix, AZ
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/27 17:30:32 (permalink)
    4 (2)
    JChristensen and all,
     
    Egg on my face bigtime!!!
     
    Turns out it was my mistake that was keeping the alarm from working. In my code to send the date to the RTC I had this for the date:
    dt = dt + dt + dt_unit;
    It should have been:
    dt=dt + dt_unit;
     
    dt already contained the dt tens digit and was shifted left by 4. So for date 26 I was adding 2 (high nibble) + 2 (high nibble) + 6 (low nibble). This resulted in a value of 0x46 which was an invalid date. So the date was being set to 0x06 in the RTC. When I was looking at values returned from the RTC yesterday, I wasn't looking at the date. I assumed (and we all know what that means) it was correct since I was pulling it from the data that was being sent to the LCD screen. When I added the code today to check the month, date, and year of the RTC in debug mode, I immediately saw the problem. The alarm is now working with a mask of 111.
     
    Pressed Enter too soon. I wasn't through with the post.
     
    There is still the issue of having to make it repeat each day. When the alarm triggers I could add 86400 seconds to the current alarm time to move it to the next day. But if the user had the alarm turned off, it would not trigger. If they had it turned off for several days, the calculations become complex. If the date happened to cross an end of month, the calculations are even more complex.
     
    I am going to handle it in hardware. Once the alarm times are setup, I will let it run continuously. When the alarm triggers I will add the 86400 seconds to move it to the next day. When the user turns the alarm off, I will not allow the PIC pin that is appying voltage to the alarm buzzer to outout the voltage.
     
    I also noticed I had the wrong part number for the other alarm chip I mentioned. It is actually a ST M41T81S.
    post edited by rbuck - 2015/07/27 17:41:20
    JChristensen
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2014/04/10 16:30:04
    • Location: 0
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/07/28 04:22:37 (permalink)
    3 (1)
    Glad you got it working! No worries about the egg, it's happened to most of us at least once ;-)
     
    The ST part is interesting, I like the integrated crystal option and the fact that it has 1/100 second resolution. But it also lacks some features that I like in the Microchip parts.  Hard to be all things to all people, eh.
     
    Reading ST AN1216, "The TIMEKEEPER® and serial real-time clock (RTC) devices provide an alarm which can be set either for a given time and day, or to repeat at a certain day in every month, or at a certain hour in every day, or at a certain minute of every hour, or at a certain second of every minute."
     
    That sounds like it could be set to alarm at 0600 every day, but I'm not sure that it could be set to (for example) 0645 every day, which would be similar if not identical to the Microchip RTCs.  OTOH, Maxim's RTC (e.g. DS3231) can alarm when hours and minutes match, or when hours, minutes and seconds match.  I like the Maxim temperature-compensated RTCs, but they're expensive.  With calibration in a reasonably temperature-controlled environment, I've found the Microchip RTCs can be nearly as accurate and they do have a rich feature set.
     
    Best regards and good luck with your project.
    anand
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2009/08/04 06:20:34
    • Location: 0
    • Status: offline
    Re: MCP7940 Alarm Unusable 2015/10/06 08:16:05 (permalink)
    0
    Hi @rbuck, 
    I know this is an old thread.... but I was just going through them to look if I could find an answer to my particular problem... and couldn't resist the temptation of contributing my two cents worth.
    I am using the exact same part ... MCP 7940N although I am not using it for alarms... just time keeping. 
    However here is my suggestion for your particular need.... Since there are two alarm registers you could program Alarm0 to give you an alarm every day of the week (mask 011)..so you start with Wkday = 1 and  then increment it when the alarm occurs and reload the said register. This will give you the repeat ability you desire... The second alarm register... i.e. Alarm1 would need to be programmed with the hours minutes and seconds registers. So for example the user wants an alarm every day to repeat at 5:55AM then set the Alarm 1 registers to 5:55:00 AM. 
    The mask for Alarm0 is set for Day of the Week match, whereas the Alarm1 is set to give you first an hour match. when that alarm has triggered .. you change the mask to give you a minutes match. 
    This appears to solve the problem if the user wanted to just set an alarm for everyday .. at the exact same time... It wouldn't work however if the user was trying to set a reminder for his wife's birthday... for that you would have to set the mask to all 1s. 
    Cheers!
    Anand 
    p.s: to increment the day of the week perhaps the following code might work:( wkday is a variable that stores the day of the week.
    ....
    ....
    wkday++;
    wkday &= 0x7;
    if(!wkday)
    {
         wkday ++;
    }
    ...
    ..
     
     
    abusername
    New Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2016/09/05 20:43:14
    • Location: 0
    • Status: offline
    Re: MCP7940 Alarm Unusable 2016/11/03 22:47:52 (permalink)
    0
    I know this is a really old thread (and I stand a good chance of not receiving a reply), but this is sort of related to a problem I am having with an MCP7940N.
     
    According to the datasheet, if *both* ALM0 and ALM1 are set (EN bits set), alarm flags clear (IF bits zero) and the ALMPOL is clear (zero), then the MFP pin will only trigger when *BOTH* alarms match. As far as I can determine, that is not happening.
     
    eg: Setup alarm#0 [0x0D] : alarm polarity (0), trigger on seconds (000), cleared interrupt flag (0), don't care weekdays (001) //set weekday to 1 because 0 is invalid
    Setup alarm#1 [0x14] : polarity is ignored (0), trigger on minutes (001), cleared interrupt flag (0), don't care weekdays (001)
    Set time for alarm #0 to (example) 25 seconds [0x0A] (all other alarm registers untouched)
    Set time for alarm #1 to (example) 3 minutes [0x11] (all other alarm registers untouched)
    Setup the control register [0x07] : enable both alarm #0 and alarm #1, the other bits are not required (00110000)
     
    The datasheet says this should alarm (MFP should go low) at xx:03:25
    However, it alarms at xx:03:00 (and at no other time).
     
    If I use either alarm separately, they work as expected (as the datasheet says).
     
    Has anyone else encountered this problem with the MCP7940N chips?
    js590
    Starting Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2016/03/19 02:15:48
    • Location: 0
    • Status: offline
    Re: MCP7940 Alarm Unusable 2016/12/20 08:39:55 (permalink)
    3 (1)
    I wish to post a suggestion for Microchip.
     
    It appears that using the feature to hit an alarm every day is quite common....
    So, why not implement/add it in one of the two reserved "alarm masks" (Hours, minutes and seconds)??
    It will improve the chip without affecting all other options... and I think is relatively simple to add.
    This change will also simplify programmer's life when a daily alarm is required!
    JUST A SUGGESTION, of course! LoL: LoL
    I think this RTC chip is among the best ones I have tried.
     
    BTW: I have another suggestion for the "Digital Trimming" feature. That's a great feature. However I don't understand what the COARSE TRIM MODE is for. It too much invasive! Why don't make it less frequent?
    Instead of 128Hz make it act at 1Hz. This way you could use less precise crystal and have a way to trim it anyway.
    It should be the next scale for trimming if the first one (CRSTRIM = 0) isn't sufficient.
     
    Page: 12 > Showing page 1 of 2
    Guest
    Quick Reply: (Open Full Version)
      Enter the random characters shown
    Submit Post
    Some restrictions apply to prevent link (URL) Spam.
    URLs in messages, signatures, and PM's are removed unless you have ...
    • been a member for at least 0 day(s);
    • made a total of 0 post(s);
    • earned at least 0 point(s) for post scores (based on the ratings on your posts);
    • earned at least 0 reward point(s);
    Jump to:
    © 2019 APG vNext Commercial Version 4.5