CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Comparator is not working with PIC16F882

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kongfu1



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

Comparator is not working with PIC16F882
PostPosted: Wed Jul 13, 2011 3:51 pm     Reply with quote

PIC16F882
CCS:4.122

Analog pulse is about every 20 ms and 3.75V
Reference voltage is set about 2.19V

Problem:
1. INT_COMP was never triggered
2. C1OUT pin has no signal output at all

Here is a simple testing code:
Code:

#include <16F882.h>
#use delay(clock=4M, crystal)

#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NOCPD,DEBUG

#INT_COMP
void Comp_int(void)
{
   IR_Idle_Timer = sys_min;
   output_toggle(PIN_A0);
}
void main (void)
{

   enable_interrupts(INT_COMP);
   enable_interrupts(GLOBAL);
   setup_comparator(CP1_A1_VREF|CP1_OUT_ON_A4);
   setup_vref(VREF_HIGH | 6);

   while(1)
   {
      delay_ms(100);
        output_toggle(PIN_C4);   
   }
   
}


Please help. Thanks.
Howard
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 13, 2011 4:18 pm     Reply with quote

Before we start, I notice you have the DEBUG fuse set. The MPLAB Help
file for the ICD2 debugger says this:
Quote:

PIC16F887 Limitations
PIC16F887, PIC16F886, PIC16F884, PIC16F883, PIC16F882

You cannot single step through an interrupt.

Due to hardware restrictions the debugger/emulator cannot jump to the interrupt vector memory location in single step or animate mode.

Are you trying to single step or animate through the #int_comp interrupt ?

How are you testing the program ? How do you know it's failing ?
kongfu1



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

PostPosted: Wed Jul 13, 2011 4:26 pm     Reply with quote

PCM programmer wrote:
Before we start, I notice you have the DEBUG fuse set. The MPLAB Help
file for the ICD2 debugger says this:
Quote:

PIC16F887 Limitations
PIC16F887, PIC16F886, PIC16F884, PIC16F883, PIC16F882

You cannot single step through an interrupt.

Due to hardware restrictions the debugger/emulator cannot jump to the interrupt vector memory location in single step or animate mode.

Are you trying to single step or animate through the #int_comp interrupt ?

How are you testing the program ? How do you know it's failing ?


Yes. That was another question about the debug. PICKIT3 was used for debug and is what Microchip suggested with this PIC. As you already pointed out this PIC is not working with ICD2 and maybe it is not working with PICKIT3 neither.

I was using a scope to monitor C1OUT pin (RA4) and input signal on RA1 pin. Input signal is in normal range (>3.75V) but RA4 has nothing.

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 13, 2011 4:34 pm     Reply with quote

The help file for Pickit 3 says the same thing.

Try and run it in Release mode. Remove the Debug fuse and select
Release in the drop-down box at the top of the MPLAB window.
Re-compile and program and run it.
kongfu1



Joined: 26 Apr 2010
Posts: 56

View user's profile Send private message

PostPosted: Wed Jul 13, 2011 4:59 pm     Reply with quote

PCM programmer wrote:
The help file for Pickit 3 says the same thing.

Try and run it in Release mode. Remove the Debug fuse and select
Release in the drop-down box at the top of the MPLAB window.
Re-compile and program and run it.


PCM,

Thanks. It is working now.

Back to PICKit3 debug, I have some difficulty to use break point even with normal code (not in interrupt routine). It always returns error information as:

PK3Err0040: The target device is not ready for debugging.
Please check your configuration bit settings and program
the device before proceeding.

Any suggestion? Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 13, 2011 5:09 pm     Reply with quote

1. In MPLAB, go to the Help / Topics menu. In the Debuggers section,
select "MPLAB Pickit 3".

2. In the pop-up window for Pickit 3 Help, expand the section on
TroubleShooting. Then click on TroubleShooting First Steps.

3. Then read these sections:
- Top 5 Questions to Answer First.
- Top 10 Reasons Why You Can't Debug.
- Other considerations.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group