Intento que Timer1 funcione en modo PWM pero hay un error como en la imagen:
HeagregadotodaslasbibliotecasestándarnecesariasparaelmodoPWM,definalamacroUSE_STDPERIPH_DRIVERenelpreprocesador,peroesteproblemaaúnpersiste.¿Puedesayudarmeaencontrardóndeestáelproblema?
Código:
#include"stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_tim.h"
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_BaseStruct;
TIM_OCInitTypeDef TIM_OCInitStructure;
void TIM_PWM_Configuration(void);
void TIM_PWM_Configuration(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_11|GPIO_Pin_13|GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOE,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_TIM1);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource11,GPIO_AF_TIM1);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource13,GPIO_AF_TIM1);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource14,GPIO_AF_TIM1);
TIM_BaseStruct.TIM_Prescaler = 1-1; //0.5s
TIM_BaseStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_BaseStruct.TIM_Period = 0xFFFF; //65535
TIM_BaseStruct.TIM_ClockDivision = 0;
TIM_BaseStruct.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1,&TIM_BaseStruct);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC1Init(TIM1,&TIM_OCInitStructure);
TIM_OC1PreLoadConfig(TIM1,TIM_OCPreload_Enable);
TIM_OC2Init(TIM1,&TIM_OCInitStructure);
TIM_OC2PreLoadConfig(TIM1,TIM_OCPreload_Enable);
TIM_OC3Init(TIM1,&TIM_OCInitStructure);
TIM_OC3PreLoadConfig(TIM1,TIM_OCPreload_Enable);
TIM_OC4Init(TIM1,&TIM_OCInitStructure);
TIM_OC4PreLoadConfig(TIM1,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM1,ENABLE);
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
}
int main(void)
{
TIM_PWM_Configuration();
TIM1->CCR1 = 10*65535/100;
TIM1->CCR2 = 35*65535/100;
TIM1->CCR3 = 70*65535/100;
TIM1->CCR4 = 65535;
while(1){}
}
#ifdef USE_FULL_ASSERT
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) */
/* Infinite loop */
while (1)
{
}
}
#endif
Muchas gracias.