cancel
Showing results for 
Search instead for 
Did you mean: 

speed of Tim8 vs. Tim4

developer2
Senior
Posted on July 03, 2013 at 01:44

Hi all,

i'm using STM32F407 with 12MHz ext. crystal with 168MHz system clock, i use demo for STM32F4Discovery,

i configured Timer4 and Timer8 in same way,

specifically: ARR=1, PSC=0, CKD=0,

and i'm measuring 42MHz on both timers,

is it something worng configured ?

Timer8 is on APB2 so it should be twice faster than Timer4 , shouldn't be ?

please help me to understand,

Kind regards,

6 REPLIES 6
Posted on July 03, 2013 at 03:02

I suspect something is not as it should be, though one could certainly configure the APB at the same speed (/4). You'd have to present some code, along with system_stm32f4xx.c, as guessing is a pointless exercise.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
developer2
Senior
Posted on July 03, 2013 at 09:41

so , during normal run i see registers:

RCC_CFGR: 0000940A

CR: 0F039783

PLLCFGR: 0740540C

and it corresponds this source:

    /* HCLK = SYSCLK / 1*/

    RCC->CFGR |= RCC_CFGR_HPRE_DIV1;

      

    /* PCLK2 = HCLK / 2*/

    RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;

    

    /* PCLK1 = HCLK / 4*/

    RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;

in docs is written that sysclk could be maximum 168MHz, APB2 84MHz (so it's DIV2 ), APB1 42MHz (so it's DIV4)

update:

i tried to change from DIV2-> DIV4:

RCC->CFGR |= RCC_CFGR_PPRE2_DIV4;

so register changed: RCC_CFGR: 0000B40A

but i still measure 42MHz on both :( nothing changed :(

is there something wrong ?

Posted on July 03, 2013 at 10:53

Post a minimal but complete, compilable example of code exhibiting the problem.

JW
developer2
Senior
Posted on July 03, 2013 at 11:18

well PLL initialization is from demo, i didn't change anything,

here is code for timers:

GPIO_InitTypeDef  GPIO_InitStructure;

RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOD, ENABLE);

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14;

GPIO_Init( GPIOD , &GPIO_InitStructure);

RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM4, ENABLE);

GPIO_PinAFConfig( GPIOD, GPIO_PinSource14,  GPIO_AF_TIM4 );

GPIO_PinAFConfig( GPIOD, GPIO_PinSource15,  GPIO_AF_TIM4 );

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_Init( GPIOD , &GPIO_InitStructure);

RCC_APB2PeriphClockCmd( RCC_APB2Periph_TIM8, ENABLE);

RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOC , ENABLE);

GPIO_PinAFConfig( GPIOD, GPIO_PinSource6,  GPIO_AF_TIM8 );

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

GPIO_Init( GPIOC , &GPIO_InitStructure);

#define ADC_CLK_TIM     TIM4

#define ADC_CLK_TIM_ALT TIM8

TIM_Cmd( ADC_CLK_TIM, DISABLE);

TIM_CtrlPWMOutputs( ADC_CLK_TIM, DISABLE );

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

TIM_OCInitTypeDef TIM_OCInitStructure;

TIM_TimeBaseStructure.TIM_Period = 1;

TIM_TimeBaseStructure.TIM_Prescaler = 0x00;

TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit( ADC_CLK_TIM, &TIM_TimeBaseStructure);

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

TIM_OCInitStructure.TIM_Pulse = 1;  /* Duty cycle: 50%*/

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OC3Init( ADC_CLK_TIM, &TIM_OCInitStructure);

TIM_OC3PreloadConfig( ADC_CLK_TIM, TIM_OCPreload_Enable);

TIM_OC4Init( ADC_CLK_TIM, &TIM_OCInitStructure);

TIM_OC4PreloadConfig( ADC_CLK_TIM, TIM_OCPreload_Enable);

TIM_CtrlPWMOutputs( ADC_CLK_TIM, ENABLE );

TIM_Cmd( ADC_CLK_TIM, ENABLE);

TIM_TimeBaseInit( ADC_CLK_TIM_ALT, &TIM_TimeBaseStructure);

TIM_OC1Init( ADC_CLK_TIM_ALT, &TIM_OCInitStructure);

TIM_OC1PreloadConfig( ADC_CLK_TIM_ALT, TIM_OCPreload_Enable);

TIM_CtrlPWMOutputs( ADC_CLK_TIM_ALT, ENABLE );

TIM_Cmd( ADC_CLK_TIM_ALT, ENABLE);

Posted on July 03, 2013 at 12:09

> GPIO_PinAFConfig( GPIOD, GPIO_PinSource6,  GPIO_AF_TIM8 );

?

JW

developer2
Senior
Posted on July 03, 2013 at 12:48

oh :( .........................................................................

.........................

wrong initialization :(

so issue solved,

thank You,