Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Selecting oscillator mode for microcontroller

Status
Not open for further replies.

Kittu20

Member level 2
Member level 2
Joined
Oct 18, 2022
Messages
52
Helped
1
Reputation
2
Reaction score
0
Trophy points
6
Activity points
427
I'm currently reading the PIC18F66K80 datasheet, specifically Section 3.3, which discusses various oscillator modes.

here's a list of each oscillator mode for the PIC18F66K80 family of devices:

  1. EC (External Clock, RA6 Available)
  2. ECIO (External Clock, Clock Out RA6)
  3. HS (High-Speed Crystal/Resonator)
  4. XT (Crystal/Resonator)
  5. LP (Low-Power Crystal)
  6. RC (External Resistor/Capacitor, RA6 Available)
  7. RCIO (External Resistor/Capacitor, Clock Out RA6)
  8. INTIO2 (Internal Oscillator with I/O on RA6 and RA7)
  9. INTIO1 (Internal Oscillator with FOSC/4 Output on RA6 and I/O on RA7)
While I understand that we can use internal or external oscillators for clock signals, I'm looking to understand the reasons behind choosing a particular mode and how to decide which one to use.

Could you please explain the rationale behind selecting different oscillator modes and offer guidance on when to use each
 

most internal oscillators are not as accurate for certain applications, but it can free 1 or 2 pins for I/O (or clock output in mode INTIO1), the Resistor/capacitor is the cheapest external oscillator, it can free a single pin (or clock output on that pín), Low power crystal is do drive a low frequency/low power crystal (I think it was up to 200kHz but most of the time to use a 32.7kHz watch crystal) XT was up o 4MHz I think and HS should be the upper limit (16MHz according to the PIC18F it uses the most power for an external oscillator)
the External clock doesn't drive a crystal or resonator, but expects a clock signal in the OSC1 PIN, it can be up to 64MHz!
 
1. An external clock source is fed to the Clock In pin and RA6 is available as a normal I/O pin.
2. same as 1. but a buffered copy of it is output on RA6.
3, 4 & 5 select different gains in the amplifier that provides feedback to an external frequency selecting device.
6. a resistor and capacitor set the frequency of an internal oscillator, RA6 is available as normal I/O.
7. same as 6. but RA6 carries a buffered copy of the internal clock signal.
8. uses the internally calibrated clock signal and both RA6 and RA7 are available as normal I/O.
9. same as 8. but RA6 carries the internal oscillator signal divided by four.

The different gains are needed to cater for the drive levels required for ceramic resonator and quartz crystals, there is wide overlap between the levels they need so you have to refer to the manufacturers data sheet to find which is most appropriate for the device you use.

For highest frequency accuracy an external clock is needed, typically from a temperature compensated quartz oscillator module. For applications needing less accuracy you can use the internal oscillator, it is still quite accurate and stable but you are restricted to the frequencies it can produce.

For lowest accuracy but cheapest designs you can use the RC oscillator. It can only produce relatively low frequencies because of the restriction on R and C values and the effects of internal IC capacitance. Any frequency in range can be selected with suitable values but it is prone to drift, depending on the stability of the RC components. Often RC is used to set a very low clock frequency and therefore lowest current consumption but upon being alerted to 'speed up' the clock selection bits are changed to a higher speed configuration.

Brian.
 
@betwixt

I still don't understand which one and why we should use. Please consider this use case:

  1. Sending Data from Micro to PC via UART, Configuration 8N1 at 115200 Speed:
    • If you need to transmit data from a microcontroller to a PC using a serial communication protocol, the configuration "8N1" refers to 8 data bits, no parity bit, and 1 stop bit.
  2. Displaying Battery Supply level on an LCD using Inbuilt ADC:
    • To display data from an device(like a battery voltage 0 to 5 V DC) on an LCD, you'd use the microcontroller's inbuilt Analog-to-Digital Converter (ADC) to convert the analog voltage to a digital value that can be shown on the LCD.
  3. Creating a Real-Time Clock Based on Software:
    • Building a real-time clock based on software usually involves writing code to keep track of time, often using an internal timer
For these three use cases, you should select an oscillator mode. What would you choose from the nine options available?
 
Last edited:

1 you need an exact value crystal to minimize errors, a common value is 11.0592 MHz (with a PIC that works at mode FOSC/[16 (n + 1)] or FOSC/[4 (n + 1)] you can achieve 0% error rate...) for that 1..MHz crystal you can try both HS mode (it will work!) or XT mode (you can try to lower the power consumption but it could fail to oscillate)

2. for ADC it's better to use a stable clock source, you can use any but RC modes, (RC is too unstable for ADC) I think internal oscillator is ok for that.

3. an RTC will need an exact clock, any external crystal or resonator should do the trick, for example the same 11.0592MHz after FOSC/4 you can use a prescaler or another method to divide the clocksignal to get a 1Hz for the RTC

I would go for HS most of the time... at least with your three cases...
 
1. UARTs use oversampling and majority bit detection to increase their tolerance to inaccurate speeds. This means they can work with typically 2% speed inaccuracy without data errors. The clock therefore isn't particularly critical for this application.

2. The ADC is relatively slow so the clock is relatively unimportant. Battery voltage only changes slowly so there is no need to sample it quickly and LCDs work at whatever speed you drive them, either directly or through the display's own driver circuit. For this application you can use any speed as long as it doesn't update the LCD so slowly that it can be seen writing pixels or segments one at a time..

3. This is the time critical one, the more accurate the processor clock, the better it will be at timekeeping. Instructions and timers all use well defined time periods so if you can keep the clock frequency stable you can in theory achieve perfect timekeeping.

If all this has to be done in one PIC, which is quite feasible, I would use a quartz crystal to give timekeeping accurate to a minute or so per year or a more precise external clock generator to give timekeeping to a few seconds per year. If you have multiple tasks, always select the clock mode to suite the most time critical one.

Brian.
 
If all this has to be done in one PIC, which is quite feasible, I would use a quartz crystal to give timekeeping accurate to a minute or so per year or a more precise external clock generator to give timekeeping to a few seconds per year. If you have multiple tasks, always select the clock mode to suite the most time critical one.

Brian.
As I understand, when choosing an oscillator for a project, we need to select one mode from the nine available options using the #pragma config FOSC = <mode> directive."

This directive will allows us to configure the oscillator mode that best suits our project's requirements.
 

Yes and no.
Yes, the FOSC does select the primary oscillator that is used initially when the MCU powers on (or resets).
No in that there is the ability to switch between oscillators *up to a point*. Section 3.3 of the data sheet discusses the various oscillator sources that you can switch between. Therefore you can switch between oscillators if you really need to while the code is running.
Susan
 

Hi,

For the various clock sources there are different behavioures
* absolute clock frequency accuracy
* clock jitter
* temperatue drift
* adjustability (manually variable capacitor, varicap, VCO)
* drift caused by supply voltage variation
* start up time after power down
* power requirement
* part cost
* PCB area
* maintenance (in the meaning of calibration by hardware, by software or manually)

Each clock source has it's features and specifications, benefits and drawbacks.
Each application has some clock requirements. These requirements determine which clock source can be used.

1) UART application needs a clock that is accurate within 1-2% tolerance. Accurate over time, temperature and supply voltage variation.
An RC clock usually can not guarantee this. But it's an easy task for an XTAL or a resonator.
Still there are options to use an RC clock for UARTs, but with increased effort. For example it could expect a dedicated UART receive pattern to calibrate on this.

2) ADC for tracking battery voltage. Is rather uncritical.
But there are other ADC tasks that have tighter requirements.
For example if you run an FFT on the ADC samples. Then you need at least a low jitter clock, but often a rather accurate and low drift clock.

3) RTC needs a very accurate very low drift clock. On the other hand it may be quite jittery.
An 1% inaccuracy lead to an error of 36 seconds per hour. Not acceptable
If you want an accuracy of 1 second per week, then it needs a clock with less than 1.6ppm = 0.00016% error
Quite hard requirement. Obviously no resistir and no capacitor is accurate like this. Thus an RC clock will not work.

Still RC clocks have their benefits:
* they are cheap
* easily adjustable frequency in a wide range by selecting part values
* very fast start up after power down

Klaus
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top