Skip to main content
Associate III
April 24, 2023
Solved

STM32G030K6T6 with PWM

  • April 24, 2023
  • 7 replies
  • 1760 views

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)

This topic has been closed for replies.
Best answer by waclawek.jan

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

7 replies

ST Employee
April 24, 2023

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.
Associate III
April 24, 2023

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.

waclawek.jan
Super User
April 24, 2023

> 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

Michal Dudka
Lead
April 24, 2023

You've probably swap PSC and ARR values...

Associate III
April 25, 2023

I changed PSC = 1 and ARR = 2000 still pwm is not generate.

waclawek.jan
waclawek.janBest answer
Super User
April 25, 2023

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

Associate III
April 26, 2023

@Community member​ 

Thank you for reply. i got the output.