就是说,你的函数声明写在了调用之后。这句话是说,你在51行调用了该函数,但是函数的定义却在159行。程序误把你的函数定义当做函数调用了,而把函数调用当做了函数声明。
解决方案:
1、在调用函数之前先声明;
2、将函数定义在调用之前。
void PWM_Init()
{
unsigned short CCR1_Val = 5000;
unsigned short CCR2_Val = 5000;
GPIO_InitTypeDef GPIO_InitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE);
GPIO_InitStructureGPIO_Pin = BSP_GPIOC_PWM1|BSP_GPIOC_PWM2; // PC6,PC7输出
GPIO_InitStructureGPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructureGPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/ -----------------------------------------------------------------------
TIM3 Configuration: generate 4 PWM signals with 4 different duty cycles:
TIM3CLK = 36 MHz, Prescaler = 0x0, TIM3 counter clock = 36 MHz
TIM3 ARR Register = 999 => TIM3 Frequency = TIM3 counter clock/(ARR + 1)
TIM3 Frequency = 36 KHz
TIM3 Channel1 duty cycle = (TIM3_CCR1/ TIM3_ARR) 100 = 50%
TIM3 Channel2 duty cycle = (TIM3_CCR2/ TIM3_ARR) 100 = 375%
TIM3 Channel3 duty cycle = (TIM3_CCR3/ TIM3_ARR) 100 = 25%
TIM3 Channel4 duty cycle = (TIM3_CCR4/ TIM3_ARR) 100 = 125%
----------------------------------------------------------------------- /
/ Time base configuration /
TIM_DeInit(TIM3);
TIM_TimeBaseStructureTIM_Period = 10000; // 200Hz
TIM_TimeBaseStructureTIM_Prescaler = 35; //36M/(35+1)=1MHz
TIM_TimeBaseStructureTIM_ClockDivision = 0;
TIM_TimeBaseStructureTIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/ PWM1 Mode configuration: Channel1 /
TIM_OCInitStructureTIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructureTIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructureTIM_Pulse = CCR1_Val; //50%占空比
TIM_OCInitStructureTIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
/ PWM1 Mode configuration: Channel2 /
TIM_OCInitStructureTIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructureTIM_Pulse = CCR2_Val;
TIM_OC2Init(TIM3, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3, ENABLE);
/ TIM3 enable counter /
TIM_Cmd(TIM3, ENABLE);
}
以上就是关于关于stm32 的问题 其实就是程序的问题全部的内容,包括:关于stm32 的问题 其实就是程序的问题、求一stm32产生spwm波的程序、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)