View previous topic :: View next topic |
Author |
Message |
kongfu1
Joined: 26 Apr 2010 Posts: 56
|
Comparator is not working with PIC16F882 |
Posted: Wed Jul 13, 2011 3:51 pm |
|
|
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
|
|
Posted: Wed Jul 13, 2011 4:18 pm |
|
|
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
|
|
Posted: Wed Jul 13, 2011 4:26 pm |
|
|
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
|
|
Posted: Wed Jul 13, 2011 4:34 pm |
|
|
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
|
|
Posted: Wed Jul 13, 2011 4:59 pm |
|
|
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
|
|
Posted: Wed Jul 13, 2011 5:09 pm |
|
|
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. |
|
|
|