Specialist Supplier of Crystals & Frequency Control Componentssales@mecxtal.com.cn0755-26500570
MERLIN home / Rednote / System Validation and Replacement

Can a PIC16F877A Replace a 4 MHz Crystal with 20 MHz? Check XT, HS and Timing

Not by changing the crystal alone. The PIC16F877A datasheet lists 20 MHz for HS oscillator operation, whereas the published XT range reaches 4 MHz. A board qualified with 4 MHz in XT mode cannot retain that setup and assume that 20 MHz will also preserve UART and timing. For repair, restore the approved 4 MHz crystal. Treat 20 MHz as a deliberate redesign and verify the exact part's supply, temperature, HS configuration and equipment timing.

Why does changing frequency require an oscillator-mode review?

The PIC16F87XA manual distinguishes XT, HS, LP and RC oscillator settings. XT and HS are internal circuit conditions, not labels for two similar-looking crystals. The crystal capacitor table has 4 MHz examples under XT and HS, but its 20 MHz example is under HS. Allowed frequency, mode and selected part must agree. A headline 20 MHz maximum is not evidence that the installed firmware and PCB already support it.

Actual situationDecision
Original 4 MHz XT board, restoration onlyRestore approved crystal and loading network
20 MHz while keeping XTOutside that mode's stated range; don't approve
20 MHz with HSConsider as a redesign; verify supply, timing and startup
Proposed 24 MHzOutside the stated 20 MHz device limit

A driven external clock is different from a passive crystal in the MCU's own loop. Use the applicable driven-input conditions rather than assuming bypassing the quartz loop permits overspeed. If the marking is limited to “877,” identify the full model, supply and approved revision before selecting a part.

Does the 15 to 33 pF guide mean buying a 22 pF crystal?

No. The 20 MHz HS example lists 15 to 33 pF each for external C1 and C2 as design guidelines. The crystal's 22 pF marking would generally describe its effective load, not either fitted capacitor. Two ideal 22 pF capacitors contribute an 11 pF series equivalent before pin and board strays. That does not specify an 11 pF crystal for every board or qualify drive and startup.

Can the old Epson 20 MHz example be ordered directly?

Microchip's historical table includes Japan's Epson CA-301 20.000M-C as a reference, with ±30 ppm. It helps identify an example used at the time, not the part necessarily fitted to your board or current availability. Verify actual construction, mechanics, mode and load for any new crystal. Do not copy the historic capacitors into a redesigned layout solely because the table includes that part. Distinguish the manufacturer's example from a supplier's commitment for the exact code.

Why can delays and UART communication change after the swap?

A PIC16F877A instruction cycle comprises four oscillator periods. At nominal 4 MHz it is 1 µs; at 20 MHz it is 0.2 µs. An illustrative 1000-instruction-cycle interval changes from 1 ms to about 0.2 ms. This applies to an equal number of instruction cycles, not every instruction path or the entire application. Interrupts, prescalers, branches and UART mode affect equipment timing. A running application does not prove those conditions were preserved.

Recheck the actual bit rate before diagnosing garbled characters

Preserve the original UART and peer settings. Check the firmware's assumed frequency, actual source and measured bit width separately after the swap. Stale build constants or baud-generator settings can corrupt communication without significant quartz frequency error. If the board includes a separate USB-to-UART bridge, host enumeration of that bridge says nothing about the PIC's baud rate. Record host detection, UART communication and processor clock as separate evidence.

How can you avoid doing the swap twice?

Record exact parts, firmware, oscillator mode and a repeatable timing or communications baseline on an existing working board. Validate the intended mode and supply on an authorized prototype. If there is no activity, check power, reset, configuration and the quartz network before trying another frequency. Use a measurement point appropriate to the circuit so the probe does not stop an otherwise working oscillator. A cold-start trace doesn't explain an issue that appears only after sustained running.

Separate three pilot checks: startup in the intended environment, consistent clock assumptions throughout firmware, and equipment-level timing and behavior. For intermittent startup, record temperature, supply events and reset state. The published 20 MHz limit does not settle those checks. On a one-unit repair, avoid undocumented side changes that create additional qualification requirements.

What should purchasing and service record?

For restoration, request the approved 4 MHz fundamental passive crystal and load for the PIC16F877A board. For a speed increase, describe 20 MHz as a new HS design candidate that needs power and firmware verification. A 24 MHz quote is not a substitute for this model just because the package is the same or the price is attractive. Maintain separate stock records by frequency and board revision so repair and redesign materials are not both reduced to “PIC crystal.”

For older equipment, check whether the same product name has multiple supply or package variants. Preserve the actual rail, full controller marking, reset setup, approved firmware build and baud rate. A public demonstration program does not reconstruct a legacy equipment configuration. A working reference unit supplies baseline evidence without requiring changes to its data. If the exact part is unavailable, qualify a same-frequency substitute for mode, load and footprint rather than bypassing the problem by raising frequency. Preserving timing is often the fastest repair when the controller must synchronize with other equipment.

Keep three pilot entries: observed clock frequency, firmware timing assumptions and measured equipment intervals compared with requirements. A failed entry is not a completed crystal approval. Use allowed operating conditions, and distinguish a room-temperature run from coverage of cold startup and supply extremes. Document changes to boot configuration, UART and interrupts so borrowed boards are not returned to stock under the wrong assumptions. For a garbled UART complaint, verify frequency and communications settings separately before expanding the repair to a whole clock redesign.

WeChat

MERLIN · TIMING COMPONENTS

Scan with WeChat to contact Sales

Add our WeCom contacts from your usual WeChat app.

On desktop, scan with your phone. On mobile, save the QR image and select it from your album in WeChat Scan.