Microcontroller tweaks its own crystal ?? - Page 1
Forum section: electronics / general

author: frogblender
author_rank: Regular Contributor
timestamp: May 08, 2020, 06:49:18 am
content: I have an STM32F4 micro. It listens for, and syncs to, an external RF pulse from some other device. The RF pulse is one single pulse, every ten seconds. In those 10 seconds of silence, of course, my micro drifts, with the drift being within the micro's crystal's tolerance (30ppm). And when the next RF pulse comes in, my firmware knows _exactly_ how much relative drift there is between my crystal and the pulse.So... I want my firmware to be able to tweak my crystal frequency.... perhaps twiddling a spare IO line which applies a gentle load to a leg of the crystal to speed it up or slow it down, or some such? Anyone have any ideas?I can't do the tweaking in the digital domain, as I have an ADC sampling using the STM's clock, and at the end of the 10 seconds I'd either have too many or too few ADC samples.

author: dermeister
author_rank: Contributor
timestamp: May 08, 2020, 06:53:08 am
content: This paper may be of interest to you for hardware clock rate adjustment:https://users.ece.cmu.edu/~agr/resources/publications/rtss-clk-13.pdf

author: Daixiwen
author_rank: Frequent Contributor
timestamp: May 08, 2020, 07:04:30 am
content: How much accuracy do you need? If you have the budget you could use a VCXO controlled from a small DAC. That's what we use for some time synchronization products and we can reach a few ppb accuracy this way. It does require to finely tune a PID regulator though.If you prefer to keep it simple, can't you do a software interpolation of your ADC data to get the required number of samples?

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: May 08, 2020, 08:54:29 am
content: If you're dealing with times of the order of 10 seconds you can easily do any timing adjustment in software withoit messing around with hardware.You can connect I/O pins with series load caps and ground/tristate them to make some adjustments, but there is a risk of glitches during switching and reset that could make it all hang up.At least switch to an alternate RC oscillator while adjusting the crystal settings if possible

author: AndyC_772
author_rank: Super Contributor
timestamp: May 08, 2020, 10:47:36 am
content: This is exactly the sort of application for which a VCXO is used, likethis onefor example.To adjust the frequency, I'd connect a PWM output from the microcontroller through an R-C filter to create a simple DAC, and connect that to the control input of the VCXO. The higher the PWM duty cycle, the higher the frequency.I used to use these all the time to synchronise clocks in telephony and on synchronous serial interfaces - worked a treat.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 09, 2020, 11:06:39 pm
content: Quote from: frogblender on May 08, 2020, 06:49:18 amHow many ppm do you need to lock to ?Or is an average good enough, and you need to get some sample count match per day ?Such Analog-domain corrections are done in some RTCs, there they switch a cap in/out on a rate-multiplier at say 1ms cadence, and a 256 repeat gives 8 bits of trim.PWM can also be used, but rate multiplier has higher modulation so better averages.The Xin pin usually has a higher ppm/pF pull than the Xout pin.You could try a IO pin between Analog-in (floats), and CMOS gnded, or use a small FET / analog switch.If the MCU has a DAC. you could experiment with a varicap diode thus making a VCO.Or, if drift matters you may like to drop the Xtal and use a VCTCXO as those will 'hold lock' much better than a xtal.The GPS ones are quite cheap. (19.2MHz, 26MHz, 38.4MHz)

author: abraxalito
author_rank: Contributor
timestamp: May 11, 2020, 02:59:09 am
content: As you've already gone for an STM32F4 this may only be of academic interest but I've just noticed NXP's latest M33 (LPC55 series) has what they call a 'Cap bank API' which allows tweaking the capacitance of its two XTAL OSCs.

author: mac.6
author_rank: Regular Contributor
timestamp: May 11, 2020, 04:04:53 pm
content: Lot of RF enabled micro (BLE and such) have a dedicated xtal for radio that can be trimmed.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 11, 2020, 04:12:31 pm
content: STM23F4 has oscillator drive strength options, I forget if it has capacitance loading options as well?If nothing else, a varactor (or if you don't want a proper varactor, some schottky diodes can be used all the same) can be put to one side or the other, and the bias voltage set by IO pin, say by PWMDAC (so, PWM channel, slow RC filter, varactor bias).Tim

author: dietert1
author_rank: Super Contributor
timestamp: May 11, 2020, 05:08:57 pm
content: Many MSP430 chips include switchable adjustment capacitors for one of the crystal oscillators. As far as i remember there are like 4 sets of caps with roughly binary relation, so one would have a choice of sixteen frequencies. Don't remember though whether oscillator supports fine-tuning while running.Regards, Dieter

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 15, 2020, 04:06:23 pm
content: In HF stuff it (used to be?) common to use diodes as tunable capacitors with a DC voltage.I forgot their name. Varicaps, varactor?You can use PWM with RC to get a DC voltage to tune the capacitor.but still, using a better external XCO may be a better option.

author: MosherIV
author_rank: Super Contributor
timestamp: May 15, 2020, 07:24:58 pm
content: Instead of trying to control the drift of the xtal from the microJust minimise the drift of the xtal !You get drift for 2 main reasons 1) temperature 2) aging.Aging is defined in the data sheet.Temperature can be controlled or adjusted for.Get a tcxo or even better oven controller crystal oscillator (ocxo)Even better, get yourself a gps dissiplined oscillator (gpsdo)