• 大小: 14.08MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-27
  • 语言: Html/CSS
  • 标签: STM32  舵机  1501MG  

资源简介

视频移植教程:https://v.qq.com/x/page/f078228nbfd.html

资源截图

代码片段和文件信息

#include “PWM_Config.h“

void PWM_Config(u32 frequency)
{
  TIM_TimebaseInitTypeDef  TIM_TimebaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;

/* PWM信号电平跳变值 */
/*frequency 对应度数
1----->0°
2----->45°
3----->90°
4----->135°
5----->180°
*/
u16 CCR1_Val = frequency;        //0°1是0°

  /* Time base configuration */  
/*按照下面的5 * 0.5 = 2.5ms为一个周期*/
  TIM_TimebaseStructure.TIM_Period = 5;       //5及为2.5ms为一个定时周期

/*计算72000000/36000 = 2000HZ  那么1/2000 = 0.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);

  /* PWM1 Mode configuration: Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;     //配置为PWM模式1
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

/*假如是增加通道,就加这里的*/
/*跳变值,当值为1的时候就是1/5的周期,即为0.5ms高电平*/
  TIM_OCInitStructure.TIM_Pulse = CCR1_Val;    //设置跳变值,当计数器计数到这个值时,电平发生跳变
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;  //当定时器计数值小于CCR1_Val时为高电平
  TIM_OC1Init(TIM3 &TIM_OCInitStructure);  //使能通道1
  TIM_OC1PreloadConfig(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); 
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;     // 复用推挽输出
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA &GPIO_InitStructure);
}
void PWM_INIT(void)
{

PWM_GPIO_Config(); /*初始化引脚*/
PWM_Config(ANGLE_0); /*默认初始化状态*/

}
void Turn_Angle(u8 angle)
{
/*第二个参数就是更改PWM_Config.C中CCR1_Val*/
  TIM_SetCompare1(TIM3angle);
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件      375038  2018-11-05 09:09  read_me.pdf
     目录           0  2018-11-03 22:10  源码\
     目录           0  2018-11-03 22:10  源码\PWM_Config\
     文件        2244  2018-11-03 22:03  源码\PWM_Config\PWM_Config.c
     文件         425  2018-11-03 22:03  源码\PWM_Config\PWM_Config.h
     目录           0  2018-11-04 08:54  源码\STM32规范化PRINTF\
     目录           0  2018-11-03 22:10  源码\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-11-03 22:10  源码\STM32规范化PRINTF\CMSIS\startup\
     目录           0  2018-11-03 22:10  源码\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-11-03 22:10  源码\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-11-03 22:10  源码\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
............此处省略473个文件信息

评论

共有 条评论