找回密码
 立即注册

QQ登录

只需一步,快速开始

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

STM32+TB6612FNG驱动麦克娜姆轮小车程序原理图

[复制链接]
跳转到指定楼层
楼主
stm32驱动麦克娜姆轮小车底层驱动原理图和代码


单片机源程序如下:
  1. #include "stm32f10x.h"
  2. #include "systick.h"
  3. #include "time3_out_pwm.h"
  4. #include "gear_motor.h"
  5. #include "usart1.h"
  6. #include "ADC.H"
  7. #include "speed_exit.h"
  8. #include "pid.h"

  9. #define DSwitch_B2 GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_15)
  10. #define DSwitch_B3 GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_3)
  11. #define DSwitch_B4 GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_4)
  12. #define DSwitch_B5 GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5)

  13. #define RunLED_0 GPIO_ResetBits(GPIOB,GPIO_Pin_9)
  14. #define RunLED_1 GPIO_SetBits(GPIOB,GPIO_Pin_9)

  15. #define LowLED_0 GPIO_ResetBits(GPIOB,GPIO_Pin_8)
  16. #define LowLED_1 GPIO_SetBits(GPIOB,GPIO_Pin_8)

  17. u32 BPS=9600;
  18. u8 DisSwitchNum=0;

  19. u8 CheckBetrry=0;


  20. extern unsigned int M1_Num;
  21. extern unsigned int M2_Num;
  22. extern unsigned int M3_Num;
  23. extern unsigned int M4_Num;

  24. void LED_GPIO_Init(void)
  25. {
  26.         GPIO_InitTypeDef GPIO_InitStructure;
  27.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

  28.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
  29.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  30.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  31.   GPIO_Init(GPIOB, &GPIO_InitStructure);
  32.         RunLED_0;
  33.         LowLED_1;
  34. }

  35. void RunLED_Flash(void)
  36. {
  37.         static u8 sta=0;
  38.         if (sta==1)
  39.         {
  40.                 RunLED_1;
  41.                 sta=0;
  42.         }
  43.         else
  44.         {
  45.                 RunLED_0;
  46.                 sta=1;
  47.                 CheckBetrry++;
  48.         }
  49. }

  50. void LowPower(void)
  51. {
  52.         static u8 num=0;
  53.         u16 value=0;
  54.         if (CheckBetrry>=50)
  55.         {
  56.                 CheckBetrry=0;
  57.                 value=GetVolt();
  58.                
  59.                 if (value<102)
  60.                 {
  61.                         num++;
  62.                 }
  63.                 else
  64.                 {
  65.                         num=0;
  66.                 }
  67.                
  68.                 if (num>5)
  69.                 {
  70.                         LowLED_0;
  71.                         TIM_SetCompare1(TIM3,0);
  72.                         TIM_SetCompare2(TIM3,0);
  73.                         TIM_SetCompare3(TIM3,0);
  74.                         TIM_SetCompare4(TIM3,0);
  75.                         while(1);
  76.                 }               
  77.         }
  78. }

  79. void DIP_Switch_GPIO_Init(void)
  80. {
  81.         GPIO_InitTypeDef GPIO_InitStructure;
  82.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE);

  83.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  84.         GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);

  85.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
  86.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  87.   GPIO_Init(GPIOA, &GPIO_InitStructure);

  88.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
  89.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  90.   GPIO_Init(GPIOB, &GPIO_InitStructure);
  91.         
  92.         DisSwitchNum=DSwitch_B2;
  93.         DisSwitchNum<<=1;
  94.         DisSwitchNum+=DSwitch_B3;
  95.         DisSwitchNum<<=1;
  96.         DisSwitchNum+=DSwitch_B4;
  97.         DisSwitchNum<<=1;
  98.         DisSwitchNum+=DSwitch_B5;
  99. }

  100. void Selcet_CtrlMode(void)
  101. {
  102.         switch (DisSwitchNum&0x03)
  103.         {
  104.                 case 0:
  105.                 {
  106.                         BPS=4800;
  107.                 }break;
  108.                 case 1:
  109.                 {
  110.                         BPS=9600;
  111.                 }break;
  112.                 case 2:
  113.                 {
  114.                         BPS=38400;
  115.                 }break;
  116.                 case 3:
  117.                 {
  118.                         BPS=115200;
  119.                 }break;
  120.                 default:break;
  121.         }
  122.         Uart1_Configuration(BPS);
  123. }


  124. int main(void)
  125. {
  126.         SystemInit();
  127.         SysTick_Configuration();
  128.         LED_GPIO_Init();
  129.         DIP_Switch_GPIO_Init();
  130.         Selcet_CtrlMode();
  131.         PID_Init();
  132.         Exit_Init();
  133.         TIM3_PWM_Init();
  134.         GearMotor_GPIO_init();
  135.         Uart1_Configuration(BPS);
  136.         ADC_InitConfiguration();

  137.         if ((DisSwitchNum&0x0C)==0x04)
  138.         {
  139.                 while(1)
  140.                 {
  141.                         UART1_Alone_HEX_Analysis();
  142.                         GearMotor_Analysis();
  143.                         LowPower();
  144.                         PID_Process();
  145.                 }               
  146.         }
  147.         else if ((DisSwitchNum&0x0C)==0x00)
  148.         {
  149.                 while(1)
  150.                 {
  151.                         UART1_Alone_ASC_Analysis();
  152.                         GearMotor_Analysis();
  153.                         LowPower();
  154.                         PID_Process();
  155.                 }
  156. ……………………

  157. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有代码51hei附件下载:
STM32代码和原理图.rar (482.39 KB, 下载次数: 82)

评分

参与人数 1黑币 +10 收起 理由
admin + 10 共享资料的黑币奖励!

查看全部评分

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

使用道具 举报

沙发
ID:111463 发表于 2023-7-10 16:25 | 只看该作者
采用常规PWM驱动即可,建议规范一下程序设计
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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