cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G030K6T6 with PWM

Sudhakar.R
Associate III

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)

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

7 REPLIES 7
Sarra.S
ST Employee

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.

Sudhakar.R
Associate III

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.

> 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

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

Sudhakar.R
Associate III

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

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

Sudhakar.R
Associate III

@Community member​ 

Thank you for reply. i got the output.