2023-04-24 09:18 AM
Hi,
I'm trying to configure the PWm with STM32G030K6T6. But pwm is not generate.
below I given my code and i don't know where i made a mistake if any one know help me.
RCC->IOPENR |= (RCC_IOPENR_GPIOAEN); // I/O port A clock enable
GPIOA->MODER &= ~(GPIO_MODER_MODE8); // clear 8th pin
GPIOA->MODER |= (GPIO_MODER_MODE8_1); // 10: Alternate function mode
/********** TIMER 1 Init **********/
RCC->APBENR2 |= RCC_APBENR2_TIM1EN; // TIM1 CLOCK ENABLE
TIM1->CR1 &= ~TIM_CR1_DIR; //Set Counter Direction as Up-Counter
TIM1->ARR = 1; //ARR VALUE IS 0-65535
TIM1->PSC = 2000-1; //PERSCALER VALUE IS 0-65535
TIM1->CCR1 = 1000; //Duty Cycle
TIM1->CNT = 0; //COUNT START IN 0
TIM1->RCR = 0;
TIM1->CCMR1 |= 0x00000068; //Configure the pins as PWM
TIM1->EGR = TIM_EGR_UG; // Update generation
TIM1->CCER |= TIM_CCER_CC1E; //Capture/Compare 1 output enable
TIM1->BDTR |= (TIM_BDTR_OSSR | TIM_BDTR_MOE); // Off-state selection for Run mode & Main output enable
TIM1->CR1 |= (TIM_CR1_CMS_0 | TIM_CR1_CEN); // COUNTER ENABLE & Center-aligned mode selection (01: Center-aligned mode 1)
Solved! Go to Solution.
2023-04-25 02:54 AM
TIM1_CH1 is AF1 for PA8, so you need to set GPIOA_AFR[1] accordingly.
Generally, if in doubts, read out and check/post content of TIM and relevant GPIO registers.
JW
2023-04-24 09:38 AM
Hello @Sudhakar.R,
it might be helpful to provide more information about your hardware setup and any error messages or behavior you are seeing
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-04-24 10:26 AM
Hi @Sarra.S
I'm using ST - link v2 for debugging and logic analyzer for checking pulse with stm32g030k6t6. And I'm not getting any error message.
2023-04-24 11:59 AM
> TIM1->ARR = 1; //ARR VALUE IS 0-65535
With this setting, TIMx_CNT counts from 0 to 1 and then back to 0. It never reaches TIMx_CCR1 so compare never happens, thus there's no edge on the output signal, exactly as you've observed.
Set TIMx_ARR to a value higher than TIMx_CCR1.
JW
2023-04-24 12:22 PM
You've probably swap PSC and ARR values...
2023-04-24 10:08 PM
I changed PSC = 1 and ARR = 2000 still pwm is not generate.
2023-04-25 02:54 AM
TIM1_CH1 is AF1 for PA8, so you need to set GPIOA_AFR[1] accordingly.
Generally, if in doubts, read out and check/post content of TIM and relevant GPIO registers.
JW
2023-04-25 10:32 PM
@Community member
Thank you for reply. i got the output.