cancel
Showing results for 
Search instead for 
Did you mean: 

PWM registers of timers problem APB1 and alternative function NUCLEOF303RE

FilipF303RE
Associate II

Hi,

I'm encountering several issues with my timers. Firstly, my timers, specifically Timer3 which is connected to APB1, aren't functioning as expected. I've also attempted to use Timer16, which operates on a clock derived from another peripheral communication bus. However, the main issue seems to be with the RCC clock for my communication bus, as it doesn't appear to be functioning properly.

I've verified the functionality of Timer3 by testing it with an external interrupt handler, but it still doesn't seem to be working correctly. Additionally, I've implemented PWM (Pulse Width Modulation) functionality, but it hasn't yielded the expected results.

Furthermore, I'm encountering difficulties with configuring alternate functions. Specifically, I'm struggling to set the appropriate bits in the AFR (Alternate Function Register).

 

I would greatly appreciate any assistance or guidance as I strive to become proficient in embedded programming. 

void configPWMPA6(void)

{

RCC -> AHBENR |= RCC_AHBENR_GPIOAEN;

//GPIOA -> MODER |= GPIO_MODER_MODER6_1;

GPIOA -> MODER &= ~(GPIO_MODER_MODER6_0);

GPIOA -> MODER |= GPIO_MODER_MODER6_1;

GPIOA -> AFR[0] |= GPIO_AFRL_AFRL6_0; //Not working Reset value 0x00000

//GPIOA -> AFR[0] &= ~(GPIO_AFRL_AFRL6_Msk);

GPIOA -> AFR[0] |= (1<<24);

}

 

#include "stm32f303xe.h"

#include "stdint.h"

#include "stm32f3xx.h"

 

void TIM3_BaseCONFIGURATION(void)

{

RCC -> APB1ENR |= RCC_APB1ENR_TIM3EN;

TIM3-> PSC = 36;

TIM3-> ARR = 100;

}

 

 

void TIM3_START(void)

{

TIM3-> CNT =0;

TIM3-> CR1 |= TIM_CR1_CEN;

}

void TIMER_UPDATE(void)

{

TIM3-> DIER |= TIM_DIER_UIE;

NVIC_SetPriority(TIM3_IRQn,0);

NVIC_EnableIRQ(TIM3_IRQn);

 

}

void TIM3_HANDLER(void)

{

if(TIM3->SR & TIM_SR_UIF)

{

TIM3->SR &= ~(TIM_SR_UIF);

 

}

}

//PC13 Button

//0 push /1 set

//PA2_TX

//PA3_RX

//AF7 0111

// 115200

//36 000 000 prescaler 2??? MAX ABH1=F

 

int main(void)

{

SysTick_Config((72000000/ 1000));

TIM3_BaseCONFIGURATION();

TIMER_UPDATE();

TIM3_START();

 

 

//1s = 72 000 000

// 0,001 = x

/* Loop forever */

 

while(1)

{

 

}

 

}

1 REPLY 1
nouirakh
ST Employee

Hello @FilipF303RE 

To reproduce the same problem that you encounter specifically with TIM3. I have tested this project:
Projects\STM32F303RE-Nucleo\Examples\TIM\TIM_PWMInput
You can find the example by clicking on this link to Github:
https://github.com/STMicroelectronics/STM32CubeF3/tree/master/Projects/STM32F303RE-Nucleo/Examples/TIM/TIM_PWMInput 

This example Use the TIM peripheral to measure the frequency and The TIM3CLK frequency is set to SystemCoreClock (Hz), the Prescaler is 0 so the counter clock is SystemCoreClock (Hz).
SystemCoreClock is set to 64 MHz for STM32F303xE Devices. TIM3 is configured in PWM Input Mode: the external signal is connected to TIM3 Channel2 used as input pin. To measure the frequency and the duty cycle, we use the TIM3 CC2 interrupt request, so in the TIM3_IRQHandler routine, the frequency and the duty cycle of the external signal are computed.

In this example, the TIM 3 works correctly, you can be inspired by this example to configure alternative functions.
If the problem persists, please provide more details on your setting project if possible, attach a ZIP of your project configuration.