cancel
Showing results for 
Search instead for 
Did you mean: 

MCO on/off modulation, STM32F334: What's the fastest way to switch MCO between off state and a clock source.

DRH
Associate III

Is there a fast way to use MCO, mux it to an internal clock souce and use a timer to realize some kind of on/off modulation of the MCO pin?

I muxed it to an internal source and tried switching the GPIO between input and output. This works fine but needs a lot of clock cycles. Therefore I'm wondering if there is an easier way, maybe with another mux or switch. I thought about GPIO locking as well but If I understand the manual right, that's not an option because of the necessary reset.

Is there another way or register to freeze the GPIO for a short duration controlled by a timer (and maybe a DMA)?

Are there other options for high speed on/off keying. Carrier will be about 20MHz and modulation about 50kHz.

Maybe to clarify my question. An external digital gate (AND) will provide the same functionality if MCO is muxed to a source (20MHz) , a timer output is providing 50kHz and both are connected to the gate input. Unfortunatley I don't have this external gate.

4 REPLIES 4
berendi
Principal

How is your clock system set up? I assume the system runs on 40 MHz, and you are halving that frequency on the MCO prescaler. Is there another way?

It should be possible to change the GPIO MODER register through two DMA channels triggered by a timer, but there would be still sime jitter. There are other ways.

You can use two general purpose (or advanced) timer in a master-slave configuration.

Configure the master timer first to output the modulating (lower frequency) signal in PWM mode 2, but do not enable the counter yet. Set the MMS bits in CR2 to the OCxREF signal of the modulating channel. It is not necessary to map the signal to an actual pin, although it could be useful for troubleshooting. Using TIM1 as the master allows some more flexibility if you want to play with the modulating frequency/duty cycle later. The active duty phase should be an integer multiple of the slave frequency so that the slave would always stop at the same phase.

Configure the slave timer to gated mode, PWM with 20 MHz frequency. Start the slave counter first, then the master.

The order of operations is important. Configuring the master first holds the gate in the inactive state until the slave is configured, and it will be started synchronized to the trigger signal.

DRH
Associate III

Hi Berendi,

thank you very much for your quick response. Right, the idea is to have an external crystal of about 40MHz and have an additional divider of 2 or 4. The divided frequency will be the carrier frequency. We have to switch on/off this carrier for a controllable on/off modulation and the idea is to use a timer for that. In best case, the compare value of this timer triggers a DMA that switches off the MCO output. I didn't find this functionality with the GPIO moder register but I will check

this tomorrow. Do you have an idea what's the fastest way to stop the GPIO for a defined time?

The idea with the two timers will work. Currently I try to safe as much timers as possible for other functionality but maybe it's the best idea and we have to find another solution for the additional things? Will think about it, thank you!

Check out the burst mode controller of HRTIM too. I haven't used HRTIM myself, but I think it might provide an even better solution, it should be able to generate a 20 MHz signal even if the rest of the system runs on 72 MHz.

DRH
Associate III

Dear Berendi,

thanks again. I didn't know that the MCO provides the "LL_RCC_MCO1SOURCE_NOCLOCK" state. Changing the RCC->CFGR register with a DMA works pretty well and fast enough. Thank you for your support.