cancel
Showing results for 
Search instead for 
Did you mean: 

Need to know capability of STM32L073RZ board for generating sinusoidal 12.5 MHz burst signal.

Dineshkumar
Associate II

Hi All ,

I want to generate the following specification of the burst signal from the STM32L073RZ board  , need to know is that possible? Or else need your valuable suggestion whether it is possible from other STM32 boards?

 Parameters

Values /Settings

Waveform

Sine

Offset

0V

Phase

0 deg

Amplitude

 2mV

Frequency

12.5MHz

Burst Cycle #

 150

Trigger

 External

Load Impedance

 50 ohm

 

 

26 REPLIES 26

How do you try to get a sinusoidal signal with 12.5 MHz on your MCU/board?

Using the MCU internal DAC?

As I see in STM32L073xx datasheet: the DAC has a max. update rate of 1 MSps (page 114/163).

Considering the Nyquist criteria (Shannon Theorem): you need 2xfs, so two values per period: this can generate just 500 KHz. But it would look like a tri-angular signal (not a sine wave).

For a nice 12.5 MHz sine wave, out of a DAC, you might need (at least) 10 samples per period: so, the DAC has to support 12.5 MHz * 10 - 125 MHz as update rate.
But 10 samples per period is still pretty bad - a huge THD (not a smooth sine wave yet).

Or, as other have mentioned here: you generate 12.5 MHz as digital - but you have to do an external low pass filter: the cut-off frequency is somewhere at 15 MHz: your sine wave might be attenuated (check the need for the 3dB cut-off frequency and how "sharp" your filter has to be, maybe N-orders).
With a simple 1-order RC filter, used to "smooth" the 12.5 MHz to a sine wave - you will get so many harmonics into the resulting signal (still almost a rectangle).

Also a simple "cross-check":

  • your MCU runs with 32 MHz - the MCU core clock
  • but you want to get a 12.5 MHz sine wave (never mind if via DAC or as digital GPIO and low-pass filter afterwards)
  • 12.5 MHz is already 2.5 MCU clock cycles ONLY!
  • how can you write so fast to any peripheral (like a GPIO pin, for 12.5 MHz rectangle, or even every 2 MCU clock cycles to a DAC with a new value)?

IMPOSSIBLE!

Assume, you need at least 3..5 clock cycles just to do one simple C-code line as instruction. You are already "behind" the speed you need for ANY 12.5 MHz signal (even it would be a rectangle signal on a GPIO pin).

NO WAY!

For a sine out of a DAC, with 12.5 MHz - you had to write (at least) 10 values per period, so with 125 MHz a new value into the DAC. But this is already way above your MCU core clock.

And even trying to toggle a GPIO pin with 12.5 MHz on an MCU which runs "just" with 32 MHz - quite impossible (and it would be a "full speed looping" - nothing else can be done).

 

Hi tjaekel , Thanks  a lot for your detailed explanation . Any other way this can be achieved? Please help.

Also any other STM32 board will full-fill my request? Please guide.

Good question: potentially NOT possible with any STM32 MCU.

I have checked the STM32H745/755 and STM32H747/757 MCU (I am using); Even the MCU core runs very fast (480 MHz) - the DAC is still at 1 MSps.

For 12.5 MHz sine out of a DAC (without external low pass filtering) you might need a "Video DAC" or a "High Speed DAC", potentially with parallel interface.

Again:
With a DAC which should generate a sinus wave, at least 2xfS *rectangle), but better 10 samples per period (a bit more line a sine wave):
So, your DAC needs 125 MSps.
And still very questionable if you can write 10 samples every 1/12.5 MHz - even with a 480 MHz MCU:  10 * 12.5 MHz is already 125 MHz, 480 MHz and 125 MHz is still a ratio of 3.84 (MCU cycles per instructions). You had still to write every C-code line as filling the DAC (even it would be there, as an external unit - but if your external interface really so fast???)

So, I think:

  • 12.5 MHz as sine wave
  • can maybe be done via writing a GPIO pin: for a rectangular signal - but even generating a 12.5 GPIO signal is very tough: and potentially impossible:
    Even on an NXP MCU running at 1 MHz and supporting "direct coupled GPIOs" - this speed was not possible (250 Mbps was max as GPIO pin).
  • Assuming, you could generate a 12.5 MHz on a regular GPIO pin - just try if it is possible - as a rectangle pulse
  • you had to filter externally (to smooth it down to a sine wave)
  • and you might need a complex analog filter (N-degrees), even with fast OpAmps (with a bandwidth of 12.5 MHz * 10 = 125 MHz)

I think: you cannot get a 12.5 MHz sine out from any MCU. You need external HW support:

You could consider to add an FPGA as HW accelerator, but even this one with a DAC inside for 125 MHz sine generated - quite unlikely. But a FPGA could generate a much faster rectangle with 12.5 MHz (and then an external low pass filter).

Just check out which DAC are on the market supporting 12.5 MHz:
And remember: sample rate, as 12 MSps is not enough! You need at least 10x (for a sine, writing 10 values per period) - so, a DAC with 120 MSps is needed. Hard to find any (except Video DACs with parallel interface, yes: you could consider the use an external DAC with a parallel interface - this would speed up, but it does not solve the issue that MCU is not fast enough to write a new DAC value).

Why do you need such a 12.5 MHz signal (as burst)?

Other option:

You use an external OSC (XTAL logic), generating the 12.5 MHz: the MCU can "gate" this signal (to generate the burst): a GPIO signal can disable an analog switch where the generate sine wave goes through.

Or use an external PLL chip, generating clocks: start and stop the PLL chip...

If it is just a fix 12.5 MHz sine wave signal: create a XTAL, OSC providing a 12.5 MHz sine wave. And you feed this analog signal through an analog switch: your MCU can control (gate) the analog switch with a simple GPIO pin: you switch the pass-through on or off (as bursts).

Since DAC is not the viable option in my case, I just tried generating the 16.0 MHz PWM signal ( square wave) using STM32 L073RZ timer. The maximum PWM frequency I could achieve only 560 Khz ( I had set PSC = 0 and Period = 2) . For this setting, I supposed to get 16 MHz PWM signal frequency correct? But I am getting very less , can someone direct me where I am doing wrong? The timer frequency configured for 32 MHz.

An external 12.5 MHz XTAL, generating the sine wave. Feed it through an analog switch and control this switch (On or Off) via an MCU GPIO pin.

If the frequency has to be variable: use an external PLL chip (and set the frequency, e.g. via I2C from MCU).

I have used external PLL chips a while back (for audio applications, needing a Word Clock). Not very difficult, just a bit external HW.

I am not bit clear , I need to solder the XTAL 12.5 MHz into the STM32 L073RZ board and generate the PWM square signal and then using LPF to get the sine wave? Is my understanding correct?

In datasheet for this MCU I see: max. TIM frequency is 16 MHz as external (getting a signal, page 117/163).

It should generate with tTIMxCLK (e.g as 32 MHz). It should be able to generate "almost" 32 KHz (see "timer resolution time as 31.25 ns).

If you get such a low frequency: TIM peripheral clock is wrong (not 32 MHz) and the timer value is too large (assuming for this max. frequency the counter value/pre-load value is 1 or even 0).

I would also assume: even you get 32 MHz as rectangle out from PWM (TIM) - how to set for 12.5 MHz?
This is not an integer ration!
You might be able to configure 32 MHz, 16 MHz, 8 MHz - but nothing in between (it is a fractional ratio to become 12.5 MHz). Dividers, counters, pre-load values - all are integers - no way to get 12.5 (out from 32 MHz  just with integer ratios as division).

So , you are telling external XTAL of 12.5 Mhz will work? Please confirm.

Your "problem" is not trivial:

OK, assuming, with 32 MHz MCU core clock you could generate a 32 MHz using PWM (but I think it is a bit less, as I understand the datasheet). OK, you tweak PWM (e,g, for generating 31,xx MHz). Now you change the MCU XTAL to 12.xxx MHz, so that PWM generates 12.5 MHz. Maybe, but is slows down entire FW as well.
And: it affects also how do you have to configure the PWM now: now the PWM clock is different. OK, you could assume with all the same settings the PWM goes down to 12.xxx MHz . But what if the PWM generates just 11.xxx MHz now? DO you want to tweak the XTAL until all seems to be OK?

And you have still the issue that the PWM, even now with 12.5 MHz is a rectangle pulse: you have to filter "heavily" to get a nice sine out of it (a multi-degree low pass filter, not just a simple RC-circuit, still keeping all the harmonics in the signal for a certain degree, it might look like a "smeared recaangle" instead of a sine wave). Filtering 12.5 MHz rectangle to 12.5 MHz "real" sine - it would be a heavy analog circuit outside the MCU).

And: what does "burst" means?

If you want to be in sync with this sine wave? For instance: you want to enable Out when sine goes through the level 0 (and vice versa to switch Off if sine wave is at level 0)? Whhaauuu, how to do?

How many periods of sine periods during the burst? (to be in sync with the sine wave periods?)

All is very delicate and maybe unable to accomplish with MCU and SW: "how to be in sync with the generated waveform?" (even it would be generated by MCU itself?)

Even using a simple analog switch, and a sine wave going through it - just On or Off on the switch, but not "synchronized" with the sine wave itself - randomly (e.g. not On or Off when sine is at level 0) - it will create a lot of harmonics: if you switch On or Off if sine wave is not at level 0 - a lot of spurious frequencies are generated. Is this acceptable?

And to be in sync with sine wave (just start and stop the burst when sine wave level is 0) - is never guaranteed!

If you need really a "sine wave burst generator": the only option I see: use an external FPGA doing all this: the FPGA might be able to be in sync with the sine wave, to generate N periods and to switch On and Off when sine is crossing the value 0 (avoiding spurious frequencies). And control this FGA via MCU, e.g. via SPI, sending commands to start and stop "sine wave burst".