pwm输出是玩航模的重要目标之一
问题描述
`之前学习的树莓派,最近又来到了Arm,手里有几块stm32f103c8t6的板子,放着也是浪费,就想用来学习使用一下!
主函数如下:
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_tim.h"
#include "stm32f10x_rcc.h"
#include "tim3pwm.h"
void Delay(u32 count)
{
u32 i=0;
for(;i<count;i++);
}
void RCC_Config(void)
{
SystemInit(); //配置系统时钟为72M
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB,ENABLE ); /* GPIOB clock enable */
RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM3,ENABLE );/* TIM3 clock enable */
RCC_APB2PeriphClockCmd (RCC_APB2Periph_AFIO,ENABLE );
//PB4,5用作定时器tim3的PWM输出引脚,要部分重映射配置,所以需要开启AFIO时钟。
}
void LED_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_14| GPIO_Pin_15;//* 配置pb14,pb15可以作为刹车或正反用的控制端,带led可以显示控制状态 */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB, GPIO_Pin_14 | GPIO_Pin_15 ); // 设置led关
// GPIO_InitTypeDef GPIO_InitStructure;
// **********RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE); // 使能PB端口时钟
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15 ;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
// GPIO_InitStructure