Hi All
I hope someone can help me here. I've tried Microchip, but maybe I'm
not explaining things well enough. I have a board which has a
32.768KHz crystal directly connected to the SOSCI/SOSCO pins on the
dsPIC. After setting up the configuration bits correctly, for running
internal FRC w/PLL, I wrote the program below, using some bits from
Microchip demos, and programmed the device, but I cannot get it to
call the ISR when the watch crystal activates the SOSCI pin. I have
made it that it turns on a relay when in the routine, and off when
back in the main loop. I can get it to go into the interrupt routine
when I use the internal oscillator as the timer device, but not the
external crystal.
I have tried every example I can find, even code direct to me from
microchip tech support but nothing works, yet all other aspects of the
chip work perfectly, I have tcp/ip / USB / SD MMC all running of the
chip, all I need is a RTC. All pointers, sugesstion, etc. would be
great. I have other code, which I can post if needed, but the code
below would be the best for myself to get working. Excuse bad coding,
but I'm new to PIC.
TIA for all help
Russ
; CODE BEGINS
.include "p33FJ256GP506.inc"
.global __reset
.global __T1Interrupt
.global _wreg_init
.global _timer_init
.global _enSecOsc
.section .text
; The following code example will enable Timer1 interrupts,
; load the Timer1 Period register and start Timer1.
; When a Timer1 period match interrupt occurs, the interrupt
; service routine must clear the Timer1 interrupt status flag
; in software.
__reset:
MOV #__SP_init, W15 ;Initalize the Stack Pointer
MOV #__SPLIM_init, W0 ;Initialize the Stack Pointer Limit
Register
MOV W0, SPLIM
NOP ;Add NOP to follow SPLIM initialization
; Setup relay for testing interrupt
BCLR TRISF,#TRISF4
BCLR LATF,#LATF4
CALL _wreg_init ;Call _wreg_init subroutine
CALL _timer_init ;Timer initialization, and Port setup
CALL _enSecOsc ; Enable secondary oscillator
done:
BSET LATF,#LATF4 ; Turn off relay
BRA done ;Place holder for last line of executed
code
;..............................................................................
;Subroutine: Initialization of W registers to 0x0000
;..............................................................................
_wreg_init:
CLR W0
MOV W0, W14
REPEAT #12
MOV W0, [++W14]
CLR W14
RETURN
;..............................................................................
; Timer Initialization
;..............................................................................
_timer_init:
CLR T1CON ; Stops the Timer1 and reset control reg.
CLR TMR1 ; Clear contents of the timer register
MOV #0x8000, w0 ; Load the Period register, -=12/04/03 RW:
changed from 0xFFFF=-
MOV w0, PR1 ; with the value 0x8000 - 32768
BCLR T1CON, #TCKPS0 ; Load Prescaler
BCLR T1CON, #TCKPS1 ; with 00 = 1:1
BSET IPC0, #T1IP0 ; Setup Timer1 interrupt for
BCLR IPC0, #T1IP1 ; desired priority level
BCLR IPC0, #T1IP2 ; (this example assigns level 1 priority)
BCLR IFS0, #T1IF ; Clear the Timer1 interrupt status flag
BSET IEC0, #T1IE ; Enable Timer1 interrupts
BSET T1CON, #TCS ; External Clock Source
BSET T1CON, #TON ; Start Timer1
RETURN
;..............................................................................
; Enable secondary oscillator
;..............................................................................
_enSecOsc:
;OSCCONL(Low byte) Unlock Sequence
MOV #OSCCONL, w1
MOV.b #0x02, w0
MOV #0x46, w2
MOV #0x57, w3
MOV.b w2, [w1]
MOV.b w3, [w1]
MOV.b w0, [w1] ; Enable Sec Osc
RETURN
;..............................................................................
; Example code for Timer1 ISR
;..............................................................................
__T1Interrupt:
PUSH.D W4
BCLR LATF,#LATF4 ; TURN ON RELAY
BCLR IFS0, #T1IF ; Reset Timer1 interrupt flag
POP.D W4
RETFIE ; Return from ISR
.end
; CODE ENDS
RTC on dsPIC33F
Started by ●April 13, 2007
Reply by ●April 13, 20072007-04-13
fatbald1 wrote:> > I hope someone can help me here. I've tried Microchip, but maybe > I'm not explaining things well enough. I have a board which has > a 32.768KHz crystal directly connected to the SOSCI/SOSCO pins on > the dsPIC. After setting up the configuration bits correctly, > for running internal FRC w/PLL, I wrote the program below, using > some bits from Microchip demos, and programmed the device, but I > cannot get it to call the ISR when the watch crystal activates > the SOSCI pin. I have made it that it turns on a relay when in > the routine, and off when back in the main loop. I can get it to > go into the interrupt routine when I use the internal oscillator > as the timer device, but not the external crystal. > > I have tried every example I can find, even code direct to me > from microchip tech support but nothing works, yet all other > aspects of the chip work perfectly, I have tcp/ip / USB / SD MMC > all running of the chip, all I need is a RTC. All pointers, > sugesstion, etc. would be great. I have other code, which I can > post if needed, but the code below would be the best for myself > to get working. Excuse bad coding, but I'm new to PIC. > > ; CODE BEGINS > > .include "p33FJ256GP506.inc" > > .global __reset > .global __T1Interrupt > > .global _wreg_init > .global _timer_init > .global _enSecOsc > > .section .text > > ; The following code example will enable Timer1 interrupts, > ; load the Timer1 Period register and start Timer1. > ; When a Timer1 period match interrupt occurs, the interrupt > ; service routine must clear the Timer1 interrupt status flag > ; in software. > > __reset: > MOV #__SP_init, W15 ;Initalize the Stack Pointer > MOV #__SPLIM_init, W0 ;Initialize the Stack Pointer Limit > Register > MOV W0, SPLIM > NOP ;Add NOP to follow SPLIM initialization > > ; Setup relay for testing interrupt > BCLR TRISF,#TRISF4 > BCLR LATF,#LATF4 > > CALL _wreg_init ;Call _wreg_init subroutine > CALL _timer_init ;Timer initialization, and Port setup > CALL _enSecOsc ; Enable secondary oscillator > > done: > BSET LATF,#LATF4 ; Turn off relay > BRA done ;Place holder for last line of executed > code > > ;.............................................................................. > ;Subroutine: Initialization of W registers to 0x0000 > ;.............................................................................. > > _wreg_init: > CLR W0 > MOV W0, W14 > REPEAT #12 > MOV W0, [++W14] > CLR W14 > RETURN > > ;.............................................................................. > ; Timer Initialization > ;.............................................................................. > > _timer_init: > CLR T1CON ; Stops the Timer1 and reset control reg. > CLR TMR1 ; Clear contents of the timer register > > MOV #0x8000, w0 ; Load the Period register, -=12/04/03 RW: > changed from 0xFFFF=- > MOV w0, PR1 ; with the value 0x8000 - 32768 > > BCLR T1CON, #TCKPS0 ; Load Prescaler > BCLR T1CON, #TCKPS1 ; with 00 = 1:1 > > BSET IPC0, #T1IP0 ; Setup Timer1 interrupt for > BCLR IPC0, #T1IP1 ; desired priority level > BCLR IPC0, #T1IP2 ; (this example assigns level 1 priority) > BCLR IFS0, #T1IF ; Clear the Timer1 interrupt status flag > BSET IEC0, #T1IE ; Enable Timer1 interrupts > > BSET T1CON, #TCS ; External Clock Source > BSET T1CON, #TON ; Start Timer1 > > RETURN > > ;.............................................................................. > ; Enable secondary oscillator > ;.............................................................................. > _enSecOsc: > ;OSCCONL(Low byte) Unlock Sequence > MOV #OSCCONL, w1 > MOV.b #0x02, w0 > MOV #0x46, w2 > MOV #0x57, w3 > MOV.b w2, [w1] > MOV.b w3, [w1] > MOV.b w0, [w1] ; Enable Sec Osc > RETURN > > ;.............................................................................. > ; Example code for Timer1 ISR > ;.............................................................................. > > __T1Interrupt: > PUSH.D W4 > BCLR LATF,#LATF4 ; TURN ON RELAY > BCLR IFS0, #T1IF ; Reset Timer1 interrupt flag > POP.D W4 > RETFIE ; Return from ISR > > .end > > ; CODE ENDSAFAICS there is no loop anywhere to repeat the test. However if the BRA done is the actual loop, there is no time for the relay to close. -- <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt> <http://www.securityfocus.com/columnists/423> <http://www.aaxnet.com/editor/edit043.html> "A man who is right every time is not likely to do very much." -- Francis Crick, co-discover of DNA "There is nothing more amazing than stupidity in action." -- Thomas Matthews -- Posted via a free Usenet account from http://www.teranews.com
Reply by ●April 16, 20072007-04-16
CBFalconer wrote:> > AFAICS there is no loop anywhere to repeat the test. However if > the BRA done is the actual loop, there is no time for the relay to > close. >Sorry I forgot to include the delay loop in the timer ISR. I used this to hold the relay while I check with the scope, just incase the debugger was missing the breakpoint within the routine, you never know. Thanks for your reply.
Reply by ●April 20, 20072007-04-20







