microcontroller - PIC24F32KA302 Sleep mode -
i want configure pic24f32ka302 go sleep mode , wake rtc interrupt. however, after waking up, program runs again beginning. datasheet mentions that: - if assigned priority interrupt less or equal current cpu priority, device wake-up , continue code execution instruction following pwrsav instruction initiated sleep mode. - if assigned priority level interrupt source greater current cpu priority, device wake-up , cpu exception process begin. code execution continue first instruction of isr. tried both configurations results same. code below:
int main(void) { sys_init(); while(1){ __delay_ms(400); sleep(); } return 0;} void __attribute__ ( (interrupt, no_auto_psv) ) _rtccinterrupt(void) { ifs3bits.rtcif = 0; //to do: total_pulse += tmr1; tmr1 = 0; led = ~led;} void interruptpriority_init(void) { intcon1bits.nstdis = 1; intcon2bits.altivt = 0; srbits.ipl = 1; ipc15bits.rtcip = 6;//6 _u2rxip = 5; _t1ip = 4; _u1rxip = 2; _hlvdip = 3;}
the function sys_init() initializes interrupt, rtc , other peripheral modules. function runs after device wakes sleep mode. have idea or advice me? thank you
it sort of errors happening causing device reset.
did add trap routines ? if not, add code , see if 1 of trap.
also make sure don't have power drop in circuit , reset pin not getting sort of noise, can add 100nf capacitor between reset pin , gnd (of course keeping pullup).
/******************************************************************************/ /* files include */ /******************************************************************************/ /* device header file */ #if defined(__xc16__) #include <xc.h> #elif defined(__c30__) #if defined(__pic24e__) #include <p24exxxx.h> #elif defined (__pic24f__)||defined (__pic24fk__) #include <p24fxxxx.h> #elif defined(__pic24h__) #include <p24hxxxx.h> #endif #endif #include <stdint.h> /* includes uint16_t definition */ #include <stdbool.h> /* includes true/false definition */ /******************************************************************************/ /* trap function prototypes */ /******************************************************************************/ /* <other function prototypes debugging trap code may inserted here> */ /* use if intcon2 altivt=1 */ void __attribute__((interrupt,no_auto_psv)) _oscillatorfail(void); void __attribute__((interrupt,no_auto_psv)) _addresserror(void); void __attribute__((interrupt,no_auto_psv)) _stackerror(void); void __attribute__((interrupt,no_auto_psv)) _matherror(void); #if defined(__pic24f__)||defined(__pic24h__) /* use if intcon2 altivt=0 */ void __attribute__((interrupt,no_auto_psv)) _altoscillatorfail(void); void __attribute__((interrupt,no_auto_psv)) _altaddresserror(void); void __attribute__((interrupt,no_auto_psv)) _altstackerror(void); void __attribute__((interrupt,no_auto_psv)) _altmatherror(void); #endif /* default interrupt handler */ void __attribute__((interrupt,no_auto_psv)) _defaultinterrupt(void); #if defined(__pic24e__) /* these additional traps in 24e family. refer pic24e migration guide. there no alternate vectors in 24e family. */ void __attribute__((interrupt,no_auto_psv)) _hardtraperror(void); void __attribute__((interrupt,no_auto_psv)) _dmacerror(void); void __attribute__((interrupt,no_auto_psv)) _softtraperror(void); #endif /******************************************************************************/ /* trap handling */ /* */ /* these trap routines ensure device continuously loops */ /* within each routine. users experience 1 of these traps */ /* can add code handle error. basic examples trap code, */ /* including assembly routines process trap sources, available @ */ /* www.microchip.com/codeexamples */ /******************************************************************************/ /* primary (non-alternate) address error trap function declarations */ void __attribute__((interrupt,no_auto_psv)) _oscillatorfail(void) { intcon1bits.oscfail = 0; /* clear trap flag */ while(1); } void __attribute__((interrupt,no_auto_psv)) _addresserror(void) { intcon1bits.addrerr = 0; /* clear trap flag */ while (1); } void __attribute__((interrupt,no_auto_psv)) _stackerror(void) { intcon1bits.stkerr = 0; /* clear trap flag */ while (1); } void __attribute__((interrupt,no_auto_psv)) _matherror(void) { intcon1bits.matherr = 0; /* clear trap flag */ while (1); } #if defined(__pic24f__)||defined(__pic24h__) /* alternate address error trap function declarations */ void __attribute__((interrupt,no_auto_psv)) _altoscillatorfail(void) { intcon1bits.oscfail = 0; /* clear trap flag */ while (1); } void __attribute__((interrupt,no_auto_psv)) _altaddresserror(void) { intcon1bits.addrerr = 0; /* clear trap flag */ while (1); } void __attribute__((interrupt,no_auto_psv)) _altstackerror(void) { intcon1bits.stkerr = 0; /* clear trap flag */ while (1); } void __attribute__((interrupt,no_auto_psv)) _altmatherror(void) { intcon1bits.matherr = 0; /* clear trap flag */ while (1); } #endif /******************************************************************************/ /* default interrupt handler */ /* */ /* executes when interrupt occurs interrupt source */ /* improperly defined or undefined interrupt handling routine. */ /******************************************************************************/ void __attribute__((interrupt,no_auto_psv)) _defaultinterrupt(void) { while(1); } #if defined(__pic24e__) /* these traps new pic24e family. refer device interrupt chapter of frm understand trap priority. */ void __attribute__((interrupt,no_auto_psv)) _hardtraperror(void) { while(1); } void __attribute__((interrupt,no_auto_psv)) _dmacerror(void) { while(1); } void __attribute__((interrupt,no_auto_psv)) _softtraperror(void) { while(1); } #endif
Comments
Post a Comment