找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2154|回复: 1
打印 上一主题 下一主题
收起左侧

用于驱动霍尔换向电机的tim设置BldC源程序

[复制链接]
跳转到指定楼层
楼主
ID:304376 发表于 2018-4-9 13:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. void BLDC_GPIOConfig(void)
  2. {                                                                                                      
  3.   GPIO_InitTypeDef GPIO_InitStructure;
  4.         GPIO_DeInit(GPIOE);
  5.         GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE);
  6.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13;
  7.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  8.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  9.   GPIO_Init(GPIOE, &GPIO_InitStructure);
  10.         GPIO_DeInit(GPIOC);
  11.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;
  12.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  13.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  14.   GPIO_Init(GPIOC, &GPIO_InitStructure);
  15.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
  16.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//éÏà-êäèë
  17.   GPIO_Init(GPIOA, &GPIO_InitStructure);
  18.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;
  19.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//éÏà-êäèë
  20.   GPIO_Init(GPIOB, &GPIO_InitStructure);
  21.         

  22.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;  
  23.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  24.   GPIO_Init(GPIOD, &GPIO_InitStructure);
  25. }
  26. /**********************************************************************
  27. * Description    : None
  28. * Input          : None
  29. * Output         : None
  30. * Return         : None
  31. * Attention      : None
  32. **********************************************************************/
  33. void BLDC_TIM1Config(void)
  34. {
  35.    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  36.    TIM_OCInitTypeDef                  TIM_OCInitStructure;
  37. //   TIM_BDTRInitTypeDef          TIM_BDTRInitStructure;

  38.    TIM_DeInit(TIM1);//3õê¼»ˉTIM1
  39.    TIM_TimeBaseStructure.TIM_Prescaler = 3-1;
  40.    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned2;
  41.    TIM_TimeBaseStructure.TIM_Period = 700-1;                                           //PWM 16K   72MHZ/(3*750)=32K
  42.    TIM_TimeBaseStructure.TIM_ClockDivision =TIM_CKD_DIV1;
  43.    TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

  44.    TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);

  45.    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  46.    TIM_OCInitStructure.TIM_OutputState  = TIM_OutputState_Disable;
  47.    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;                  
  48.    TIM_OCInitStructure.TIM_Pulse = bldc_speed;//(unsigned int)AD_value; £¬μçÆ½·¢éúìø±ä*/
  49.    TIM_OCInitStructure.TIM_OCPolarity   = TIM_OCPolarity_High;
  50.    TIM_OCInitStructure.TIM_OCNPolarity  = TIM_OCNPolarity_High;         
  51.    TIM_OCInitStructure.TIM_OCIdleState  = TIM_OCIdleState_Set;
  52.    TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;           
  53.    TIM_OC1Init(TIM1,&TIM_OCInitStructure);

  54.    TIM_OCInitStructure.TIM_Pulse =bldc_speed;//(unsigned int)AD_value;
  55.    TIM_OC2Init(TIM1,&TIM_OCInitStructure);

  56.    TIM_OCInitStructure.TIM_Pulse =bldc_speed;//(unsigned int)AD_value;
  57.    TIM_OC3Init(TIM1,&TIM_OCInitStructure);

  58.    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
  59.    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;                  
  60.    TIM_OCInitStructure.TIM_Pulse =100;
  61.    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;           
  62.    TIM_OC4Init(TIM1,&TIM_OCInitStructure);

  63. //   TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
  64. //   TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
  65. //   TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
  66. //   TIM_BDTRInitStructure.TIM_DeadTime = 500;
  67. //   TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable;
  68. //   TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low;
  69. //   TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;
  70. //   TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure);

  71.    TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
  72.    TIM_OC2PreloadConfig(TIM1,TIM_OCPreload_Enable);

  73.    TIM_OC3PreloadConfig(TIM1,TIM_OCPreload_Enable);

  74.    TIM_SelectInputTrigger(TIM1, TIM_TS_ITR1);

  75. //   TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Trigger);

  76.    TIM_CtrlPWMOutputs(TIM1,ENABLE);

  77. //   TIM_Cmd(TIM1,ENABLE);                       
  78. }


复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:304376 发表于 2018-4-9 13:24 | 只看该作者
用于驱动霍尔换向电机的tim设置程序
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表