|
|
View previous topic :: View next topic |
Author |
Message |
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
Oscillator Switching Works sometimes |
Posted: Mon Oct 16, 2006 1:12 pm |
|
|
I'm trying to using the PIC16LF6720 with H4 4MHz main Oscillator PLL to 16MHz, and allow the code to switch to TIMER1 Oscillator which has 32768KHz input.
Timer 1 OSC is enabled but it's getting a 32KHz signals from a TCXO All signal voltage levels are very good. Although I'm wasting one pin by enabling the Oscillator, it required for Oscillator Swithcing to be enabled.
Switching to and from SlowSpeed() is activated by the user pressing a switch, or by code calls.
This works for about 98% of the time.
When it fails it always fails going into the Low Frequency clock, never fails going from Low Frequency to High Frequency. !
I can predict when switching has failed because the unit appears to be hung. The "Odd effect" (reproducible 100% of the time) is this:
If the failure to switch to Low Frequency happens and I leave the unit running for several minutes (not determined yet how many but I'm sure it's longer than 10 minutes) the unit starts to function normally at Slow Speed and from that time on so long as I do not power cycle switching back and forth Low to High and High to Low Frequency never fails. !
It's as if the code went out to the weeds and finally found it's way back... !
I've tried longer delays to allow for PLL lock and Oscllator switching as per data sheet, and it does not help.
In slow speed there is only one Interrupt enabled and the ISR sets a global value and that's all. I'm trying to convince myself it's not the single ISR that's eating my lunch at 32KHz because once it works, it works fine. !
Here is a snippet of my code which is just about all that is done in the SpeedSwitching function.
I suspect I missed something and simply can't see what I did wrong!
Best regards
Hans W
int KeySwitch=0; // global
////////////////////////////////////
// the key ISR
#int_EXT3
EXT3_isr()
{
KeySwitch=1; // thats all it does
}
////////////////////////////////////
//
void GoSlowSpeed()
{
int done=0;
disable_interrupts(GLOBAL);
disable_interrupts(INT_RDA);
disable_interrupts(INT_RDA2);
disable_interrupts(INT_TIMER3);
disable_interrupts(INT_TIMER1);
// only interrupt still enabled is #int_EXT3
Setup_Oscillator(OSC_TIMER1);// 32Khz
#use delay(clock=32768)
delay_ms(25); // have tried as much as 250mS
enable_interrupts(GLOBAL);
KeySwitch=0;
do{
// slow stuff done here, "done" can be incremented for other reasons.
if( Keyswitch )
{
done++;
}
}while( !done );
disable_interrupts(GLOBAL);
// switch to H4 Oscillator
#use delay(clock=16000000)
setup_OSCILLATOR(OSC_NORMAL);
delay_ms(16); // have tried as much as 250mS.
enable_interrupts(INT_TIMER3);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_RDA);
enable_interrupts(INT_RDA2);
enable_interrupts(GLOBAL);
} |
|
|
Ttelmah Guest
|
|
Posted: Mon Oct 16, 2006 2:38 pm |
|
|
I'd start by sticking a scope on T1OSO, and verifying that the 32K oscillator signal is seen here. The hang, sounds like the behaviour you get if you switch to an oscillator that is enabled, but not running...
The 'suspicion', is that the oscillator starts up for some reason latter, and once it is running, the problem disappears.
You don't need any delay after switching the oscillator, the chip should do this for you.
Best Wishes |
|
|
Guest
|
|
Posted: Mon Oct 16, 2006 2:55 pm |
|
|
Ttelmah wrote: | I'd start by sticking a scope on T1OSO, and verifying that the 32K oscillator signal is seen here. The hang, sounds like the behaviour you get if you switch to an oscillator that is enabled, but not running...
The 'suspicion', is that the oscillator starts up for some reason latter, and once it is running, the problem disappears.
You don't need any delay after switching the oscillator, the chip should do this for you.
Best Wishes |
Thanks for the tip. However as I pointed out the T1OSC is fed directly from a 32KHz TCXO chip and not by using a 32KHz crystal.
Good point and I have not checked (just assumed) the MAXIM 32KHz is running, I've never had these fail, and if they do fail in this design then Three of them are suddenly going bad !
I'll hard wire a test point to iit and keep a scope probe connected to confirm that the TCXO is in fact running when the "effect happens"
OK about not needing a delay, I added it after the thing failed. |
|
|
Guest
|
Correct and test |
Posted: Mon Oct 16, 2006 3:52 pm |
|
|
Anonymous wrote: | Ttelmah wrote: | I'd start by sticking a scope on T1OSO, and verifying that the 32K oscillator signal is seen here. The hang, sounds like the behaviour you get if you switch to an oscillator that is enabled, but not running...
The 'suspicion', is that the oscillator starts up for some reason latter, and once it is running, the problem disappears.
You don't need any delay after switching the oscillator, the chip should do this for you.
Best Wishes |
Thanks for the tip. However as I pointed out the T1OSC is fed directly from a 32KHz TCXO chip and not by using a 32KHz crystal.
Good point and I have not checked (just assumed) the MAXIM 32KHz is running, I've never had these fail, and if they do fail in this design then Three of them are suddenly going bad !
I'll hard wire a test point to iit and keep a scope probe connected to confirm that the TCXO is in fact running when the "effect happens"
OK about not needing a delay, I added it after the thing failed. |
Correction: T1OSI (not out) is fed directly from the TCXO chip.
I connected a scope probe and when the failure happens there is a 32KHz signal (with full pp V) at T1OSI (pin 29) |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
Update Further findings. |
Posted: Mon Oct 16, 2006 10:09 pm |
|
|
I've reduced the code to these three lines.
disable_interrupts(GLOBAL);
output_high(PIN_B7); // scope on this pin show B7 to be High
Setup_Oscillator(OSC_TIMER1);// 32Khz The chip goes ut to the weed patch
output_low(PIN_B7); // and takes several minutes before B7 goes low
enable_interrupts(GLOBAL);
With interrupts disabled I find it hard to imagine what the chip is doing for all those minutes !
Pity the ICD-U40 does not allow debugging at 32KHz. Not being able to step through the code makes it difficult to debug. That's why I'm using the scope and doing simple thigns like setting and clearing pins.
I think I'll post this question on the Microchip help pages...
hansw
From the LST file.
.................... disable_interrupts(GLOBAL);
0C0E4: BCF FF2.6
0C0E6: BCF FF2.7
0C0E8: BTFSC FF2.7
0C0EA: BRA C0E6
.................... output_high(PIN_B7);
0C0EC: BSF F8A.7
.................... Setup_Oscillator(OSC_TIMER1);// 32KHz as system clock current goes down to 4.5mA
0C0EE: MOVLW 01
0C0F0: MOVWF FD3
.................... output_low(PIN_B7);
0C0F2: BCF F8A.7
.................... enable_interrupts(GLOBAL);
0C0F4: MOVLW C0
0C0F6: IORWF FF2,F |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 17, 2006 1:53 pm |
|
|
In your code, you're using Pin B7, but that pin is used by the CCS-ICD.
Are you attempting to toggle that pin, while using the debugger ?
If so, that could explain the problem.
If that's not the problem, then:
1. Can you put the code that you posted above into a small, compileable
test program, that shows the #fuses line, and post it ?
2. Can you post your compiler version ? |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
|
Posted: Tue Oct 17, 2006 8:05 pm |
|
|
PCM programmer wrote: | In your code, you're using Pin B7, but that pin is used by the CCS-ICD.
Are you attempting to toggle that pin, while using the debugger ?
If so, that could explain the problem.
If that's not the problem, then:
1. Can you put the code that you posted above into a small, compileable
test program, that shows the #fuses line, and post it ?
2. Can you post your compiler version ? |
Thanks for your reply.
I needed the last two pins (b6 and b7) and have code that never uses those pins when connected to the debugger.
The ICD-U40 simply does not "step" or "break" at 32KHz and so I left all of the "forbidden code" until last becasue I realized that I would be stuck with "old style printf" debugging. !
I'll get a test program toegther tomorrow. It's a good idea anyway becasue I'm still not convinced it's the chip, I think I did something (how much can I do wrong in one line of code?) and I have not yet seen the problem !
I'm up to date on my yearly subscritption, but I'm stuck at PCH V3.249 because the Old IDE in PCWH is simply much better. Sorry to say this but the new IDE sucks... I doubt I'll ever get to like it... too many bells and whistles! and I don't like giving away 4-5 lines of code space just to make room for a fat bloated menu !
I also do not want to battle unkown compiler issues, I need to stick with one chip and a compiler version that I can get used to, knowing the quirks of either item is many times better than battling unkowns. |
|
|
Ttelmah Guest
|
|
Posted: Wed Oct 18, 2006 2:27 am |
|
|
I understood that you were using an external oscillator (this is presumably a 'crystal oscillator'...). The point I was making was to look at T1OSO, not the input. In the past, there have been problems on some occasions with the primary oscillator, where if the input is overdriven, it does not run as expected. My suspicion isthat something similar is happening here, and that perhaps the internal gate is getting into an unexpected state, from being driven possibly too hard. If so, I'd expect the output pin, to not be matching the invert of the input signal. This is what I was suggesting testing. The internal 'oscillator', when enabled, has significant gain, and an input that is expecting to receive a noticeably attenuated signal from the output of a crystal, not a 'rail to rail' logic signal.
Best Wishes |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
T1OSO |
Posted: Wed Oct 18, 2006 9:43 am |
|
|
Ttelmah wrote: | I understood that you were using an external oscillator (this is presumably a 'crystal oscillator'...). The point I was making was to look at T1OSO, not the input. In the past, there have been problems on some occasions with the primary oscillator, where if the input is overdriven, it does not run as expected. My suspicion isthat something similar is happening here, and that perhaps the internal gate is getting into an unexpected state, from being driven possibly too hard. If so, I'd expect the output pin, to not be matching the invert of the input signal. This is what I was suggesting testing. The internal 'oscillator', when enabled, has significant gain, and an input that is expecting to receive a noticeably attenuated signal from the output of a crystal, not a 'rail to rail' logic signal.
Best Wishes |
Yes I understood that:
My correction was to clarify that my circuit was feeding the TCXO into T1OSI and not T1OSO as I had incorrectly stated.
I agree this may be the source of the problem, I've noticed a change in the duty cycle at the output during the initial 1 to 2 seconds when the request to change osc. takes place, but this happens on units that work OK all the time also.
I've been experimenting with suggestions from the Maxim 32KHz data sheet (ver. 103000) Page 3 Fig.4 where they show a method of coupling to a RTC chip using a 1M and 100pF. It did not help cure the problem and I left it at that.
Perhaps I need to reduce the drive even further, they suggest 1M and 100pF as starting values.
This odd method of coupling is more aimed at reducing power in the 32KHz.
A much simplfied schematic of T1 osc. stage suggests it's the classic invertor gate with a high value resistor connected from o/p to i/p .
I'll play with adding a lower the FB R and or put a pull up/down on the o/p stage to try and force a gain reduction.
The simple test would be to cut the feed from the RTC and wire in a 32KHz crystal to see if it fixes the problem.
Thanks for the help. |
|
|
Ttelmah Guest
|
|
Posted: Wed Oct 18, 2006 10:32 am |
|
|
OK. I wondered if you were misunderstanding what I was asking/saying (very easy to do - I do it all the time...).
The only thing I note, is that you are using the 'LF' chip variant. Now this has a different oscillator selected for Timer1 (the 'low power' version of the standard oscillator). You are presumably using the 18LF6720 (you originally say the 16LF6720)?.
I have only used switching like this on the standard (not low power) variant, and had no problems.
The only erratum for the 6720, should not affect this.
I am interested that you see the output change when the oscillator switch takes place. I would not have expected this (the oscillator is 'stand alone', and only it's output connects into the system clock multiplexer). Interesting!...
My actual thinking about problems, was in two specific situations. The first was what happens if your external clock starts before 'MCLR' rises?. The second was what happens if it starts before Vdd rises?. Though the normal PIC inputs are fairly well protected against the old CMOS latchup behaviour, I fond myself wondering if this was true for this low-power gate?...
If the external oscillaor has an 'enable', could you connect it to the PICs MCLR, to disable the oscillator till the PIC starts?.
Best Wishes |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
10K resistor |
Posted: Wed Oct 18, 2006 10:08 pm |
|
|
A 10K pull-up on the TCXO/T1OSI pin and I have still not been able to make it fail. !
I hate these bump in the night fixes.
Without knowing what the output stage really is in the DS32KHz, or what the PIC T1 Oscillator stage looks like, there no way of knowing why it fixed the problem.
I have to assume if the extra 10K fixes the problem on other units as well then I'll add it to the list of quirks for the PIC18LF6720 or DS32KHz...
BTW Just for the record. I arranged for the DS32KHz to power up after the PIC, that did not fix the problem.
As it is the DS32KHz and PIC power up on the same VDD, so it was a good suggestion because the DS32KHz outputs a few millisecond before the PIC is ready.
I'm happy it was not a code issue! As I said how many mistakes can I make in one line of code |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
10K resistor |
Posted: Thu Oct 19, 2006 4:56 pm |
|
|
Worked fine on a second unit. Third unit wil be modified tomorrow.
Only thing to do now is test the fix at 85C and -40C !
hansw |
|
|
|
|
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
|