AnsweredAssumed Answered

STM32F0 Timers

Question asked by green.ken on Dec 2, 2015
Latest reply on Dec 2, 2015 by green.ken
I am having trouble creating a PWM output using a timer (timer 3, channel 1). Processor is an STM32F072CB. I'm using the following code:
Note: GPIO clock is enabled for port A

   RCC_TypeDef  *rccptr = RCC;

   // Enable clock to Timer 3
   rccptr->APB1ENR  |= RCC_APB1ENR_TIM3EN;
   rccptr->APB1RSTR |= RCC_APB1RSTR_TIM3RST;   //reset timer 3

   // Configure the pin as timer 3 counter 1 output
   GPIOA->AFR[0] |= 0x01000000;   //pin PA6 - alternate function 1 (TIM3_CH1)
   GPIOA->MODER  |= 0x00002000;   //set PA6 to "alternate function"

   // Configure timer 3 channel 1
   TIM3->CCMR1  = 0x0068;   //PWM mode 1; output; preload enable
   TIM3->CCER   = 0x0001;   //CC1 is output to pin
  
   TIM3->PSC    = 1 - 1;
   TIM3->ARR    = 40000 - 1;
   TIM3->CCR1   = 300;
  
   TIM3->CR1   |= 0x0001;   //start the counter

The issue is that the output pin (pin 16) does not change - always low. What am I missing?

Outcomes