AnsweredAssumed Answered

STM32F031 PWM input capture without CubeMx.

Question asked by alexandre fortier on May 3, 2018
Latest reply on May 6, 2018 by dhenry

Hello I am Alexandre,

I am working on STM32F031C4T6

I succeed to read the duty cycle and period of PWM on port PA8

I tried to do the same on port PA4, PA6, PA7, PB0, PB1, PB10 and PB11, but it is not working at all.

 

Here my working code on PA8:

/*************************************************************************************************/

//Initialisation for GPIOA

RCC->AHBENR |= RCC_AHBENR_GPIOAEN;

 

//Work for PA5/8/9

GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER4 | GPIO_MODER_MODER8
| GPIO_MODER_MODER9)) | GPIO_MODER_MODER4_1
| GPIO_MODER_MODER8_1 | GPIO_MODER_MODER9_1;

 

GPIOA->AFR[0] |= 0x02 << (5 * 4);
GPIOA->AFR[1] |= 0x02 | (0x02 << ((9 - 8) * 4));

 

//Initialisation for TIM1

RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; 
TIM1->CR1 |= TIM_CR1_CEN; 
TIM1->CCMR1 |= TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_1; 
TIM1->SMCR |= TIM_SMCR_TS_2 | TIM_SMCR_TS_0 
                        | TIM_SMCR_SMS_2;
TIM1->CCER |= TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC2P; 
TIM1->DIER |= TIM_DIER_CC1IE;

/*************************************************************************************************/

With this code i can get the dutry cycle on CCR2 and the period on CCR1.

 

 

Here below the code for PB1 and PB0 which is not working:

/*************************************************************************************************/

//Initialisation for GPIOB

RCC->AHBENR |= RCC_AHBENR_GPIOBEN; //active l'horloge du GPIOB

 

GPIOB->MODER = (GPIOB->MODER & ~(GPIO_MODER_MODER0 | GPIO_MODER_MODER1))
                                   | GPIO_MODER_MODER0_1| GPIO_MODER_MODER1_1 ;

GPIOB->AFR[0] |= 0x02 << (1 * 4);
GPIOB->AFR[0] |= 0x02 << (0 * 4);

 

//Initialisation for TIM3

RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
TIM3->CR2 |= TIM_CR2_TI1S;
TIM3->CR1 |= TIM_CR1_CEN;
TIM3->CCMR1 |= TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_1;

TIM3->SMCR |= TIM_SMCR_TS_2 | TIM_SMCR_TS_0
| TIM_SMCR_SMS_2;
TIM3->CCER |= TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC2P;
TIM3->DIER |= TIM_DIER_CC1IE;

/*************************************************************************************************/

 

I want to receive the duty cycle and the period on every port, can you help me?

I am beginner on micro programming thanks for your help. =)

Outcomes