Author Topic: Microcontroller tweaks its own crystal ??  (Read 1835 times)

0 Members and 1 Guest are viewing this topic.

Offline frogblenderTopic starter

  • Regular Contributor
  • *
  • Posts: 128
Microcontroller tweaks its own crystal ??
« on: May 08, 2020, 06:49:18 am »
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.
 

Offline dermeister

  • Contributor
  • Posts: 27
  • Country: us
Re: Microcontroller tweaks its own crystal ??
« Reply #1 on: May 08, 2020, 06:53:08 am »
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
 

Offline Daixiwen

  • Frequent Contributor
  • **
  • Posts: 352
  • Country: no
Re: Microcontroller tweaks its own crystal ??
« Reply #2 on: May 08, 2020, 07:04:30 am »
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?
 
The following users thanked this post: I wanted a rude username

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13748
  • Country: gb
    • Mike's Electric Stuff
Re: Microcontroller tweaks its own crystal ??
« Reply #3 on: May 08, 2020, 08:54:29 am »
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
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4228
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: Microcontroller tweaks its own crystal ??
« Reply #4 on: May 08, 2020, 10:47:36 am »
This is exactly the sort of application for which a VCXO is used, like this one for 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.

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 1549
  • Country: au
Re: Microcontroller tweaks its own crystal ??
« Reply #5 on: May 09, 2020, 11:06:39 pm »
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.

How 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)

 
 

Offline abraxalito

  • Newbie
  • Posts: 5
Re: Microcontroller tweaks its own crystal ??
« Reply #6 on: May 11, 2020, 02:59:09 am »
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.
 

Offline mac.6

  • Regular Contributor
  • *
  • Posts: 225
  • Country: fr
Re: Microcontroller tweaks its own crystal ??
« Reply #7 on: May 11, 2020, 04:04:53 pm »
Lot of RF enabled micro (BLE and such) have a dedicated xtal for radio that can be trimmed.
 

Online T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21697
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
Re: Microcontroller tweaks its own crystal ??
« Reply #8 on: May 11, 2020, 04:12:31 pm »
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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 

Offline dietert1

  • Super Contributor
  • ***
  • Posts: 2074
  • Country: br
    • CADT Homepage
Re: Microcontroller tweaks its own crystal ??
« Reply #9 on: May 11, 2020, 05:08:57 pm »
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
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3367
  • Country: nl
Re: Microcontroller tweaks its own crystal ??
« Reply #10 on: May 15, 2020, 04:06:23 pm »
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.
 

Offline MosherIV

  • Super Contributor
  • ***
  • Posts: 1530
  • Country: gb
Re: Microcontroller tweaks its own crystal ??
« Reply #11 on: May 15, 2020, 07:24:58 pm »
Instead of trying to control the drift of the xtal from the micro

Just 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)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf