Wake-up from Sleep Mode by Comparator interrupt for 30F2020

General discussion on mikroPascal for dsPIC30/33 and PIC24.
Post Reply
Author
Message
ionic
Posts: 1
Joined: 05 Aug 2009 07:54

Wake-up from Sleep Mode by Comparator interrupt for 30F2020

#1 Post by ionic » 05 Aug 2009 08:16

I'm trying to use comparator CMP1A (RB0) interrupt to wake-up sleep mode. When analog input voltage of RB0 is higher than AVDD/4(1.25V), comparator module will generate an interrupt to wake-up the system from Sleep mode. And I set RB7 for testing the interrupt: if interrupt is happened, RB7 is set to high and LED will be turned on; if not, RB7 is set to low.
After my testing, LED is not on, that is, interrupt is not happed. I don't know where the error of my code is.

Thanks

Ionic

Here is my code:

Code: Select all

int main( void )
{
ADPCFG = 0xfff0;
TRISBbits.TRISB7 = 0;
LATBbits.LATB7 = 0; // for testing interrupt
Init_CMP1();
while(1)
{
Sleep()
}
}

void Init_CMP1(void)
{
IPC7bits.AC1IP = 7;
IEC1bits.AC1IE = 1; 

CMPCON1bits.INSEL = 0;    // CMP1A:RB0
CMPCON1bits.EXTREF = 0;  //Interal Ref 
CMPCON1bits.RANGE = 1;   //AVDD/2
CMPCON1bits.CMPPOL= 0;  //non inverted
CMPDAC1 = 0x01FF;           //Ref=AVDD/4=1.25V;
CMPCON1bits.CMPON = 1;   /* CMP1 enabled */
}

void _ISR _CMP1Interrupt(void)
{
LATBbits.LATB7 = 1;            // if interrupt is happened, RB7 is set to 1
IEC1bits.AC1IE = 0;            // turn off interrupt enable

IFS1bits.AC1IF = 0;
}
Sorry, I type wrong number, AC1IE in Init_CMP1 should be 1.
But the problem still exits.
Last edited by ionic on 05 Aug 2009 09:45, edited 1 time in total.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

#2 Post by jpc » 05 Aug 2009 09:10

minor detail, this is Pascal section, regarding your problem, where do you enable this interrupt ? i only see IEC1bits.ACIE = 0 !
Au royaume des aveugles, les borgnes sont rois.

Post Reply

Return to “mikroPascal for dsPIC30/33 and PIC24 General”