资源简介

视频演示地址:https://v.qq.com/x/page/d0766ufjnl4.html

资源截图

代码片段和文件信息

#include “PWM_Config.h“
void PWM_Config(u8 CCR1_Valu8 CCR2_Val)
{
  TIM_TimebaseInitTypeDef  TIM_TimebaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;

  TIM_TimebaseStructure.TIM_Period = 255;       //5及为2.5ms为一个定时周期
  TIM_TimebaseStructure.TIM_Prescaler = 36000;     //设置预分频:不预分频,即为36MHz
  TIM_TimebaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ; //设置时钟分频系数:不分频
  TIM_TimebaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //向上计数模式
  TIM_TimebaseInit(TIM3 &TIM_TimebaseStructure);
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;     //配置为PWM模式1
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;  //当定时器计数值小于CCR1_Val时为高电平

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = CCR1_Val;    //设置跳变值,当计数器计数到这个值时,电平发生跳变
  TIM_OC1Init(TIM3 &TIM_OCInitStructure);  //使能通道1
  TIM_OC1PreloadConfig(TIM3 TIM_OCPreload_Enable);


  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = CCR2_Val;   //设置通道2的电平跳变值,输出另外一个占空比的PWM
  TIM_OC2Init(TIM3 &TIM_OCInitStructure);   //使能通道2
  TIM_OC2PreloadConfig(TIM3 TIM_OCPreload_Enable);

  TIM_ARRPreloadConfig(TIM3 ENABLE);  // 使能TIM3重载寄存器ARR
  TIM_Cmd(TIM3 ENABLE);                   //使能定时器3
}

void PWM_GPIO_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 ENABLE); 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA  ENABLE); 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB ENABLE);  //使能PBPE端口时钟

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;     // 复用推挽输出
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA &GPIO_InitStructure);

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;  //LED0-->PB.5 端口配置
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;   //推挽输出
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;  //IO口速度为50MHz
 GPIO_Init(GPIOA &GPIO_InitStructure);  //根据设定参数初始化GPIOB.5
 GPIO_ResetBits(GPIOAGPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5);  //PB.5 输出高

}



void PWM_INIT(void)
{
PWM_GPIO_Config();
/*最大255,控制PWM的输出,第一个是马达A,第二个是马达B*/
  /*更改PWM,以后再调用这一条就行了,就能改变速度了*/
PWM_Config(255255);

IN1 = 1;
  IN2 = 1;
  IN3 = 1;
  IN4 = 1;
}


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件      482425  2018-10-26 15:37  read_me.pdf
     目录           0  2018-10-26 14:48  源码\
     目录           0  2018-10-26 14:48  源码\PWM_Config\
     文件        2569  2018-10-26 14:46  源码\PWM_Config\PWM_Config.c
     文件         283  2018-10-26 14:36  源码\PWM_Config\PWM_Config.h
     目录           0  2018-10-26 14:48  源码\STM32规范化PRINTF\
     目录           0  2018-10-26 14:48  源码\STM32规范化PRINTF\CMSIS\
     文件       17273  2010-06-07 10:25  源码\STM32规范化PRINTF\CMSIS\core_cm3.c
     文件       85714  2011-02-09 14:59  源码\STM32规范化PRINTF\CMSIS\core_cm3.h
     目录           0  2018-10-26 14:48  源码\STM32规范化PRINTF\CMSIS\startup\
     目录           0  2018-10-26 14:48  源码\STM32规范化PRINTF\CMSIS\startup\TrueSTUDIO\
     文件       12604  2011-03-10 10:54  源码\STM32规范化PRINTF\CMSIS\startup\TrueSTUDIO\startup_stm32f10x_cl.s
     文件       12592  2011-03-10 10:53  源码\STM32规范化PRINTF\CMSIS\startup\TrueSTUDIO\startup_stm32f10x_hd.s
     文件       12239  2011-03-10 10:53  源码\STM32规范化PRINTF\CMSIS\startup\TrueSTUDIO\startup_stm32f10x_hd_vl.s
     文件        9826  2011-03-10 10:53  源码\STM32规范化PRINTF\CMSIS\startup\TrueSTUDIO\startup_stm32f10x_ld.s
     文件       10275  2011-03-10 10:53  源码\STM32规范化PRINTF\CMSIS\startup\TrueSTUDIO\startup_stm32f10x_ld_vl.s
     文件       10275  2011-03-10 10:53  源码\STM32规范化PRINTF\CMSIS\startup\TrueSTUDIO\startup_stm32f10x_md.s
     文件       10757  2011-03-10 10:53  源码\STM32规范化PRINTF\CMSIS\startup\TrueSTUDIO\startup_stm32f10x_md_vl.s
     文件       13252  2011-03-10 10:53  源码\STM32规范化PRINTF\CMSIS\startup\TrueSTUDIO\startup_stm32f10x_xl.s
     目录           0  2018-10-26 14:48  源码\STM32规范化PRINTF\CMSIS\startup\arm\
     文件       15766  2011-03-10 10:52  源码\STM32规范化PRINTF\CMSIS\startup\arm\startup_stm32f10x_cl.s
     文件       15503  2011-03-10 10:52  源码\STM32规范化PRINTF\CMSIS\startup\arm\startup_stm32f10x_hd.s
     文件       15692  2011-03-10 10:52  源码\STM32规范化PRINTF\CMSIS\startup\arm\startup_stm32f10x_hd_vl.s
     文件       12376  2011-03-10 10:52  源码\STM32规范化PRINTF\CMSIS\startup\arm\startup_stm32f10x_ld.s
     文件       13656  2011-03-10 10:52  源码\STM32规范化PRINTF\CMSIS\startup\arm\startup_stm32f10x_ld_vl.s
     文件       12765  2011-03-10 10:52  源码\STM32规范化PRINTF\CMSIS\startup\arm\startup_stm32f10x_md.s
     文件       14073  2011-03-10 10:51  源码\STM32规范化PRINTF\CMSIS\startup\arm\startup_stm32f10x_md_vl.s
     文件       15955  2011-03-10 10:51  源码\STM32规范化PRINTF\CMSIS\startup\arm\startup_stm32f10x_xl.s
     目录           0  2018-10-26 14:48  源码\STM32规范化PRINTF\CMSIS\startup\gcc_ride7\
     文件       13072  2011-03-10 10:52  源码\STM32规范化PRINTF\CMSIS\startup\gcc_ride7\startup_stm32f10x_cl.s
     文件       13160  2011-03-10 10:52  源码\STM32规范化PRINTF\CMSIS\startup\gcc_ride7\startup_stm32f10x_hd.s
............此处省略470个文件信息

评论

共有 条评论