cancel
Showing results for 
Search instead for 
Did you mean: 

Output pin cannot be changed Timer10 PWM.

pentti
Associate II
Posted on February 15, 2012 at 13:50

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****/

5 REPLIES 5
Posted on February 15, 2012 at 14:11

TIM_CtrlPWMOutputs(TIMER, ENABLE);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pentti
Associate II
Posted on February 16, 2012 at 06:06

Thanks Clive1 but this is not solution for this problem.  The TIM_CtrlPWMOutputs function works only with timer 1-8.  And I have also used the other timers but only pin 6 works.  It is also same case with other ports.  Always pin 6 works but pin 3 is quit.  I don't understand that.

pentti
Associate II
Posted on February 16, 2012 at 11:35

Ok, this was my mistake.  I found Document Doc ID 15818 Rev 8 and there is table 7 where is describe all Ports and Pins.  So solution is to change Port and Pin according to the timer.

Example: timer 8-> port C, pin 6, 7, 8, 9.

Posted on February 16, 2012 at 15:47

Yeah, Sorry it was just the 5 second response to get a potential reason for not seeing output at a pin.
 But, the pin muxing fabric is fairly limited (ie not a cross bar), what pins support what functions are expressed in the Reference Manual.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
emalund
Associate III
Posted on February 16, 2012 at 16:08

<i>But, the pin muxing fabric is fairly limited (ie not a cross bar), what pins support what functions are expressed in the Reference Manual.</i>

the ''

pin muxing fabric is fairly limited

'' issue is often brought up by thuse that did not read the datasheet before they designed their hardware.

I had a discussion some time ago with a knowledgeable SILabs employee and asked ''why not a full MUX?'' he answered ''we prototyped that and it occupied 10 times more on the die than the processor, so we abandoned that''. I can, of course not make a direct, complete analogy between SILabs '51s and ST ARMs, but do believe that were we to have full MUXes we would have to pay through the nose. That, of course is irrelevant for the amateur who buy one chip, but the manufacturers live from theose that buy millions, and they would not pay for a full MUX.

Erik