cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 Timers

greenk
Associate
Posted on December 02, 2015 at 00:56

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?
2 REPLIES 2
Posted on December 02, 2015 at 01:31

Wouldn't this hold the timer in reset?

rccptr->APB1RSTR |= RCC_APB1RSTR_TIM3RST;  

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
greenk
Associate
Posted on December 02, 2015 at 20:40

You're right. I didn't read the manual closely enough. I thought setting the bit in the APB1RSTR register would just pulse the timer ''reset'', resetting all of the bits. But that's apparently not how it works. Thanks for the help.