2021-01-16 10:50 AM
Hi,
I have NUCLEO-G071RB board . How to calculate 1KHz frequency with STM32G071 Output compare ?
My System Clock frequency is 64 MHz .
--
Karan
Solved! Go to Solution.
2021-01-19 03:27 AM
// GPIOx_MODER - 2 bits per pin
#define GPIO_Mode_In 0x00 // GPIO Input Mode
#define GPIO_Mode_Out 0x01 // GPIO Output Mode
#define GPIO_Mode_AlternateFunction 0x02 // GPIO Alternate function Mode
#define GPIO_Mode_AF GPIO_Mode_AlternateFunction
#define GPIO_Mode_Analog 0x03 // GPIO Analog Mode
GPIOB->MODER = (GPIOB->MODER & ~(0
| GPIO_MODER_MODE6
)) | (0
| (GPIO_Mode_Out * GPIO_MODER_MODE6_0)
);
2021-01-16 11:45 AM
timer frequency = (timer clock) / (PSC + 1) / (ARR + 1)
PSC is "Prescaler", ARR is "Period"
So for a 64 MHz timer:
prescaler=63
period=999
And for 50% duty cycle, set pulse = (ARR + 1) / 2 = 500.
2021-01-16 10:21 PM
Thanks... But...
These calculation gives 500Hz instead of 1KHz on Digital Storage Oscilloscope.
F = 64/(63 + 1) /999 + 1 ;
F = 1/1000 ;
T = 1000
While below calculation gives 1KHz.
prescaler = 63 ;
period = 499 ;
pulse = 499 ;
Why so ?
2021-01-16 10:46 PM
It is simle. In one timer period comes one Compare event. If you toggle output on compare event you have one toggle per (timer) period. To generate square wave you need two toggles (rising edge and falling edge). Whole period of your waveform takes two periods of timer. TDK suggest you both situations that you are describing (probably because your question was unclear - asking for 1kHz square wave or 1kHz Copmare events).
2021-01-16 11:38 PM
Thanks Sorry ...
But I am asking for 1KHz Square wave.
--
Karan
2021-01-16 11:44 PM
Ok. And you have (period 499, prescaler 63, pulse can be any value from 0 to 499).
2021-01-17 12:38 AM
Thanks for clarification ..
But what is role of Pulse "Register" in any case.?
Karan
2021-01-17 12:42 AM
It has many roles depending on output mode. For example can store duty cycle value in PWM modes, pulse width in one-pulse mode, phase shift if toggling on multiple outputs etc. Read STM32G071 Reference manual ...
2021-01-17 07:34 AM
> Why so ?
You have toggle on match mode. Set it to PWM mode, or double the frequency.
2021-01-18 09:57 AM
Thanks for update.
If I have 1KHz (1ms) square wave output with output compare.
Will it possible to switched off Output Compare module
in between say 356 us and it should low untill next start of output compare.
---
Karan