AnsweredAssumed Answered

Timer issue

Question asked by c.kalhana on Feb 8, 2016
Latest reply on Feb 8, 2016 by dembek.radoslaw.001
Hi,

I'm having an issue setting up TIM1 for PWM on the STM32F446.
In the following code, the PWM works for TIM2 but not for TIM1.

Any ideas?

Thank you.

  RCC->APB1ENR |= (1UL << 0); // TIM2 clock enable
  TIM2->PSC   = 89;               // set prescaler   = 1 MHz
  TIM2->ARR   = 999;              // set auto-reload =  for 1 kHz
  TIM2->CCR2 = 15;                // 1.5% duty cycle


  TIM2->CCMR1 |= 0x6800;
  TIM2->CR1 |= 0x80;  
  TIM2->CCER |= 0x10;
  TIM2->EGR |= 0x01;
  TIM2->CR1 |= 0x01;
  
  RCC->AHB1ENR |= (1UL << 0);       // GPIOA clock enable
  GPIOA->MODER |= (2UL << 2*1);     // PA1  - is alt function
  GPIOA->OSPEEDR |= (3UL << 2*1);   // PA1  - is high speed
  GPIOA->AFR[0] |= (1 << 4);        // PA1 - AF1 mapping
  
//================================================================


  RCC->APB2ENR |= (1UL << 0); // TIM1 clock enable
  TIM1->PSC   = 179;           // set prescaler   = 1 MHz
  TIM1->ARR   = 999;          // set auto-reload =  for 1 kHz
  TIM1->CCR2 = 15;            // 1.5% duty cycle


  TIM1->CCMR1 |= 0x6800;
  TIM1->CR1 |= 0x80;  
  TIM1->CCER |= 0x10;
  TIM1->EGR |= 0x01;
  TIM1->CR1 |= 0x01;
  
  RCC->AHB1ENR |= (1UL << 0);       // GPIOA clock enable
  GPIOA->MODER |= (2UL << 2*9);     // PA9  - is alt function
  GPIOA->OSPEEDR |= (3UL << 2*9);   // PA9  - is high speed
  GPIOA->AFR[1] |= (1 << 4);        // PA9 - AF1 mapping

Outcomes