RTCC problem in Dspic33fj128gp802

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Alastur
Posts: 6
Joined: 16 Apr 2010 16:00

RTCC problem in Dspic33fj128gp802

#1 Post by Alastur » 22 Mar 2012 12:22

Hi all,

I've been using external RTCC clocks via i2C during years in my 18f pics, but now i wanted to use the internal RTCC of the dspic33fj128gp802 with 18pF capacitors and 32.768 hz secondary xtal.

I've tested several source codes with RTCC interrupts and Timer1 interrupts, but with erratic results . Do you have a sample code or library to use the internal RTCC of this 33fj128gp802 or similar with good results?

Thanks in advance

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: RTCC problem in Dspic33fj128gp802

#2 Post by janko.kaljevic » 23 Mar 2012 11:45

Hello,

At the moment we do not have example with internal RTCC module for your controller.
But maybe some other has and is willing to post it here.

Or you can try to write it and we will help you if you encounter any issue.

Best regards.

Alastur
Posts: 6
Joined: 16 Apr 2010 16:00

Re: RTCC problem in Dspic33fj128gp802

#3 Post by Alastur » 30 Mar 2012 12:42

Here is part of my source code,i 've tested with the use of the Timer1 interrupt too, but not good results in the output of the variable MIN_SECONDS and not output of the rtcc interrupt, looks like not working



....
.....





sub procedure Rtccinit()



//Unlocking sequence

NVMKEY=0X55
NVMKEY=0XAA
RCFGCAL.RTCWREN = 1 'se rtcwren bit
RCFGCAL.RTCEN=0 'disable el RTCC

PADCFG1.RTSECSEL=1 'seconds clock is selected for the RTCC pin


' Enable the RTCC interrupt*/

IFS3.RTCIF = 0 ' //clear the RTCC interrupt flag
IEC3.RTCIE = 1 ' //enable the RTCC interrupt


RCFGCAL.RTCOE = 1 ' //enable RTCC output

'Load the initial values to the RTCC value registers*/
RCFGCAL=RCFGCAL OR 0X300 ' set RTCPTR with 11
RTCVAL=0X0007 ' set year
RTCVAL=0X1028 'set month and day
RTCVAL=0X0110 ' set day of week and hour
RTCVAL=0X0808 'set minutes and seconds

RCFGCAL.RTCEN=1 ' ; enable RTCC, Set RTCEN bit
RCFGCAL.RTCWREN=0 ' Clear RTCWREN bit

end sub


sub procedure RtccRead()

' Wait for RTCSYNC bit to become ‘0’
'**********************************************
while(RCFGCAL.RTCSYNC=1) NOP WEND

'**********************************************
' Read RTCC timekeeping register
'**********************************************
RCFGCAL=RCFGCAL OR 0X0300 ' SET 11 IN RTCPTR
ANYO=RTCVAL
MES_FECHA=RTCVAL
WDAY_HORA=RTCVAL
MIN_SECONDS=RTCVAL

end sub

sub procedure INTERRUPCION_RTCC() iv IVT_ADDR_RTCCINTERRUPT
IFS3.RTCIF = 0
RtccRead()' ' // read the date and time registers.
ESTADO= ESTADO XOR 1
PORTB.5= ESTADO ' // this interrupt looks like not working



main:
' Main program

.....
.....
....


' PLL with xtal de 10MHZ, M=32, N1=2, N2=2 total 80Mhz, means 40MIPS
CLKDIV.0=0 CLKDIV.1=0 CLKDIV.2=0 CLKDIV.3=0 CLKDIV.4=0 'set N1 with 2
PLLFBD=30 '30 ' M VALE 32 vamos con el cristal del 10 Mhz
CLKDIV.6=0 CLKDIV.7=0 'SET N2 WITH 2

'Disable Watch Dog Timer
RCON.SWDTEN=0 ' RCONNbits.SWDTEN=0;

while OSCCON.5 =0 NOP WEND
OSCCON.LPOSCEN=1 'ENABLE el lposcen // Enable the 32.768kHz Secondary oscillator
OSCCONL=02
IPC15.0=1
IPC15.1=1
IPC15.2=1
IFS3.RTCIF = 0 ' //clear the RTCC interrupt flag
IEC3.RTCIE = 1 ' //enable the RTCC interrupt
RCFGCAL.RTCOE = 1 ' //enable RTCC output
RCFGCAL.RTSECSEL=1 ' //BY SECONDS

RtccInit()'


' //Unlocking Sequence required for external oscilator and to unlock OSCCON register.
asm
' ; Unlocking Assembly language code.
MOV #0x742, w1 ;note memory address of OSSCONL address
MOV.B #0x02, w0
MOV #0x46, w2
MOV #0x57, w3
MOV.B w2, [w1]
MOV.B w3, [w1]
MOV.b w0, [w1]
END ASM


...


WHILE TRUE
RtccRead()
WordToStr(MIN_SECONDS, txt) ' i can't obtain precise seconds
wend


end.

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”