Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIC32 low voltage interrupt
20-05-2012, 12:34 AM, (This post was last modified: 20-05-2012, 04:03 PM by KiloOne.)
#1
PIC32 low voltage interrupt
Another interrupt need for the MICRO.

I would like to generate an interrupt when a voltage I am reading on C2IN- falls below a reference voltage set on the 'Comparator Voltage Reference' CVREF+.

I believe I set CM2CON = 0x8090;

I think this sets comparator 2 up as:

Bit 15 is 1 so it is ON
Bits 7-6 are 10 for creating an Interrupt on High to low transition comparator output
Bit 4 is 1 so that CVREF+ is high side of comparator
Bits 1-2 are 00 so C2IN- is low side of comparator

I hope I can generate this interrupt internally but I am unsure of how to do it.

Any help with the interrupt code would again be really appreciated. Smile

Thanks,
Dale
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
20-05-2012, 04:04 PM,
#2
RE: PIC32 low voltage interrupt
Ugh Confused low level interrupt stuff.
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply
20-05-2012, 05:33 PM, (This post was last modified: 20-05-2012, 06:37 PM by KiloOne.)
#3
RE: PIC32 low voltage interrupt
And, I think that to set up the CVR I do:

CVRCON = 0x801F;

Bit 15 is 1 so CVR is ON
Bit 4 is on so source is VREF+
Bits 3-0 are 1111 so value is 2.37v

And then I set up the CMP2 interrupts:

IEC1CLR = 0x000000010; // disable CMP2 interrupt
IPC7SET = 0x00070000; // Set CMP2 interrupt sub priority
IFS1CLR = 0x000000010; // Clear the CMP2 interrupt flag
IEC1SET = 0x000000010; // Enable CMP2 interrupt

So in the main datasheet I found:

CMP2 – Comparator Interrupt IRQ=36 Vector Number=30 IFS1<4> IEC1<4> IPC7<20:18> IPC7<17:16>

And this code works Big Grin
Code:
void ISR_wrapper_vector_30(void) __attribute__ ((section (".vector_30")));    // from PIC32 datasheet vector flag is 30 for CMP2
// ISR_wrapper will call the CMP2Interrupt()
void ISR_wrapper_vector_30(void) { CMP2Interrupt(); }
// CMP2Interrupt() is declared as an interrupt routine
void CMP2Interrupt(void) __attribute__ ((interrupt));
void CMP2Interrupt(void) {             // CMP2 interrupt treatment
    CDC.printf("Yeah\r\n");
    IFS1CLR = 0x00000010; // Clear the CMP2 interrupt flag
}

Dale
PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)