2016-05-28 22 views
0

PIC24F32KA302がスリープモードに移行し、RTC割り込みによってウェイクアップするように設定します。しかし、起床後、私のプログラムは最初からやり直しています。 - 割込みの割当て優先度が現在のCPU優先度以下である場合、スリープモードを開始したPWRSAV命令に続く命令からデバイスがウェイクアップしてコード実行を継続します。 - 割り込みソースの割り当てられた優先度レベルが現在のCPU優先度より大きい場合、デバイスはウェイクアップし、CPU例外処理が開始されます。コード実行は、ISRの最初の命令から継続されます。 両方の設定を試しましたが、結果は同じです。 私のコードは、以下である:PIC24F32KA302スリープモード

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;} 

関数SYS_Init()、RTC、およびその他の周辺モジュール割り込み初期化します。この機能は、デバイスがスリープモードから起動すると常に実行されます。 私に何か考えてもらえますか?ありがとうございます

答えて

0

デバイスをリセットさせる原因となるエラーが発生する可能性があります。

トラップルーチンを追加しましたか?そうでない場合は、このコードを追加して、そのトラップに入るかどうかを確認してください。

また、回路に電力低下がなく、リセットピンに何らかのノイズがないことを確認してください。リセットピンとGNDの間に100nFのコンデンサを追加できます(もちろんプルアップを維持してください) 。

/******************************************************************************/ 
/* Files to 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 for debugging trap code may be 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 are additional traps in the 24E family. Refer to the PIC24E 
migration guide. There are no Alternate Vectors in the 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 simply ensure that the device continuously loops  */ 
/* within each routine. Users who actually experience one of these traps  */ 
/* can add code to handle the error. Some basic examples for trap code,  */ 
/* including assembly routines that process trap sources, are available at */ 
/* www.microchip.com/codeexamples            */ 
/******************************************************************************/ 

/* Primary (non-alternate) address error trap function declarations */ 
void __attribute__((interrupt,no_auto_psv)) _OscillatorFail(void) 
{ 
     INTCON1bits.OSCFAIL = 0;  /* Clear the trap flag */ 
     while(1); 
} 

void __attribute__((interrupt,no_auto_psv)) _AddressError(void) 
{ 
     INTCON1bits.ADDRERR = 0;  /* Clear the trap flag */ 
     while (1); 
} 
void __attribute__((interrupt,no_auto_psv)) _StackError(void) 
{ 
     INTCON1bits.STKERR = 0;   /* Clear the trap flag */ 
     while (1); 
} 

void __attribute__((interrupt,no_auto_psv)) _MathError(void) 
{ 
     INTCON1bits.MATHERR = 0;  /* Clear the 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 the trap flag */ 
     while (1); 
} 

void __attribute__((interrupt,no_auto_psv)) _AltAddressError(void) 
{ 
     INTCON1bits.ADDRERR = 0;  /* Clear the trap flag */ 
     while (1); 
} 

void __attribute__((interrupt,no_auto_psv)) _AltStackError(void) 
{ 
     INTCON1bits.STKERR = 0;   /* Clear the trap flag */ 
     while (1); 
} 

void __attribute__((interrupt,no_auto_psv)) _AltMathError(void) 
{ 
     INTCON1bits.MATHERR = 0;  /* Clear the trap flag */ 
     while (1); 
} 

#endif 

/******************************************************************************/ 
/* Default Interrupt Handler             */ 
/*                   */ 
/* This executes when an interrupt occurs for an interrupt source with an  */ 
/* improperly defined or undefined interrupt handling routine.    */ 
/******************************************************************************/ 
void __attribute__((interrupt,no_auto_psv)) _DefaultInterrupt(void) 
{ 
     while(1); 
} 

#if defined(__PIC24E__) 

/* These traps are new to the PIC24E family. Refer to the device Interrupt 
chapter of the FRM to 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 
関連する問題