小学生
最后登录1970-1-1
在线时间 小时
注册时间2015-7-4
|
/**
******************************************************************************
* @file main.c
* @author fire
* @version V1.0
* @date 2013-xx-xx
* @brief 2aêÔtim1Ëĸöí¨μàêä3ö2»í¬Õ¼¿Õ±èμÄpwm2¨(PA8.PA9.PA10--2¢μ÷êÔ3ö»¥212¨DÎ)
******************************************************************************
* @attention
*
* êμÑéƽì¨:ò°»e iSO STM32 ¿a·¢°å
* ÂÛì3 :http://www.firebbs.cn
* ìÔ±| :http://firestm32.taobao.com
*
******************************************************************************
*/
#include "stm32f10x.h"
#include "bsp_pwm_output.h"
/**
* @brief Ö÷oˉêy
* @param ÎT
* @retval ÎT
*/
int main(void)
{
//TIM3_PWM_Init();
//TIM1_PWM_Init();
TIM1_PWM_Init();
while (1)
{
}
}
/*********************************************END OF FILE**********************/
/*以上是main函数*/
/*下面是bsp_pwm_output.c文件*/
/**
******************************************************************************
* @file bsp_pwm_output.c
* @author STMicroelectronics
* @version V1.0
* @date 2013-xx-xx
* @brief tim3êä3öËÄ·pwm bsp
******************************************************************************
* @attention
*
* êμÑéƽì¨:ò°»e iSO STM32 ¿a·¢°å
* ÂÛì3 :http://www.firebbs.cn
* ìÔ±| :http://firestm32.taobao.com
*
******************************************************************************
*/
#include "bsp_pwm_output.h"
static void TIM1_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
/* GPIOA and GPIOB clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
/*GPIOA Configuration: TIM3 channel 1 and 2 as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/*GPIOB Configuration: TIM3 channel 3 and 4 as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
static void TIM1_Mode_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
u16 CCR1_Val = 500;
u16 CCR2_Val = 375;
u16 CCR3_Val = 250;
/* -----------------------------------------------------------------------
TIM3 Channel1 duty cycle = (TIM3_CCR1/ TIM3_ARR+1)* 100% = 50%
TIM3 Channel2 duty cycle = (TIM3_CCR2/ TIM3_ARR+1)* 100% = 37.5%
TIM3 Channel3 duty cycle = (TIM3_CCR3/ TIM3_ARR+1)* 100% = 25%
TIM3 Channel4 duty cycle = (TIM3_CCR4/ TIM3_ARR+1)* 100% = 12.5%
----------------------------------------------------------------------- */
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 999;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &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(TIM1, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
/* PWM1 Mode configuration: Channel2 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR2_Val;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
/* PWM1 Mode configuration: Channel3 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR3_Val;
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM1, ENABLE);
TIM_Cmd(TIM1, ENABLE);
//TIM_Cmd(TIM3, ENABLE);
}
void TIM1_PWM_Init(void)
{
//TIM3_GPIO_Config();
//TIM3_Mode_Config();
TIM1_GPIO_Config();
TIM1_Mode_Config();
}
/*********************************************END OF FILE**********************/
以上代码是根据火哥的例子改的的,编译时,提示TIM3_PWM_Init()没有定义。这是怎么回事。在线等。请求帮忙
|
|