|
|
View previous topic :: View next topic |
Author |
Message |
xlh1460
Joined: 28 Jul 2010 Posts: 10
|
Timer1 Works but Comparator1 Doesn't when debugging. |
Posted: Tue Jan 11, 2011 12:11 am |
|
|
MPLAB 8.63, PICkit 3 Debugger, Compiler 4.108.
Program Code:
Code: |
#include <16f886.h>
// 4 MHz internal clock, No watchdog timer, MCLR pin used as I/O, No internal pullup resistors
#fuses INTRC_IO,NOWDT,MCLR,NOPUT,BORV21
// Enable delay functions with 4 MHz clock
#use delay(clock=4000000)
#define LED PIN_B2
void main()
{
// 32.768kHz Crystal Connected to RC0/T1OSO and RC1/T1OSI
setup_timer_1(T1_EXTERNAL | T1_CLK_OUT | T1_DIV_BY_1);
// A1/C12IN- and A3/C1IN+ connected to T1OSO and T1OSI, respectively
// 32.768kHz signal is output on A4/C1OUT
setup_comparator(CP1_A1_A3 | CP1_OUT_ON_A4);
enable_interrupts( GLOBAL );
enable_interrupts( INT_TIMER1 );
while(true)
{
}
}
#INT_TIMER1
void timer1_isr()
{
output_toggle(LED);
}
|
When I use the programmer to program the chip, the LED toggles and I measure a 32.768kHz signal on pin A4.
When I run the same code in the debugger, the LED toggles but I don't get a signal on pin A4.
Any idea why the comparator doesn't appear to be working when running in the debugger?
Thanks.
UPDATE:
I decided to measure A4 with a scope instead of my DIY frequency counter and see that there is signal there.
The output is less than 1Vpp. When not debugging the signal is 5Vpp as expected. ??? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Tue Jan 11, 2011 6:35 am |
|
|
Don't have any of that hardware but I'd look at the schematics of both your programmer and the debugger to see what the difference is.
At first I thought it might be the famous open drain pin, but the spec says it's a normal I/O pin.
Since your scope sees a 1v pulse, I suspect the lack of a correct pullup resistor(low value) or some other 'heavy' load on the pin. Again, reading the schematics should show what is 'wrong'. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Tue Jan 11, 2011 8:34 am |
|
|
As a separate comment though, what is the 'point' of what is being done?.
You already have a TTL clock output, on the timer, driving the crystal. If you want to buffer this with the comparator, or possibly invert it, 'fine', but I'd not connect to the timer input pin for the other comparator source, since this doubles the capacitive loading at this point, and may well encourage the frequency to be out of spec.....
I can't see anything too suggest 'why' the debugger affects things though.
Best Wishes |
|
|
xlh1460
Joined: 28 Jul 2010 Posts: 10
|
|
Posted: Tue Jan 11, 2011 10:45 am |
|
|
Ttelmah wrote: | As a separate comment though, what is the 'point' of what is being done?.
You already have a TTL clock output, on the timer, driving the crystal. If you want to buffer this with the comparator, or possibly invert it, 'fine', but I'd not connect to the timer input pin for the other comparator source, since this doubles the capacitive loading at this point, and may well encourage the frequency to be out of spec.....
I can't see anything too suggest 'why' the debugger affects things though.
Best Wishes |
Great question as to the point.
I am trying to get an accurate 32.768 clock out of the PIC and it wasn't clear to me how to do it.
Are you suggesting that I use the T1OSO pin as the output source for that signal? If so, I really overlooked the obvious solution and made this far more difficult than I needed to.
I based my design on an application note from Silicon Labs where they took this approach with their C8052F321 chip.
It is likely that chips external crystal drive circuit has differerent characteristics than the PIC making their use of the comparator necessary.
I am still troubleshooting the debugger issues. I am using a PICkit 3 that I am beginning to think has some issues. I plan on replacing it soon.
Thank you. |
|
|
xlh1460
Joined: 28 Jul 2010 Posts: 10
|
|
Posted: Tue Jan 11, 2011 11:32 am |
|
|
I just checked the TOSO and T1OSI pins with a scope.
Probing T1OSI stops the oscillator from running and the output on T1OSO is not a TTL signal.
Am I missing something?
Thanks again. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Tue Jan 11, 2011 3:20 pm |
|
|
What I was suggesting was buffering the TIOSO signal, but stopping using the TIOSI signal. As you have found, the latter, is _sensitive_. Any load you apply here loads the crystal, and will make your signal inaccurate. Feed TIOSO into the comparator, and run the other comparator input, off the Vref, set to about the mid voltage of the timer waveform. You then get a square wave, without adding much load to the crystal.
Best Wishes |
|
|
xlh1460
Joined: 28 Jul 2010 Posts: 10
|
|
Posted: Tue Jan 11, 2011 4:28 pm |
|
|
Ttelmah wrote: | What I was suggesting was buffering the TIOSO signal, but stopping using the TIOSI signal. As you have found, the latter, is _sensitive_. Any load you apply here loads the crystal, and will make your signal inaccurate. Feed TIOSO into the comparator, and run the other comparator input, off the Vref, set to about the mid voltage of the timer waveform. You then get a square wave, without adding much load to the crystal.
Best Wishes |
Got it. Thanks very much. |
|
|
|
|
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
|