2015-12-01 3:56 PM
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 ARCC_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?2015-12-01 4:31 PM
Wouldn't this hold the timer in reset?
rccptr->APB1RSTR |= RCC_APB1RSTR_TIM3RST;2015-12-02 11:40 AM
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.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.