View previous topic :: View next topic |
Author |
Message |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
Is #INT_COMP broken? |
Posted: Mon May 24, 2010 5:12 pm |
|
|
In the recent versions ex v4.106 say using 18F2620 or 18F8720 the interrupt does not to work when volts on F6 cross 3.6v ( f4 is tied to GND)
I did a search on #INT_COMP and if I have it right there maybe an issue.
Code: | #include <18F8720.h>
#fuses HS,NOPROTECT,NOPUT,NOBROWNOUT,NOLVP,NOWDT
//////////////
#device *=16
#device adc=10
#use delay(clock=8MHZ,restart_wdt)
////// ////////////////////////////////////////////////////////////////
/// RS232 interface using hardware
/// this will be interrupt driven using a circular buffer
//#use rs232(STREAM=WPS, baud=9600, xmit=PIN_C6,rcv=PIN_C7,ERRORS)
////// ////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
//////////////////////////// debugging //////////////////////////////
////////////////////////////////////////////////////////////////////
#use rs232(debugger) ///// debug printf to monitor/////////////////
int8 safe_conditions=TRUE;
int8 compare_reg;
#byte CMCON= 0x0fb4
#INT_COMP
void isr()
{
compare_reg=CMCON; ////// must read to clear flag
if(c1OUT==1) safe_conditions=TRUE;
else safe_conditions=FALSE;
}
void main()
{
printf("\r\n comparator test...\r\n\n");
output_high(PIN_h1);
setup_comparator( F6_VR_F4_VR);
setup_vref(VREF_HIGH|15); //// 5v vdd this is 3.6v
/// two lines below are uncommented when testing interrupt
// enable_interrupts(INT_COMP);
// enable_interrupts(GLOBAL);
while(TRUE)
{
///// code below doesn't work when the /* */ pair is removed
/*
if(safe_conditions==true)
{
output_high(PIN_H1);
}
else
{
output_low(PIN_H1);
}
safe_conditions=TRUE;
*/
///// code below works but is not interrupt driven
if(c1OUT==1)
{
output_high(PIN_H1);
}
else
{
output_low(PIN_H1);
}
delay_ms(500);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 24, 2010 8:09 pm |
|
|
Quote: | In the recent versions ex v4.106
|
Can you post an earlier version of the compiler that runs your program
(with interrupts enabled) and is guaranteed to work ? If you can, then
I can compile the program with that version and with vs. 4.106.
Then I can compare the .LST files with ExamDiff and it wll instantly
highlight any differences. |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Tue May 25, 2010 12:31 am |
|
|
In the main routine this statement should not be there
Code: | safe_conditions=TRUE; |
In the isr
Code: | compare_reg=CMCON; ////// must read to clear flag |
the above statement isn't necessary since flag is cleared by compiler
#INT_COMP is working and never was broken it was my code that was at fault
PCM programmer thanks for the offer of assistance |
|
|
|