cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0 Output Compare formula (NUCLEO-G071RB)

Karan 123
Senior

Hi,

I have NUCLEO-G071RB board . How to calculate 1KHz frequency with STM32G071 Output compare ?

My System Clock frequency is 64 MHz .

0693W000007BXkMQAW.png 

0693W000007BXkWQAW.png 

--

Karan

20 REPLIES 20
Karan 123
Senior

0693W000007Bk0bQAC.pngWill it possible to switched off Output Compare module like above?

> Will it possible to switched off Output Compare module like above?

Yes, in several ways.

Maybe the most straightforward is to change given pin seeing in GPIO_MODER from AF to OUT.

Our use the Forced Low Output Compare mode in TIMx_CCMRx.

Read the TIM chapter in RM.

JW

It is possible. You can use PWM mode (instead toggle) and set duty cycle to 50% (generating square wave). When you need you can set duty cycle to another value (say 356us) and after single period set it back to 500us (50%). If you have to "shut down" output by external signal, you can use break function (if your ouput is from timer with that feature). You can manually force output to low (search in timer section of reference manual "Forced output mode") whenever you need. And probably there will be another mechanisms.

I don't want to set duty cycle at fixed value ( Say 356us)

I want to switch off either PWM or Output Compare randomly in between.

Karan

"Maybe the . . . ."​

You mean to say change GPIO from Alternate Function to Output or Input what?

Is there any method with HAL library function.?

--

​Karan

You didnt specified what do you exactly want. It is software who decide when and what value should be on timer output ? Or it is external signal (and what is acceptable latency) ? And how signal should behave after that event (holds its value to another event, to end of period, to another SW intervention) ? Meaning your formula "start of output compare" is unclear because "output compare" is event. It has no start or end, it is one moment. Why not to use method described by waclawek.jan (set pin from alternate function (timer controls pin) to output (SW controls pin) and back) ?

> You mean to say change GPIO from Alternate Function to Output or Input what?

You probably want the pin to output a defined level all the time, so from Alternate Function to Output.

> Is there any method with HAL library function.?

I don't know, I don't use Cube/HAL.

JW

How to do that without HAL or at register level.?

-​

Karan​

I want to Switch Off Output Compare any time ​in between 1KHz of square wave .

For Example I want Switched off

Output Compare, When ZCD is detected (On Another pin)

​​--

Karan​

Ok. Use function LL_GPIO_SetPinMode() from LL drivers (can be enabled in CubeMX) to change pin mode from LL_GPIO_MODE_ALTERNATE (timer) to LL_GPIO_MODE_OUTPUT (SW control) and vice versa. Functions LL_GPIO_SetOutputPin() respective LL_GPIO_ResetOutputPin() can be used to set output value (if pin controlled by SW). Both can be done also in register level changing proper bits in GPIOx.MODER register and GPIOx.BSRR register (read reference manual for details). Or google tutorials to working with GPIO on STMs.