AnsweredAssumed Answered

Output pin cannot be changed Timer10 PWM.

Question asked by virtanen.pentti on Feb 15, 2012
Latest reply on Feb 16, 2012 by malund.erik
Hi I have trying to use TIM10_PWMOutput examples from STM32F2xx Standard Peripherals Firmware Library.  It works very well but if I try to using the other output pin than GPIO_Pin_6 the output is quit.
The Port Pin 6 is works well but Pin 3 is quit.  I have also trying to using only Pin 3 but it doesn't work.
Could anybody help me, please?
I'm using the STM3220G-EVAL evaluation board and I have also tried this example with our own board but it is same case, doesn't work.
What I have missed or understand wrong?
/**
  ******************************************************************************
  * @file    TIM/TIM10_PWMOutput/main.c
  * @author  MCD Application Team
  * @version V1.0.0
  * @date    18-April-2011
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
  ******************************************************************************
  */
 
/* Includes ------------------------------------------------------------------*/
#include "stm32f2xx.h"
 
/** @addtogroup STM32F2xx_StdPeriph_Examples
  * @{
  */
 
/** @addtogroup TIM10_PWMOutput
  * @{
  */
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define TIMER   TIM10
 
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;
uint16_t CCR1_Val = 233;
uint16_t PrescalerValue = 0;
uint16_t TimerPeriod = 0;
uint16_t Channel1Pulse = 0, Channel2Pulse = 0, Channel3Pulse = 0, Channel4Pulse = 0;
 
/* Private function prototypes -----------------------------------------------*/
void TIM_Config(void);
 
/* Private functions ---------------------------------------------------------*/
 
void Delay(__IO uint32_t nCount)
{
  while(nCount--)
  {
  }
}
 
 
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f2xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f2xx.c file
     */
 
  /* TIM Configuration */
  TIM_Config();
 
  //test();
 
  /* -----------------------------------------------------------------------
    TIM10 Configuration: generate 1 PWM signal:
    The TIM10CLK frequency is set to SystemCoreClock (Hz), to get TIM10 counter
    clock at 20 MHz the Prescaler is computed as following:
     - Prescaler = (TIM10CLK / TIM10 counter clock) - 1
    SystemCoreClock is set to 120 MHz for STM32F2xx devices
 
    The TIM10 is running at 30 KHz: TIM10 Frequency = TIM10 counter clock /(ARR + 1)
                                                    = 20 MHz / 666 = 30 KHz
    TIM10 Channel1 duty cycle = (TIM10_CCR1/ TIM10_ARR)* 100 = 50%
 
  ----------------------------------------------------------------------- */
  /* Compute the prescaler value */
  PrescalerValue = (uint16_t) (SystemCoreClock / 20000000) - 1;
 
  /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = 665;
  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 
  TIM_TimeBaseInit(TIMER, &TIM_TimeBaseStructure);
 
  /* PWM1 Mode configuration: Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
 
  TIM_OC1Init(TIMER, &TIM_OCInitStructure);
 
  TIM_OC1PreloadConfig(TIMER, TIM_OCPreload_Enable);
 
  /* PWM1 Mode configuration: Channel2 */
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = CCR1_Val + 80;
 
  TIM_OC2Init(TIMER, &TIM_OCInitStructure);
  TIM_OC2PreloadConfig(TIMER, TIM_OCPreload_Enable);
    
  TIM_ARRPreloadConfig(TIMER, ENABLE);
 
  /* TIM10 enable counter */
  TIM_Cmd(TIMER, ENABLE);
 
  while (1)
  {
        TIM_SetCompare1(TIMER, CCR1_Val+200);
        Delay(0x1234); 
        TIM_SetCompare1(TIMER, CCR1_Val);
        Delay(0x1234);
  }
 
}
 
/**
  * @brief  Configure the TIM10 Ouput Channels.
  * @param  None
  * @retval None
  */
void TIM_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
   
  /* TIM10 clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE);
 
  /* GPIOF clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
   
  /* GPIOF Configuration: TIM10 CH1 (PF6) */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; //GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOF, &GPIO_InitStructure);
 
  /* Connect TIM pins to AF3 */
  GPIO_PinAFConfig(GPIOF, GPIO_PinSource6, GPIO_AF_TIM10);
  GPIO_PinAFConfig(GPIOF, GPIO_PinSource3, GPIO_AF_TIM10);
 
}
 
 
#ifdef  USE_FULL_ASSERT
 
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 
  while (1)
  {}
}
#endif
 
/**
  * @}
  */
 
/**
  * @}
  */
 
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

Outcomes