Can an INTERNAL and EXTERNAL oscillator run at the same time?

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Exactly what chip and timer are you talking about. For a PIC18 PRE and POSTSCALE are usually timer parameters that some have and others don't. Using the K42 processor series as an example: TMR2 does and TMR3 does NOT.
Hi N,
18F4431 PIC .
Do you have a copy of the datasheet? Mine is revision D from 2010. Document # DS39616D, titled:
PIC18F2331/2431/4331/4431​
Data Sheet​
Hi P,
I've got the same D/S.
I'll try tomorrow, thanks all for today.
C
 

cmartinez

Joined Jan 17, 2007
8,788
Hello. The short answer to your question is, yes you can. I know this because I had to use an external 32.768 kHz crystal to keep accurate timing in a PIC16LF1825, while at the same time I switched the MCU's clock source between its internal and external clocks for power saving purposes. The external clock was used to trigger a Timer1 interrupt for clock and calendar keeping. I was able to easily switch between both clock sources without a hitch with said chip.

But when I tried to do the same thing on a different project using a PIC16LF18446 I hit a wall, so to speak. In that architecture, it's not possible to use the same pin as both the system clock and the Timer source. So I had to use an external oscillator (and not a crystal) connected to the chip's OSC1 pin, and also to RA0, which I then used as the timer source.

My point is that getting what you want depends on the chip you're using. And unfortunately I'm not familiar with your chip. You're gonna have to test it.
 

nsaspook

Joined Aug 27, 2009
16,359
Yes, it depends.
PC18 Q84 WS RGA driver
1710640405264.png

1710639944201.png
10MHz clock chip for CANBUS clock module requirements
1710640028580.png
10Mz to 40MHZ with 4X PLL and internal clock set to 16MHz
1710640086529.png
FOSC 40MHz external clock source
1710640130601.png
same PWM, 16MHz internal clock source
1710640178070.png
CLKOUT and a GPIO pin for the two clocks.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi C and N,
Some nice equipments there!
From the D/S I thought I'd found the settings for what I want, which is an 8mHz external crystal set to x4 PLL. and the internal Oscillator for the CCP1 section.
My settings stopped TMR1.

Here's the OSH oscillator PORTC.2 showing CCPR1 1mS and PORTD.7 is a isec flash in the MAIN LOOP, and the LOG, which shows the result from each setting change. The bottom, shows nothing as the TMR1 stopped.
I hope you can follow it.
C
 

Attachments

nsaspook

Joined Aug 27, 2009
16,359
Hi C and N,
Some nice equipments there!
From the D/S I thought I'd found the settings for what I want, which is an 8mHz external crystal set to x4 PLL. and the internal Oscillator for the CCP1 section.
My settings stopped TMR1.

Here's the OSH oscillator PORTC.2 showing CCPR1 1mS and PORTD.7 is a isec flash in the MAIN LOOP, and the LOG, which shows the result from each setting change. The bottom, shows nothing as the TMR1 stopped.
I hope you can follow it.
C
I'll see if I can get a few 40 pin 4431 chips. Those are sort of old and don't have support in MCC so it's back to doing a manual config.
The 4431 is pin compatible with one of my Q84 boards, so I can just drop it on that.
1710704062522.png
What board are you using? A PICDEM MC?
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
I'll see if I can get a few 40 pin 4431 chips. Those are sort of old and don't have support in MCC so it's back to doing a manual config.
The 4431 is pin compatible with one of my Q84 boards, so I can just drop it on that.
View attachment 317838
What board are you using? A PICDEM MC?
Hi N,
I've just seen some in Mouser, I presume I could buy a couple and have them delivered to you. I'm in the UK, and the postage is E20, so a couple would be £40ish, and a bit too much for this really, I'm not sure what it would be where you are.
It may be easier if you use MPLAB, if you've got it (I don't use it) and set the settings there, as a test.
I try my settings in the Oshonsoft simulator, which works well.

My PCB, has been designed by me over years, and produced in China, then I stick all the bits on.
C
 

Attachments

nsaspook

Joined Aug 27, 2009
16,359
Hi N,
I've just seen some in Mouser, I presume I could buy a couple and have them delivered to you. I'm in the UK, and the postage is E20, so a couple would be £40ish, and a bit too much for this really, I'm not sure what it would be where you are.
It may be easier if you use MPLAB, if you've got it (I don't use it) and set the settings there, as a test.
I try my settings in the Oshonsoft simulator, which works well.

My PCB, has been designed by me over years, and made orinted in China, then I stick the bits on.
C
Don't worry about that, I can easily get some and I have a some XC8 compatible code to play with so I can see what's possible without using BASIC.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Don't worry about that, I can easily get some and I have a some XC8 compatible code to play with so I can see what's possible without using BASIC.
Hi N,
That's good of you, but give me a day or two before you order, in case I get better results.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi N,
The reason I needed to know if both oscillators can work at the same time, is time controlled INTERRUPTs, where I thought I needed PRE and POST-SCALING, but I've been testing and I think I have found that I don't.
I haven't finished checking, but I'll post my results.
C
 

cmartinez

Joined Jan 17, 2007
8,788
Hi N,
The reason I needed to know if both oscillators can work at the same time, is time controlled INTERRUPTs, where I thought I needed PRE and POST-SCALING, but I've been testing and I think I have found that I don't.
I haven't finished checking, but I'll post my results.
C
You may need to reconsider the MCU you chose for your project, then.
 

MrChips

Joined Oct 2, 2009
34,912
You mean 8MHz and 32MHz?
8mHz and 32mHz mean something else.

Be aware that if you have two crystals on the same board, one will try to pull the other into synchronization.

 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
You mean 8MHz and 32MHz?
8mHz and 32mHz mean something else.

Be aware that if you have two crystals on the same board, one will try to pull the other into synchronization.

Hi Mr C,
I'm using TMR1 as it has an external clocked PIN but no POSTSCALE, where TMR2 has PRESCALE and POSTSCALE, but no output PIN. (as mentioned I think TMR1 will do what I need).

There is an 8mHz internal oscillator, with choice settings, and and external 8mHz crystal x4PLL = 32mHz.
Unless anyone tells me otherwise, I think one or the other is chosen.
C.
 

MrChips

Joined Oct 2, 2009
34,912
Will you please stop typing 8mHz and 32mHz?
The period of one 8mHz cycle is 125 seconds. The period of one 32mHz cycle is 31.25 seconds.

The period of one 8MHz cycle is 125 nanoseconds. The period of one 32MHz cycle is 31.25 nanoseconds.
That is 9 orders of magnitude difference.
 

MrChips

Joined Oct 2, 2009
34,912
I don't know anything about the Microchip PIC you are using. I would have to look up the datasheet.
I am using an 8MHz crystal on my MCU and I can generate just about any clock frequency I want all the way up to 50MHz. I don't need any additional crystal. The MCU core is clocking at 200MHz.
 

Papabravo

Joined Feb 24, 2006
22,084
Will you please stop typing 8mHz and 32mHz?
The period of one 8mHz cycle is 125 seconds. The period of one 32mHz cycle is 31.25 seconds.

The period of one 8MHz cycle is 125 nanoseconds. The period of one 32MHz cycle is 31.25 nanoseconds.
That is 9 orders of magnitude difference.
Some people have impediments they cannot overcome. It is not for want of trying; some things are just not in the realm of possibility for some people. It may feel good to rant, but it surely does not have the intended effect.
 

BobTPH

Joined Jun 5, 2013
11,566
If I understand you correctly, you are saying that you want TIMER1 to interrupt every 1ms. And you don't think you can clock it to do that with the oscillator being an 8 MHz crystal x 4 PLL or 32MHz.

I don't see the problem. You don't even need the prescalar.

Fosc is 32 Mhz.
TIMER1 is clocked by Fosc / 4 which is 8 MHz.


Load TIMER1 with (65536 - 8000) and it will interrupt after 1 msec. It is tricky to do this continuously because you have to allow for the instruction cycles from when the interrupt occurred to when it is reloaded. But I have done this before on PIC16s and it works just fine.
 
Top