MCP79410 good time keeping, No alarms?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232

    Default MCP79410 good time keeping, No alarms?

    Greetings!
    My project uses a 16F886 @8Mhz and a MCP79410 RTCC. I am pleased with the digital calibration and the unit is keeping very accurate time. HOWEVER, I have been working with the Alarms for several days and I’m getting nowhere! I have three identical boards and the RTCC acts the same on all boards. I must be missing something!

    MFP is tied to RB0 with pull up resistor and a button for manual interrupt with DT_INT’s. The button interrupt is working as expected.

    The ISR checks to see if ALM0IF or ALM1IF has been set, if NOT the interrupt was caused by button press. The OLED notifies upon interrupt which flag is set, if any.

    My major problem is that I can‘t get the darn thing to go into alarm state. I expect an interrupt if RTCC goes into alarm state, its not happening... No interrupt... No Alarm flag set. As I said all three board are working the same so it must be something in the setup I missed.
    PBP 2.60, PMASM
    Code:
           ; Clock set to 0000,  Alarm0 set,   MFP set to Hi in default position, goes low on interrupt
    Set_TimeDate:              
            rtcsec     = %10000000           ;top 4 bits ST&tens, bottom 4 bits ones   
            rtcmin     = %00000000   	;can be a Hex $ entry,                                        
            rtchour    = %00000000   	;bit6,12/24hr : bit5 pm/am : bit4=tens : bottom 4bits=ones             
            rtcday     = %00000001  	;oscon bit5 : Vbat bit4 :  Vbaten bit3 :  bit 2-0 day                                     
            rtcdate    = %00000000  	
            rtcmon     = %00000000  	 ;bits4 tens : bottom 4 bits ones                          
            rtcyear    = %00000000   	
            rtccon     = %10010000   	;[OUT][SQWE][ALM1][ALM0][EXTOCS][RS2][RS1][RE0]  CONTROL 
            rtccal     = %00000000   	;Calibration                    
            i2cwrite I2C_Dat, I2C_Clk, $DE,$00,[STR RTCbuffer\9] ' Write all 8 RTC reg
            Return 
    
                            
            ;Set Alarm0 for Lo on alarm interrupt, Alarm set to  Seconds match, Seconds set to 15
    Set_RTCC_Alarm0:
            Alrm0_sec    =  $0F       
            Alrm0_min    =  %00      
            Alrm0_hour   =  %00   
            Alrm0_day    =  %00    ;   [ALM0POL][ ALM0C2][ALM0C1][ALM0C0][  ALM0IF  ] [  DAY   ]  Addr 0Dh                                      
            Alrm0_date   =  %00    
            Alrm0_mon    =  %00     
            i2cwrite I2C_Dat, I2C_Clk, $DE,$0A,[STR Alrm0_buffer\6] 
           Return
    
             ;Set Alarm1 for Lo on alarm interrupt, Alarm set to  Seconds match, Seconds set to 15   
    Set_RTCC_Alarm1:
            Alrm1_sec   =  $0F       
            Alrm1_min   =  %00      
            Alrm1_hour  =  %00    
            Alrm1_day   =  %00    ;   [ALM1POL][ ALM1C2][ALM1C1][ALM1C0][  ALM1IF  ] [  DAY   ]  Addr 14h                             
            Alrm1_date  =  %00    
            Alrm1_mon   =  %00     
            i2cwrite I2C_Dat, I2C_Clk, $DE,$11,[STR Alrm1_buffer\6] 
            Return
    OLED display posts a constant update of the clock. If I push the INT button, OLED post BIN value of Alrm0_day and Alrm1_day. This tells me if ALM0IF and ALM1IF is clear or set. Following my interpretation of the datasheet almost everything else is working as expected. Calibration works well, PWM on MFP works well, EEProm works well in Page Write and Byte Read, and ID is cool.

    PBP I2C command doesn’ like the EEProm Random Read or Current Address Read. I guess some bit banging will be required. SRAM wants to give me back only seven bits instead of eight; what’s with that?
    Any comments or direction will be appreciated!

    Wayne

  2. #2
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Re: MCP79410 good time keeping, No alarms?

    update:
    My testing shows that both my MCP7940 and MCP79410 will not alarm interrupt on seconds only.

    When I setup Alarms to match on Min. the flags will set on both Alarms, however Alarm0 will not interrupt. Alarm1 will not clear flag with the same command structure used to clear flag Alarm0. Where’s my DS1307?

  3. #3
    Join Date
    Mar 2013
    Location
    Leicestershire - England
    Posts
    4


    Did you find this post helpful? Yes | No

    Cool Re: MCP79410 good time keeping, No alarms?

    Hi MOUNTAIN747, I am just starting to attempt to communicate with this RTC. Could you possibly share any more code for this project . Many thanks perkoperkins

  4. #4
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Re: MCP79410 good time keeping, No alarms?

    Hi perkoperkins, what are you having problems with? I can dig out several code blocks to assist you if you can tell me what you are trying to do. In the code from the first post the i2cwrite communication is all you need to talk to the RTCC to set the time.

    Wayne

  5. #5
    Join Date
    Mar 2013
    Location
    Leicestershire - England
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: MCP79410 good time keeping, No alarms?

    Hi Wayne , Thanks for your promt reply !!.

    Hardware Used -
    Pic Used = PIC16F876A - 4MHZ External Xtal - SDA Port RC.4 - SCL Port RC.3 - Output ( Currently LCD ) but want to use a 4x7segment display. Using PBP 2.60.

    I have uploaded what code I have so far, If you could pick out any errors for me that would be great. I'm fairly new to PBP and
    this is the first time I have tried i2c. when i run this code the time and date is set but if i set ClkSec = %10000000 to start
    the oscilator My seconds display 80 and start to count up . I read on Microchips Application note AN1491

    (http://ww1.microchip.com/downloads/e...tes/01491A.pdf)
    " The recommended practice is to load the Time and Date registers from 0x01 through 0x06 and then load the Seconds register 0x00 with the ST (oscillator Start bit set, enabling the oscillator)."


    When I try this though I get the wrong setting returned on the LCD. Is my method for converting the BCD to DEC correct ?

    One more question sorry ! When the i2cread is read, do the variables need manually updating ie

    RtcSec = (ClkBuffer[0])
    RtcMin = (ClkBuffer[1])
    Rtchour = (ClkBuffer[2])

    etc
    etc

    Thankyou for taking the time to answer my questions , any help or code examples would be great. Can't find much code on
    the net , other than for C.

    Thanks Tim


    MyRTC4Forum.bas


    ( I'm hoping my code has appeared above if not ill try again )

  6. #6
    Join Date
    Mar 2013
    Location
    Leicestershire - England
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: MCP79410 good time keeping, No alarms?

    Ill Try again - Hopefully will work this time

    Code:
    ' ________________________ Chip Setup ___________________________ 
                                                     
    @ __config _XT_OSC & _WDT_OFF & _LVP_OFF & _CPD_OFF & _DEBUG_OFF            
                                                                                                                                      
    ' ___________________ Definitions & LCD Definitions _____________ 
                                                              
    DEFINE OSC 4            ' Tell PBP using a 4 MHZ Crystal
    DEFINE I2C_HOLD 1       ' 
    define LCD_DREG PORTB   ' Declare data bus port 
    define LCD_DBIT 0       ' Declare data bus starting address 
    define LCD_RSREG PORTC  ' Declare Register Select
    define LCD_RSBIT 7      ' port and bit
    define LCD_EREG PORTC   ' Declare Enable port and bit
    define LCD_EBIT 6       ' Declare Enabit bit
    define LCD_BITS 4       ' Declare no. of Bits
    define LCD_LINES 2      ' Declare no. of lines 
                             
    ' _________________________ Variables ______________________________
    
      BCDsecs   var  byte   '
      BCDmins   var  byte   '
      BCDHours  var  byte   ' Conversion Variables
      BCDday    var  byte   ' 
      BCDdate   var  byte   '
      BCDmon    var  byte   '
      BCDyear   var  byte   '
      
    ' ______________________ Clock Variables ___________________________
    
      ClkSec    var byte '$00   ' Seconds Register       
      ClkMin    var byte '$01   ' Minutes Register      
      ClkHour   var byte '$02   '   Hours Register             
      ClkDay    var byte '$03   '    Days Register                                  
      ClkDate   var byte '$04   '    Date Register                  
      ClkMonth  var byte '$05   '   Month Register                              
      ClkYear   var byte '$06   '    Year Register
      ClkCont   var byte '$07   '          Control
      ClkCal    var byte '$08   '      Calibration
      ClkBuffer var byte[9]     '      Time Buffer 
    
    ' ______________________ Alarm0 Variables ___________________________
    
      Alm0Secs  var byte '$0A   ' Seconds Register       
      Alm0Mins  var byte '$0B   ' Minutes Register      
      Alm0Hour  var byte '$0C   '   Hours Register             
      Alm0Day   var byte '$0D   '    Days Register                                  
      Alm0Date  var byte '$0E   '    Date Register                  
      Alm0Month var byte '$0F   '   Month Register                              
      Alm0Buff var byte[6]
    ' ______________________ Alarm0 Variables ___________________________
     
      Alm1Secs  var byte '$11   ' Seconds Register       
      Alm1Mins  var byte '$12   ' Minutes Register      
      Alm1Hour  var byte '$13   '   Hours Register             
      Alm1Day   var byte '$14   '    Days Register                                  
      Alm1Date  var byte '$15   '    Date Register                  
      Alm1Month var byte '$16   '   Month Register
      Alm1Buff var byte[6]  
     
    ' _____________________ Pin Definitions _________________________ 
                                                                               
      SDA var PORTC.4     ' Serial Data Pin RC.4    ( pin )                    
      SCL var PORTC.3     ' Serial Data Pin RC.3    ( pin )    
      SetButt  var PORTB.0     '
      UpButt   var PORTB.1
      DownButt var PORTB.1
    
    ' ____________________ Inital time setup ________________________
     
      ClkSec   = %10000000;$00     
      ClkMin   = $00    
      ClkHour  = $00        
      ClkDay   = $01                               
      ClkDate  = $17               
      ClkMonth = $10                           
      ClkYear  = $78
      ClkCont  = %10000000;$00
      clkcal   = $00
    
    ' _______________________ Main Program __________________________
     
    '
    pause 500
                   ' Allow LCD to Wake Up !
    gosub settime
    
    goto Main
        
    Main :
        gosub gettime
        gosub disptime
        goto main
        end
        
    
    ' _________________________ Subrountines ________________________
    
    
    SetTime :   ;$DE = write
        i2cwrite sda, scl, $DE,$00,[str clkbuffer\9]
        'i2cwrite sda, scl, $DE,$00,[clksec,clkmin,clkhour,clkday,clkdate,clkmonth,clkyear,clkcont,clkcal]
        'i2cwrite sda, scl, $DE,$00,[clksec]
        return
        
    GetTime :    ;$DF = read 11011111
        i2cread sda, scl, $DF,$00,[str clkbuffer\9]   
        'i2cread sda, scl, $DF,$00,[clksec,clkmin,clkhour,clkday,clkdate,clkmonth,clkyear]     
            
           bcdsecs  = (clksec>>4*10)  + (clksec & %00001111)      ; convert BCD to Decemal ??
           bcdmins  = (clkmin>>4*10)  + (clkmin & %00001111)      ;
           bcdhours = (clkhour>>4*10) + (clkhour & %00001111)     ;
           BCDday   = (clkday>>4*10) + (clkday & %00001111)       ;
           bcddate  = (clkdate>>4*10) + (clkdate & %00001111)     ;
           bcdmon   = (clkmonth>>4*10)+ (clkmonth & %00001111)    ;
           bcdyear  = (clkyear>>4*10) + (clkyear & %00001111)     ;
           
        return
    
    DispTime :
    
        lcdout $FE,1,dec bcdhours,":",dec bcdmins,":",dec bcdsecs         
        lcdout $FE,$c0,dec bcddate,"/",dec bcdmon,"/",dec bcdyear
        pause 100
     
    '    lcdout $FE,1,dec clkhour,":",dec clkmin,":",dec clksec            
    '    lcdout $FE,$c0," ",dec clkdate,"/",dec clkmonth,"/",dec clkyear
    '    pause 100
     
     
     
        return

  7. #7
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Re: MCP79410 good time keeping, No alarms?

    Perkoperkins, sorry for the delay but in summer months I don’t work with PBP on a daily basses. I’ve looked over your BCD to DEC and I have some points to cover.

    (clkday>>4*10) Look at the data sheet. Reg 03h day, this is a good example. You are shifting right then multiplying OSCON and VBAT by 10. Reg 03h will only require (clkday & %00001111). Check all your registers to insure your calculations only include relevant data.

    Seconds register can be used to enable or disable the oscillator at any time. I load all registers with one pass of the programmer then use a second pass of the programmer to load seconds register only to sink time with the PC as best I can. Without writing a VB program to pull time from the PC I haven’t found a better way to set the clock.
    The way your var’s are set up, yes, I think you need to update variable on each new pass of GetTime however this is not necessary if you change some variable structure. Look at some of Darrel Taylor’s links on this subject. The commented second line in GetTime will update, but Darrel’s is a technique you should try. External Modifiers
    Darrel also explains using external modifiers which I think is a good practice. This will update your variables when you use GetTime and use the first line for i2cread.
    Code:
                   ClkBuffer var byte [9]
    ASM
    ClkSec 	var  byte  =  _ClkBuffer
    ClkMin    var  byte  =  _ClkBuffer  + 1
    ClkHour   var  byte  =  _ClkBuffer  + 2
    ClkDay    var  byte  =  _ClkBuffer  + 3
    ….
    ….
    END ASM
            ClkSec   var   byte  ext
            ClkMin   var   byte  ext
            ClkHour  var   byte  ext
            ClkDay   var   byte  ext
    …
    …
    I'll look over some more of your program when I have time.
    Wayne

  8. #8
    Join Date
    Mar 2013
    Location
    Leicestershire - England
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: MCP79410 good time keeping, No alarms?

    Thanks wayne much apreciated !!!!
    Tim

Similar Threads

  1. Mcp79410 rtcc
    By keymuu in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th July 2012, 04:36
  2. May be it is good idea
    By hardcore in forum PBP Wish List
    Replies: 2
    Last Post: - 16th March 2010, 01:09
  3. Alarms with Mel's "Olympic Timer" based timer - how to?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 20th June 2007, 22:09
  4. Problem Keeping PORTD.1 LOW
    By koossa in forum mel PIC BASIC Pro
    Replies: 48
    Last Post: - 9th September 2005, 08:51
  5. DS1307 multiple alarms
    By jrt4fun in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th August 2004, 21:49

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts