• 大小: 4.12MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-11
  • 语言: 其他
  • 标签: 电机驱动  CAN  

资源简介

电机驱动程序基于STM32F1

资源截图

代码片段和文件信息

#include  “init.h“

void CAN_Thread1 (void const *argument); //CAN数据接收
osThreadId T_CAN_ID1;
osThreadDef(CAN_Thread1 osPriorityHigh 1 512);

void Transfer_Thread1 (void const *argument); //CAN数据接收
osThreadId T_Transfer_ID1;
osThreadDef(Transfer_Thread1 osPriorityNormal 1 512);

void LED_Thread1 (void const *argument); 
osThreadId T_LED_ID1;
osThreadDef(LED_Thread1 osPriorityNormal 1 128);

void ID_Thread1 (void const *argument); 
osThreadId T_ID_ID1;
osThreadDef(ID_Thread1 osPriorityLow 1 128);

osSemaphoreId_t CAN_Semaphore; // 
osSemaphoreDef(CAN_Semaphore);


u16 CAN_ID=0;
u32 Revice_State=0Revice_State_Last=0; //接收CAN信号状态  无信号则停止电机输出  

u8 xy;
u8 WorkState=WORK;
extern  int  encoder;
/*RTXKernelStartInit and Task Creak*/
void KernelTaskInit(void)
{
/************************************************/
//外设初始化过程
/************************************************/
    TIM4_PWM_Init(8003-1);  //10KHZ
   CANID_GPIOinit();     //GPIO初始化 
    ID_init();
  CANTransfer_Init(CANID);//CAN通信初始化 
//  USART1_Init(115200);    //串口查看 
    Led_OutputInit();     //led灯初始化
//  USART1_Printf();      //串口打印模块信息
  Encoder_Configuration(Encoderdata-10); 
    Encoder_init(2000-1240-1); //20ms采集
  my_delayms(CAN_ID&0x0f);//根据ID号延时启动  
   NVIC_StateInit();
   if(osKernelInitialize()!=osOK)
 { while(1);
 }
   CAN_Semaphore=osSemaphoreNew(10osSemaphore(CAN_Semaphore));
 T_CAN_ID1=osThreadCreate(osThread(CAN_Thread1)NULL);
 T_Transfer_ID1=osThreadCreate(osThread(Transfer_Thread1)NULL);
 T_LED_ID1=osThreadCreate(osThread(LED_Thread1)NULL);
 T_ID_ID1=osThreadCreate(osThread(ID_Thread1)NULL);

   if( osKernelStart()!=osOK) //Start Task Running
 {
   while(1); 
 }
}
void ID_init(void)
{
 u8 id=0;

 CAN_ID=(ID_CAN|Read_CanID());
   id=(CAN_ID&0x0f); 
   switch(id)
 {
   case 1:{x=0y=1;}break;
   case 2:{x=2y=3;}break;
 case 3:{x=4y=5;}break;
 case 4:{x=6y=7;}break;
 case 5:{x=0y=1;}break;
   case 6:{x=2y=3;}break;
 case 7:{x=4y=5;}break;
 case 8:{x=6y=7;}break;
 
 default:{ Motor_Pwm=0; WorkState=WARING;}break;
 }

}
//中断优先级定义
void NVIC_StateInit(void )
{
    NVIC_InitTypeDef  Nvic_InitStructure;
   /* Configure one bit for preemption priority */
   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/*中断设置*/
Nvic_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;    //CAN1 RX0中断
Nvic_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;    //抢占优先级0
Nvic_InitStructure.NVIC_IRQChannelSubPriority = 0;    //子优先级为0
Nvic_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&Nvic_InitStructure);

Nvic_InitStructure.NVIC_IRQChannel = TIM2_IRQn;    
Nvic_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;    //抢占优先级1
Nvic_InitStructure.NVIC_IRQChannelSubPriority = 0;    //子优先级为0
Nvic_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&Nvic_InitStructure);
}
/*
CAN接收中断线程  CAN接收成

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4867  2018-01-04 16:53  直流电机驱动\BSPInit\init.c

     文件        493  2017-12-21 22:37  直流电机驱动\BSPInit\init.h

     文件        136  2017-10-29 15:18  直流电机驱动\BSPInit\main.c

     文件     633941  2011-03-10 10:51  直流电机驱动\BSPInit\stm32f10x.h

     文件       3287  2017-04-22 21:36  直流电机驱动\BSPInit\stm32f10x_conf.h

     文件       2432  2015-03-18 18:49  直流电机驱动\BSPInit\stm32f10x_it.c

     文件       1983  2011-04-04 18:57  直流电机驱动\BSPInit\stm32f10x_it.h

     文件       2208  2017-11-17 19:12  直流电机驱动\Devicer\data_transfer.c

     文件        222  2017-04-23 11:44  直流电机驱动\Devicer\data_transfer.h

     文件       2955  2017-11-17 00:03  直流电机驱动\Devicer\encoder.c

     文件        228  2017-11-17 00:12  直流电机驱动\Devicer\encoder.h

     文件        441  2017-11-17 19:12  直流电机驱动\Devicer\led.c

     文件        307  2017-11-10 18:43  直流电机驱动\Devicer\led.h

     文件       5049  2017-12-28 23:31  直流电机驱动\Devicer\motor_devicer.c

     文件        608  2018-01-04 15:25  直流电机驱动\Devicer\motor_devicer.h

     文件        254  2017-12-26 19:42  直流电机驱动\Devicer\mydelay.c

     文件        126  2016-05-10 12:13  直流电机驱动\Devicer\mydelay.h

     文件        426  2017-10-29 18:31  直流电机驱动\Devicer\Read_GPIOID.c

     文件        184  2017-04-28 19:59  直流电机驱动\Devicer\Read_GPIOID.h

     文件       7339  2017-12-22 11:29  直流电机驱动\Devicer\transfer_can.c

     文件        383  2018-01-04 17:03  直流电机驱动\Devicer\transfer_can.h

     文件       6956  2015-12-10 17:06  直流电机驱动\Project\DebugConfig\Motor_STM32F103T8.dbgconf

     文件        339  2018-01-04 16:52  直流电机驱动\Project\EventRecorderStub.scvd

     文件      17324  2018-01-04 15:12  直流电机驱动\Project\Listings\irq_cm3.lst

     文件     329886  2018-01-04 17:03  直流电机驱动\Project\Listings\Motor.map

     文件      55146  2017-11-11 20:33  直流电机驱动\Project\Listings\startup_stm32f10x_hd.lst

     文件      45134  2018-01-04 15:12  直流电机驱动\Project\Listings\startup_stm32f10x_md.lst

    .......    175009  2018-01-04 17:12  直流电机驱动\Project\Motor.uvguix.Administrator

     文件     176107  2017-11-11 20:35  直流电机驱动\Project\Motor.uvguix.Administrator.bak

    .......    176189  2017-12-28 23:31  直流电机驱动\Project\Motor.uvguix.Listen

............此处省略159个文件信息

评论

共有 条评论