cancel
Showing results for 
Search instead for 
Did you mean: 

TIM4 PWM PROBLEM STM32F3DISCOVERY: PLL_SOURCE_HSE_BYPASS ?

andreaspiezia9
Associate III
Posted on December 29, 2015 at 16:00

Hi all,

I've downloaded the following simple code in my STM32F3DISCOVERY but I don't see anything. Should be a sistem clock config problem?

In main.c:

&sharpinclude ''stm32f30x.h''

 

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

 

void RCC_Configuration(void)

{

  /* Enable GPIO clock */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

 

  /* Enable TIM3/4 clock */

  RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM4, ENABLE);

}

 

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

 

void GPIO_Configuration(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

 

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_10); // TIM4_CH1

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_10); // TIM4_CH2

 

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_11 | GPIO_Pin_12;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

}

 

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

 

void TIM_Configuration(void)

{

  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

  TIM_OCInitTypeDef TIM_OCInitStructure;

 

  TIM_TimeBaseStructure.TIM_Prescaler = 72 - 1; // 72 to 1 MHz

  TIM_TimeBaseStructure.TIM_Period = 10 - 1; // 1 MHz to 100 KHz

  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

 

  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

 

  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

  TIM_OCInitStructure.TIM_Pulse = 10 / 4; // 25%

  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

 

  TIM_OC1Init(TIM4, &TIM_OCInitStructure);

  TIM_OC2Init(TIM4, &TIM_OCInitStructure);

 

  TIM_Cmd(TIM4, ENABLE);

 }

 

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

 

int main(void)

{

  RCC_Configuration();

 

  GPIO_Configuration();

 

  TIM_Configuration();

 

  while(1); // Don't want to exit

}

and I've this in system_stm32f30x.c :

/* Select the PLL clock source */

//&sharpdefine PLL_SOURCE_HSI        // HSI (~8MHz) used to clock the PLL, and the PLL is used as system clock source

//&sharpdefine PLL_SOURCE_HSE        // HSE (8MHz) used to clock the PLL, and the PLL is used as system clock source

&sharpdefine PLL_SOURCE_HSE_BYPASS // HSE bypassed with an external clock (8MHz, coming from ST-Link) used to clock

 

Can you help me?

Thanks in advantage.

#pwm #stm32-mco-clock-output
5 REPLIES 5
andreaspiezia9
Associate III
Posted on January 02, 2016 at 18:40

Hi Clive and Happy New Year.

Thank you very much, I'm investigating and I'll came back with the explanation.

Posted on December 29, 2015 at 21:19

Should be a system clock config problem?

 

Ok, and that relates to the issue how? The system starts with a different clock, you're not saying the PWM is slower, but rather that it doesn't exist. Have you been able to step through the code, and check the pins with a scope? Aren't PA11/12 committed to USB on the F3-DISCO? Check it gets to main() and doesn't get stuck somewhere in SystemInit()

If you want to check internal clocks, output via MCO (PA8)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
andreaspiezia9
Associate III
Posted on December 30, 2015 at 09:19

Thank you Clive,

your comments are really helpful and appreciate. I've checked the pins with the scope. 

I've a question: what does mean ''Aren't PA11/12 committed to USB on the F3-DISCO'' ?

I'd like to check the MCO via PA8, as you suggest, but I have a doubt how to set the TIM_OCInitStructure.TIM_OCMode and the TIM_TimeBaseStructure, can you help me?

Posted on December 30, 2015 at 15:21

Check the Manual/Schematic, aren't the pins you are talking about connected to the USER USB? Does that conflict with your use? Do you need to change solder bridges to get to pins?

void OutputHSE2MCO(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Output HSE clock on MCO1 pin(PA8) ****************************************/
/* Enable the GPIOA peripheral */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* Configure MCO1 pin(PA8) in alternate function */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* HSE clock selected to output on MCO1 pin(PA8)*/
RCC_MCOConfig(RCC_MCOSource_HSE);
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
andreaspiezia9
Associate III