AnsweredAssumed Answered

Hello forum,  The processor is STM32F072  I got a download of a code snippet that I want to modify. It works great on PA8.  I want the same PWM output on PA9 and PA10. I tried several things but none worked.  Here is the code snippet    /* (1) Enable the

Question asked by Blight.David on Mar 23, 2017

Hello forum,

The processor is STM32F072

I got a download of a code snippet that I want to modify.  It works great on PA8.  I want the same PWM output on PA9 and PA10.  I tried several things but none worked.  Looking for suggestions

Here is the code snippet

/* (1) Enable the peripheral clock of Timer x */
/* (2) Enable the peripheral clock of GPIOA */
/* (3) Select alternate function mode on GPIOA pin 8*/
/* (4) Select AF2 on PA8 in AFRH for TIM1_CH1 */

RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; /* (1) */
RCC->AHBENR |= RCC_AHBENR_GPIOAEN; /* (2) */
GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER8)) | (GPIO_MODER_MODER8_1);/* (3) */
GPIOA->AFR[1] |= 0x02; /* (4) */

 

/* (1) Set prescaler to xx, so APBCLK/48 i.e 48 MHz */
/* (2) Set ARR = 200, as timer clock is 1MHz the period is 50 us */
/* (3) Set CCRx = x, , the signal will be high during 0-199 steps */
/* (4) Select PWM mode 1 on OC1 (OC1M = 110),
enable preload register on OC1 (OC1PE = 1) */
/* (5) Select active high polarity on OC1 (CC1P = 0, reset value),
enable the output on OC1 (CC1E = 1)*/
/* (6) Enable output (MOE = 1)*/
/* (7) Enable counter (CEN = 1)
select edge aligned mode (CMS = 00, reset value)
select direction as upcounter (DIR = 0, reset value) */
/* (8) Force update generation (UG = 1) */

 

TIMx->PSC = 1; /* (1) */
TIMx->ARR = 200; /* (2) */
TIMx->CCR1 = 25; /* (3) */
TIMx->CCMR1 |= TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1PE; /* (4) */
TIMx->CCER |= TIM_CCER_CC1E; /* (5) */
TIMx->BDTR |= TIM_BDTR_MOE; /* (6) */
TIMx->CR1 |= TIM_CR1_CEN; /* (7) */
TIMx->EGR |= TIM_EGR_UG; /* (8) */

Outcomes