PWM generation at very low Duty-cycle
Hello ,
I am using the STM32G0C1RET6 MCU and want to generate the frequency in between 20Khz to 200Khz, with dutycyle in between 1 to 100%, but frequency below 10 percent is not generating, as my CCR value gets 0, due to low ARR value. Am I going in right direction or not I am not getting it, and if have understood the correct use of CCR and ARR registers.
here is a snippet of my code I am using,
for setting the frequency I am using this logic
case TIMER1:
if (freq_input > 100000)
TIM1->PSC = 32-1;
else
TIM1->PSC = 64-1;
new_arr = (HAL_RCC_GetHCLKFreq() / (freq_input * TIM1->PSC)) - 1;
TIM1->ARR=new_arr;
for setting Dutycycle i am using,
uint32_t CCR = ((duty_input) * new_arr) /100 ;
switch(timer) {
case TIMER1:
if (channel == 1)
TIM1->CCR1=CCR;
here, HAL_RCC_GetHCLKFreq = 64MHz.
here using the less or higher prescalar affects the frequency, so i chose accordingly.
