Skip to main content
Skfir
Associate III
April 21, 2023
Solved

NUCLEO-U575ZI unable to activate PWM pin output

  • April 21, 2023
  • 2 replies
  • 832 views

Hi everybody! I keep trying to out a PWM signal, using TIM1 ch1. CC do trigger fine, but the output pin doesn't change. Please help!

void TIMER_init(void){
//PA8 - CH1
	GPIOA->MODER &= ~((3 << GPIO_MODER_MODE8_Pos) + (3 << GPIO_MODER_MODE9_Pos)); //Switching off analog functionality
	GPIOA->MODER |= (2 << GPIO_MODER_MODE8_Pos) + (2 << GPIO_MODER_MODE9_Pos); //^Connect pins to the alternate function multiplexer
	GPIOA->AFR[1] &= ~(255 << GPIO_AFRH_AFSEL8_Pos); //Clearing the alternate function fields
	GPIOA->AFR[1] |= (2 << GPIO_AFRH_AFSEL8_Pos) + (1 << GPIO_AFRH_AFSEL9_Pos); //Connect timer outputs to the pins (Choosing Timer1 outputs as an alternate function)
 
	RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; //Switch on the TIM1 module
	TIM1->PSC = 15; //Timer frequency is divided by 16 (PSC+1)
//Example to start the timer
	TIM1->ARR = 60535;
	TIM1->CCR1 = 32767;
	TIM1->CCMR1 |= (TIM_CCMR1_OC1M_2 + TIM_CCMR1_OC1M_1); //PWM mode 1,
	TIM1->CCER |= TIM_CCER_CC1E; //Enable Compare module CH1 output on the pin PA8
	TIM1->BDTR |= TIM_BDTR_MOE + TIM_BDTR_AOE;	 //Enable "main output" otherwise output won't work
	//**Enabling ch1 interrupt
	TIM1->DIER |= TIM_DIER_CC1IE;
	NVIC_EnableIRQ(TIM1_CC_IRQn);
	//**
	TIM1->CR1 |= TIM_CR1_CEN;	//Starting timer
}

This topic has been closed for replies.
Best answer by Skfir

Found the solution! The thing is the list of alternate functions starts from zero, not from one, haha. So I simply pointed at a wrong function. Now works.

2 replies

waclawek.jan
Super User
April 21, 2023

Is GPIOA clock enabled in RCC?

Read out and check/post TIM and relevant GPIO registers content.

JW

Skfir
SkfirAuthorBest answer
Associate III
April 21, 2023

Found the solution! The thing is the list of alternate functions starts from zero, not from one, haha. So I simply pointed at a wrong function. Now works.