2010-04-14 11:20 AM
PWM output not working?
2011-05-17 04:47 AM
Hello.
I dont see the text in your program like this:
/* 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(TIM3, &TIM_OCInitStructure);
2011-05-17 04:47 AM
Oh! Yes, I did not post it because a simple configuration. This is what I do:
/******************************* TIM_CONFIG
************************************
* Configure General Purpose Timers
* Description: We will only use Timer 2
*******************************************************************************/
static void TIM_Config(void)
{
TIM_TimeBaseInitTypeDef tim_config;
TIM_OCInitTypeDef tim_oc_config;
/* TIM2 configuration */
tim_config.TIM_Period = TIM2_period;
tim_config.TIM_Prescaler = TIM2_prescaler;
tim_config.TIM_ClockDivision = TIM_CKD_DIV1;
tim_config.TIM_CounterMode = TIM_CounterMode_Up;
tim_config.TIM_RepetitionCounter = 0x0000;
TIM_TimeBaseInit(TIM2, &tim_config);
TIM_OCStructInit(&tim_oc_config);
/* Output Compare Timing Mode configuration: Channel1 */
tim_oc_config.TIM_OCMode = TIM_OCMode_Timing;
tim_oc_config.TIM_Pulse = 0x0;
TIM_OC1Init(TIM2, &tim_oc_config);
/* Enable Auto Reload Register Preload */
TIM_ARRPreloadConfig(TIM2, ENABLE);
/* TIM2 counter enable */
TIM_Cmd(TIM2,ENABLE);
/* Immediate load of TIM2 Precaler value */
TIM_PrescalerConfig(TIM2, TIM2_prescaler, TIM_PSCReloadMode_Immediate);
/* Clear TIM2 update pending flag */
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
/* Enable TIM2 Update interrupt */
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
}
/******************************* PWM_CONFIG ************************************
* Configure PWM Timer
* Description: We will use Timer 1 for our PWM signal generation. We'll use
* a bits resolution defined at top of file.
*******************************************************************************/
static void PWM_Config(void)
{
TIM_TimeBaseInitTypeDef tim_config; /* TIM1 Init Struct */
TIM_OCInitTypeDef pwm_config; /* Output Compare Init Struct */
/* Time base configuration **************************************************/
tim_config.TIM_Prescaler = PWM_prescaler; // Max frequency
tim_config.TIM_CounterMode = TIM_CounterMode_Up;
tim_config.TIM_Period = PWM_resolution;
tim_config.TIM_ClockDivision = TIM_CKD_DIV1;
tim_config.TIM_RepetitionCounter = 0;
/* Do the setup */
TIM_TimeBaseInit(TIM1,&tim_config);
/* Channel 1 Configuration in PWM mode **************************************/
pwm_config.TIM_OCMode = TIM_OCMode_PWM1;
pwm_config.TIM_OutputState = TIM_OutputState_Enable;
pwm_config.TIM_OutputNState = TIM_OutputNState_Enable;
/* TIM_Pulse is the duty cycle */
pwm_config.TIM_Pulse = PWM_value;
pwm_config.TIM_OCPolarity = TIM_OCPolarity_Low;
pwm_config.TIM_OCNPolarity = TIM_OCNPolarity_High;
pwm_config.TIM_OCIdleState = TIM_OCIdleState_Set;
pwm_config.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM1,&pwm_config); // Do the setup
/* Enable Auto Reload Register Preload */
TIM_ARRPreloadConfig(TIM1, ENABLE);
/* TIM1 counter enable */
TIM_Cmd(TIM1,ENABLE);
}
In other applications the same code worked, is that possible right?Thanks!
2011-05-17 04:47 AM
At first ise that you dont use the commands for TIM1.
look here (FW lib functions for TIM1):TIM1_DeInit Resets the TIM1 peripheral registers to their default reset values. TIM1_TimeBaseInit Initializes the TIM1 Time Base Unit according to the specifiedparameters in the TIM1_TimeBaseInitStruct. TIM1_OC1Init Initializes the TIM1 Channel1 according to the specified parameters in the TIM1_OCInitStruct. TIM1_OC2Init Initializes the TIM1 Channel2 according to the specified parameters in the TIM1_OCInitStruct.All command for timer 1 begins from TIM1
Is the problem here?
2011-05-17 04:47 AM
Hi Denis!
Finally I found the solution. But it was not what you said :p Hehehe
Look, when I initialized my system I did:
Everything was ok, only initializing order were wrong. I must init RCC _before_ GPIOs. After inverting the order of this, everything worked perfect. In fact, in previous versions where I did use the same functions RCC was already initialized but I didn't know that (I was using RTOS from Micrium and when I used BSP functions the RTOS did the initialization).
Even so, thank you very much!
By the way, in my FW lib there's no functions called ''TIM1_xxx'' ?¿?¿ :S
Moderator note: should I mark this as answered?