4
\$\begingroup\$

I've seen a microcontroller (don't remember the exact part number at the moment,) that doesn't have XTAL pins.

It was an 8-pin MCU - it didn't have any clock input pins on the device.

How do those devices work without a clock, and with only power. How does the device start working?

I understand that there are internal oscillators that would help, but just not able to understand how the device would start up. Like, how would it be for programming and other stuff?

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Newbie, some MSP430's for example have an internal DCO, a VLO, and perhaps even an internal oscillator configured externally with a resistor (ROSC.) The DCO allows a very wide range of programming options for speed, dithering, etc. \$\endgroup\$
    – jonk
    Oct 25, 2022 at 18:55
  • 4
    \$\begingroup\$ Every STM32 micro I've used over the last few years has an internal clock which it boots up on. You then have the option to switch over to an external flock if you want to after your code starts running. \$\endgroup\$
    – brhans
    Oct 25, 2022 at 20:25
  • 1
    \$\begingroup\$ Only 8 pins? Makes sense to use an internal oscillator, so that those few pins can be programmed functionally as the programmer wishes. In any case, two of those eight pins must be for power (GND, +VDD). Even so, some 8-pin microcontrollers do devote 2 pins for a crystal or other resonator...quite a few applications need tight frequency control that crystals provide (like a watch). That leaves only 4 pins to do useful stuff. What don't you understand about the internal oscillator?...on power-up it starts promptly, and instructions begin executing at a rate determined by its frequency. \$\endgroup\$
    – glen_geek
    Oct 25, 2022 at 21:19

7 Answers 7

26
\$\begingroup\$

Many (most?) MCU's have an internal oscillator that can be used as the clock.

Typically there will be a configuration that is held in non-volatile memory to set the clocking mode. The actual method will depend upon the specific microcontroller.

The downside to using the internal clock is that it is not very accurate, maybe +/- 1-2% and so cannot be used for applications that require high-accuracy such as for time of day. It may not even be accurate enough for reliable use as a clock for async communications (commonly referred to as RS232).

The AVR line of microcontrollers have an internal clock available. On many versions of AVR the speed of the internal clock is selectable from a few choices to optimize power.

\$\endgroup\$
11
  • 1
    \$\begingroup\$ Oh, so initially, we just provide power to the MCU. Once power is provided, using JTAG, or SWD or some other debugging interface, we program the MCU to use the internal or external clock, right? \$\endgroup\$
    – Newbie
    Oct 25, 2022 at 18:49
  • 5
    \$\begingroup\$ @Newbie Your phrasing makes it sound like you think we hook up the JTAG and then change a setting so the MCU uses a different oscillator. This is not the case. The MCU always boots up using the internal oscillator. It then starts to run the code you uploaded to it with a JTAG or SWD and if those instructions contain something to tell it to change to the external oscillator, it does. If it doesn't, it doesn't. \$\endgroup\$
    – DKNguyen
    Oct 26, 2022 at 3:55
  • 10
    \$\begingroup\$ @DKNguyen Depends on MCU. Not all MCUs start with internal clocks nor have software selectable clocks. For example some AVRs and PICs have "fuse bits" or "confg bits" for many things like clock selection which you can change with a programmer, JTAG or In System Programming interface. \$\endgroup\$
    – Justme
    Oct 26, 2022 at 5:55
  • 1
    \$\begingroup\$ @Newbie, What fuse bits to config depend on which specific MCU you are using, you asked a generic question, and you got multiple answers. If you want to know how to set the fuse, pick one specific MCU that you are interested and read the datasheet. Also most of the compiler tool chain will allow your to configure the fuse settings. \$\endgroup\$
    – hcheung
    Oct 26, 2022 at 12:11
  • 3
    \$\begingroup\$ I'm not sure if what is being told here in the comments is 100% correct in the context of AVR. (It is for e.g. STM32) On an AVR, you select the desired clock by flashing fuse-bits. This is done through a programmer, but it's not part of the binary you are uploading. E.g. see here: engbedded.com/fusecalc \$\endgroup\$
    – Opifex
    Oct 26, 2022 at 15:05
12
\$\begingroup\$

The Microchip PIC range of chips (or at least some of them) can use their own internal oscillator, instead of an external clock.

\$\endgroup\$
5
  • \$\begingroup\$ Beat me to it! ) \$\endgroup\$
    – PStechPaul
    Oct 25, 2022 at 18:33
  • \$\begingroup\$ But how does it start? \$\endgroup\$
    – Newbie
    Oct 25, 2022 at 18:46
  • 2
    \$\begingroup\$ @Newbie You program the clock settings into it while flashing the software. Then turn the power on. \$\endgroup\$
    – Simon B
    Oct 25, 2022 at 22:29
  • 3
    \$\begingroup\$ @Newbie you give it power and the clock runs, as with oscillators in general. \$\endgroup\$
    – Ian Bland
    Oct 26, 2022 at 1:47
  • \$\begingroup\$ @Newbie Are you asking how it starts with the internal oscillator? It is configured to do so. Or are you asking how it starts so that it can listen for code and configuration to be uploadable? The PIC's programming system is pure hardware based and does not use a clock at all. Instead the programmer (USB device, parallel port dongle etc.) will clock in the bit stream using one of the programming pins into the MCU the same way you'd use a memory device (RAM, ROM, SD Card etc). And just like a memory device (eg. SD Card) the PIC's programming system does not use any other clocks for its logic \$\endgroup\$
    – slebetman
    Oct 27, 2022 at 1:32
11
\$\begingroup\$

Just look for internal oscillator in the documentation or features on an MCU. There are drawbacks and positives to using an internal oscillator

Chances are, your favorite MCU has an internal RC oscillator. There are numerous microcontroller families from all major manufacturers that include this module, including those from Texas Instruments, STMicroelectronics, and Microchip. There are also accompanying application notes online from virtually all manufacturers on how to calibrate the internal oscillator of their MCUs. https://www.allaboutcircuits.com/technical-articles/the-good-and-the-bad-of-mcu-internal-oscillators/


I understand that there are internal oscillators that would help, but just not able to understand how the device would start up. Like, how would it be for programming and other stuff?

The device operates the same way, the clock source is pulled from an internal clock source. A processor will not operate without a clock. To select the clock usually a JTAG is used to program the MCU and tell it to use an internal or external source. Upon startup the MCU reads the configuration from ROM and tells it which clock to use. Sometimes the internal clock is used and then it switches to an external clock. The difference is external clocks can be more precise so if you need more precision in timing then

\$\endgroup\$
2
4
\$\begingroup\$

In general, the programming device could be providing the clock needed to configure clock source if the clock is missing. That is not always the case though.

Many microcontrollers have an internal oscillator, with the specification explained on the datasheet. If more accuracy (and often higher clock frequency) is required, you'd use an external clock source.

The Atmega microcontrollers, such as the Microchip Atmega328p used in Arduino can use their internal oscillator. In the case of Atmega328 the clock source is set in "fuse" bits during the programming with an AVR ISP programmer.

\$\endgroup\$
5
  • \$\begingroup\$ Thank you for the answer! Could you please tell me what are fuse bits? \$\endgroup\$
    – Newbie
    Oct 25, 2022 at 18:48
  • \$\begingroup\$ In the case of Atmegas it is a normal register of settings. Two bits of the register might set the clock source for example. The "fuse" term is derived from having a possibility to permanently set them to a state. With Atmega they are not "burned" permanently to a state just by setting them. Why someone would want to set them permanently For example once you set "programmable" fuse to 0, it won't accept new FW and the device is more difficult to be hi-jackked. \$\endgroup\$
    – Ralph
    Oct 25, 2022 at 19:00
  • \$\begingroup\$ I wonder what the silicon-area and power-consumption trade-offs are between "fuse" bits and software-controlled registers? I would think for many high-reliability purposes a useful trade-off would be to have two fuse bits for each mode setting, one of which would, if programmed, force it to zero continuously and the other of which would force it to one unconditionally. By my understanding, reading a programmed flash bit "continuously" would take more current than reading an unprogrammed one, so having circuitry continuously check that the chip was allowed to be in its present state would... \$\endgroup\$
    – supercat
    Oct 26, 2022 at 16:27
  • \$\begingroup\$ ...not affect quiescent current draw, but would ensure that even if a stray radiation event particle tried to switch device modes, it couldn't latch in a state contrary to what the fuses dictated. \$\endgroup\$
    – supercat
    Oct 26, 2022 at 16:28
  • \$\begingroup\$ There has probably been multiple reasons, but it's more of selecting a hardware setting or "route" and you wouldn't be accessing the information often, only during boot up. Might've been literally a route for some devices that gets blown like a fuse (not the case with AVR etc). \$\endgroup\$
    – Ralph
    Oct 26, 2022 at 19:16
3
\$\begingroup\$

Most of the microcontrollers have internal clock. The internal clock is usually resistor capacitor based (RC Oscillator) which is not very accurate (only 1% to 2%. External Oscillator are crystal based and are very accurate. PIC microcontrollers and many AVRs have internal clock. You can check the datasheet of the MCU for Oscillator details.

\$\endgroup\$
2
\$\begingroup\$

Yes, there are many MCUs with internal oscillators that require no external clock sources.

Most MCUs have several clock sources, and a clock source has to be explicitly selected to be something else than a default. The default is one of the internal oscillators. There may be more than one, in fact.

In some MCUs, the clock configuration is permanent and comes from a special "config word" written into the MCU by the programmer device. This "config word" is known by many names, e.g. "fuse word", and it may reside in the code address space, or outside of it.

In other MCUs, the configuration is volatile and is programmed into the clock control registers by the firmware as it starts up. The bootloader may change the clock configuration, and then once the firmware runs it may make further changes as needed.

MCUs with complex clocking have "clock watchdogs" that use the internal oscillator to detect presence of an external clock signal. When the external clock fails for any reason, the MCU can automatically switch to the internal clock as a fallback. The firmware can respond to it in an interrupt handler, and can take necessary recovery/failsafe actions.

\$\endgroup\$
1
\$\begingroup\$

Almost all Microcontrollers have a internal clock source. Some micro-controllers have features to use a external clock. If you are not concerned about any clock timing error in nano second scale, you can just use internal clock. Almost all real time operating systems use a timer based on internal clock of a microcontroller for their timing, scheduling and task functionality.A internal clock is usually accurate in millisecond scale.

All peripherals need a clock source to function and generate signals at accurate intervals. ADC, SPI, PWM, General purpose timer and others use the internal clock. They derive their clock from the main clock source of the microcontroller which is usually written as XTAL.

More info about XTAL and external clock EXTAL here:

https://www.nxp.com/docs/en/application-note/AN1706.pdf

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Almost all? You can still buy old technology which has no internal clock. And what does it matter what clock an RTOS uses? Usually peripherals use the system clock for running, and the system clock is derived from somewhere, be it external or internal. \$\endgroup\$
    – Justme
    Oct 26, 2022 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.