找回密码
 立即注册

QQ登录

只需一步,快速开始

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

基于STM32F103VET6的无刷直流电机控制程序和资料还有原理图

  [复制链接]
跳转到指定楼层
楼主
基于STM32F103VET6的无刷直流电机控制程序和资料还有原理图
压缩包内部文件:

PCB正面

PCB反面

无感无刷直流电机之电调设计全攻略

内部文件:


Cortex-M3架构


采用FOS



MAIN.C
  1. /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
  2. * File Name          : main.c
  3. * Author             : MCD Application Team
  4. * Version            : V2.0.1
  5. * Date               : 06/13/2008
  6. * Description        : Main program body
  7. ********************************************************************************
  8. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  9. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
  10. * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  11. * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
  12. * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
  13. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  14. *******************************************************************************/

  15. /* Includes ------------------------------------------------------------------*/
  16. #include "stm32f10x_lib.h"
  17. #include "main.h"
  18. #include "CAN\can.h"

  19. #define ADC1_DR_Address    ((u32)0x4001244C)
  20. /* Private typedef -----------------------------------------------------------*/
  21. /* Private define ------------------------------------------------------------*/
  22. /* Private macro -------------------------------------------------------------*/
  23. /* Private variables ---------------------------------------------------------*/
  24. static vu32 TimingDelay = 0;

  25. volatile struct {
  26.                 unsigned Key           :                1;
  27.                 unsigned CalSpeed :         1;
  28.                 unsigned Sec      :                1;
  29.                 unsigned Fault           :                1;
  30.                 }Flags;

  31. unsigned int DesiredSpeed=500;
  32. unsigned int ActualSpeed;
  33. unsigned int pwm=500;
  34. unsigned int T3Count;
  35. unsigned int ActualSpeed5[3];
  36. vu16 ADC_DMABUF;
  37. unsigned int AveActualSpeed;
  38. unsigned char AveNum;
  39. unsigned char j;


  40. float kp=0.50,ki=0.08,kd=0.0;
  41. //float ABC[3]={0.8,0.08,0.0};
  42. int ek=0,ek1=0,ek2=0;
  43. float duk;
  44. int du;
  45. int ekSpeed=0;
  46. unsigned char LED_Code[16]={0x5f,0x44,0x9d,0xd5,0xc6,0xd3,0xdb,0x45,0xdf,0xd7,0xcf,0xda,0x1b,0xdc,0x9b,0x8b};
  47. int LED_Dis;

  48. u16 motor_statue=0;
  49. extern u16 My_PWM;
  50. extern bool Direction;
  51. extern CanRxMsg tmp_CanRxMessage;
  52. extern CanTxMsg tmp_TxMessage;
  53. int state,state1,state2,state3,counter1,counter2,counter3,speed_1,aim_speed,check_run,speed_code;
  54. short ADC_ConvertedValue[5]={0,0,0,0,0};

  55. u8 *Row0[10]={"Set Speed:"};
  56. u8 *Row1[10]={"Now Speed:"};
  57. u8 *Clear[16]={"                "};

  58. TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
  59. TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  60. TIM_OCInitTypeDef  TIM_OCInitStructure;
  61. EXTI_InitTypeDef EXTI_InitStructure;
  62. ErrorStatus HSEStartUpStatus;  

  63. /* Private function prototypes -----------------------------------------------*/
  64. void RCC_Configuration(void);
  65. void GPIO_Configuration(void);
  66. void NVIC_Configuration(void);
  67. void CalculateDC(int u,int y);
  68. void TIM3_Configuration1(void);
  69. void TIM2_Configuration1(void);
  70. void TIM4_Configuration1(void);
  71. void SysTick_Configuration(void);
  72. void DMA_Configuration1(void);
  73. void ADC_Configuration1(void);
  74. int pid(int nonce,int aim);
  75. /* Private functions ---------------------------------------------------------*/
  76. /*******************************************************************************
  77. * Function Name  : main
  78. * Description    : Main program.
  79. * Input          : None
  80. * Output         : None
  81. * Return         : None
  82. *******************************************************************************/
  83. int main(void)
  84. {
  85.         #ifdef DEBUG
  86.         debug();
  87.         #endif
  88.           int i,j,k;
  89.         /* System Clocks Configuration */
  90.         RCC_Configuration();
  91.      
  92.         /* NVIC configuration */
  93.         NVIC_Configuration();
  94.         CAN_Config();
  95.     DMA_Configuration1();
  96.         ADC_Configuration1();
  97.         
  98.         TIM3_Configuration1();         
  99.         TIM2_Configuration1();
  100.         TIM4_Configuration1();

  101.         
  102.         
  103.         GPIO_Configuration();  
  104.         SysTick_Configuration();
  105.         SysTick_CounterCmd(SysTick_Counter_Enable);
  106.         /* Configure the systick */   
  107.         //SysTick_Config();

  108.         /* Configure the GPIO ports */
  109.         

  110.         
  111.                
  112.         GPIO_SetBits(GPIOC, GPIO_Pin_11);
  113.            //DisplayNumber(5,0,325);         
  114.         aim_speed=2000;
  115.         //My_PWM=100;
  116.                 //EXTI_GenerateSWInterrupt(EXTI_Line1);
  117.                 //for(i=0;i<500;i++);
  118.                 //EXTI_GenerateSWInterrupt(EXTI_Line1);        
  119.                 //for(i=0;i<500;i++);
  120.                 //EXTI_GenerateSWInterrupt(EXTI_Line1);
  121.         while (1)
  122.         {
  123.                 //motor_statue=0;
  124.                 //Direction=FALSE;
  125.                 LED_Dis=speed_1;
  126.                 if(speed_code!=((GPIO_ReadInputData(GPIOE)>>1)&0x07))
  127.                 {
  128.                         speed_code=(GPIO_ReadInputData(GPIOE)>>1)&0x07;
  129.                          tmp_TxMessage.StdId = 0x0f;
  130.                           tmp_TxMessage.RTR = CAN_RTR_DATA;
  131.                           tmp_TxMessage.IDE = CAN_ID_STD;
  132.                           tmp_TxMessage.DLC = 8;
  133.                           tmp_TxMessage.Data[0] = speed_code;
  134.                         CAN_Send_Message(&tmp_TxMessage);

  135.                         //aim_speed=speed_code*1000;
  136.                 }

  137.                         if(state1>5)
  138.         {        
  139.                 if(check_run<3&&aim_speed>300)
  140.                 {        GPIO_ResetBits(GPIOC, GPIO_Pin_11);
  141.                 for(i=0;i<5000;i++);
  142.                 My_PWM=200;
  143.                 GPIO_SetBits(GPIOC, GPIO_Pin_11);
  144.                         EXTI_GenerateSWInterrupt(EXTI_Line0);
  145.                         for(i=0;i<500;i++);
  146.                         EXTI_GenerateSWInterrupt(EXTI_Line1);        
  147.                         for(i=0;i<500;i++);
  148.                         EXTI_GenerateSWInterrupt(EXTI_Line2);
  149.                 }
  150.                 state1=0;
  151.                 check_run=0;
  152.         }               

  153.                 for(i=0;i<100000;i++);
  154.                 My_PWM+=pid(speed_1,aim_speed)/((speed_1/My_PWM)+1);        
  155.                 if(My_PWM<0)
  156.                 My_PWM=0;
  157.                 if(My_PWM>5000)                           
  158.                 My_PWM=5000;
  159.                 /*
  160.                 if((speed_1-aim_speed)<3)
  161.                 {
  162.                         My_PWM+=10;        
  163.                 }
  164.                 if((aim_speed-speed_1)<3)
  165.                 {
  166.                         My_PWM-=10;        
  167.                 }
  168.                
  169.                 for(j=10;j<90;j++)
  170.                 {        
  171.                         for(k=0;k<5;k++)
  172.                         for(i=0;i<50000;i++);
  173.                         My_PWM=j*10;
  174.                 }                        
  175.                 for(k=0;k<100;k++)
  176.                 for(i=0;i<50000;i++);         
  177.                 for(j=90;j>10;j--)
  178.                 {
  179.                         for(k=0;k<5;k++)
  180.                         for(i=0;i<50000;i++);
  181.                         My_PWM=j*10;
  182.                 }               
  183.                 Direction=TRUE;                        
  184.                 for(k=0;k<50;k++)
  185.                 for(i=0;i<50000;i++);
  186.                 My_PWM=100;
  187.                 EXTI_GenerateSWInterrupt(EXTI_Line1);
  188.                 for(i=0;i<500;i++);
  189.                 EXTI_GenerateSWInterrupt(EXTI_Line1);        
  190.                 for(i=0;i<500;i++);
  191.                 EXTI_GenerateSWInterrupt(EXTI_Line1);                                 
  192.                
  193.                 for(j=10;j<90;j++)
  194.                 {        
  195.                         for(k=0;k<5;k++)
  196.                         for(i=0;i<50000;i++);
  197.                         My_PWM=j*10;
  198.                 }                        
  199.                 for(k=0;k<100;k++)
  200.                 for(i=0;i<50000;i++);         
  201.                 for(j=90;j>10;j--)
  202.                 {
  203.                         for(k=0;k<5;k++)
  204.                         for(i=0;i<50000;i++);
  205.                         My_PWM=j*10;
  206.                 } */
  207.         }
  208. }

  209. int pid(int nonce,int aim)
  210. {
  211.         static int ek_2=0;
  212.         static int ek_1=0;
  213.         static int ek=0;
  214. //        int ec;        
  215.         int uk;
  216.         
  217.         ek=aim-nonce;
  218. //        ec=ek/T;
  219.         uk=kp*(ek-ek_1+ki*ek+kd*(ek-2*ek_1+ek_2));
  220.         ek_2=ek_1;
  221.         ek_1=ek;
  222.         return (uk);
  223. }

  224. /*******************************************************************************
  225. * Function Name  : RCC_Configuration
  226. * Description    : Configures the different system clocks.
  227. * Input          : None
  228. * Output         : None
  229. * Return         : None
  230. *******************************************************************************/
  231. void RCC_Configuration(void)
  232. {
  233.     ErrorStatus HSEStartUpStatus;

  234.     // RCC system reset(for debug purpose)
  235.     RCC_DeInit();

  236.     // Enable HSE
  237.     RCC_HSEConfig(RCC_HSE_ON);

  238.     // Wait till HSE is ready
  239.     HSEStartUpStatus = RCC_WaitForHSEStartUp();

  240.     if(HSEStartUpStatus == SUCCESS)
  241.     {
  242.         // Enable Prefetch Buffer
  243.         FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

  244.         // Flash 2 wait state
  245.         FLASH_SetLatency(FLASH_Latency_2);

  246.         // HCLK = SYSCLK
  247.         RCC_HCLKConfig(RCC_SYSCLK_Div1);

  248.         // PCLK2 = HCLK
  249.         RCC_PCLK2Config(RCC_HCLK_Div1);

  250.         // PCLK1 = HCLK/2
  251.         RCC_PCLK1Config(RCC_HCLK_Div2);

  252.         // PLLCLK = 8MHz * 9 = 72 MHz
  253.         RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

  254.         // Enable PLL
  255.         RCC_PLLCmd(ENABLE);

  256.         // Wait till PLL is ready
  257.         while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
  258.         {
  259.         }

  260.         // Select PLL as system clock source
  261.         RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

  262.         // Wait till PLL is used as system clock source
  263.         while(RCC_GetSYSCLKSource() != 0x08)
  264.         {
  265.         }
  266.     }
  267.     else
  268.     {
  269.         // If HSE fails to start-up, the application will have wrong clock configuration.
  270.         // User can add here some code to deal with this error

  271.         // Go to infinite loop
  272.         while (1)
  273.         {
  274.         }
  275.     }

  276. #ifdef _GPIOA
  277.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  278. #endif

  279. #ifdef _GPIOB
  280.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  281. #endif

  282. #ifdef _GPIOC
  283.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
  284. #endif

  285. #ifdef _GPIOD
  286.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
  287. #endif

  288. #ifdef _GPIOE
  289.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
  290. #endif

  291. #ifdef _GPIOF
  292.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);
  293. #endif

  294. #ifdef _GPIOG
  295.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE);
  296. #endif

  297. #ifdef _AFIO
  298.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  299. #endif

  300. #ifdef _CAN
  301.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
  302. #endif

  303. #ifdef _USART1
  304.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  305. #endif

  306. #ifdef _SPI1
  307.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
  308. #endif

  309. #ifdef _FSMC
  310.     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  311. #endif

  312. #ifdef _USART2
  313.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
  314. #endif

  315. #ifdef _PWR
  316.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  317. #endif

  318. #ifdef _BKP
  319.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP, ENABLE);
  320. #endif

  321. #ifdef _TIM2
  322.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
  323. #endif

  324. #ifdef _DMA1
  325.     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
  326. #endif

  327. #ifdef _ADC1
  328.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
  329. #endif

  330. }

  331. /*******************************************************************************
  332. * Function Name  : GPIO_Configuration
  333. * Description    : Configures the different GPIO ports.
  334. * Input          : None
  335. * Output         : None
  336. * Return         : None
  337. *******************************************************************************/
  338. void GPIO_Configuration(void)
  339. {
  340.         GPIO_InitTypeDef GPIO_InitStructure;  
  341.         /*PE4£¬PE5£¬PE6ÎaLED*/
  342.           GPIO_InitStructure.GPIO_Pin =GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
  343.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  344.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  345.           GPIO_Init(GPIOE, &GPIO_InitStructure);
  346.         
  347.          /*PD8-PD15 ÎaêyÂë1ü¶ÎÑ¡*/
  348.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8| GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11| GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14| GPIO_Pin_15;
  349.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  350.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  351.           GPIO_Init(GPIOD, &GPIO_InitStructure);
  352.                                                                   
  353.         /*PB12-PB15 ÎaêyÂë1üλѡ*/
  354.           GPIO_InitStructure.GPIO_Pin =GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
  355.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  356.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  357.           GPIO_Init(GPIOB, &GPIO_InitStructure);

  358.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
  359.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
  360.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  361.         GPIO_Init(GPIOE, &GPIO_InitStructure);
  362.         /*PE2,PE3ÎaêäèëéÏà- °′¼ü */
  363.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3;
  364.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  365.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  366.         GPIO_Init(GPIOE, &GPIO_InitStructure);
  367.          
  368.           /* ÅäÖÃHall½ó¿úIO */
  369.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
  370.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  371.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  372.         GPIO_Init(GPIOD, &GPIO_InitStructure);
  373.         
  374.         /*»ô¶ûDÅoÅÏßÖD¶ÏÅäÖÃ*/
  375.          GPIO_EXTILineConfig(GPIO_PortSourceGPIOD,GPIO_PinSource0);
  376.         GPIO_EXTILineConfig(GPIO_PortSourceGPIOD,GPIO_PinSource1);
  377.         GPIO_EXTILineConfig(GPIO_PortSourceGPIOD,GPIO_PinSource2);

  378.         EXTI_InitStructure.EXTI_Line = EXTI_Line0|EXTI_Line1|EXTI_Line2;
  379.         EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  380.         EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
  381.         EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  382.         EXTI_Init(&EXTI_InitStructure);        

  383.          /*PC4,PC5,PC6 ÎaéÏ°ëÇÅ±Û PC11ÎaÇy¶ˉê1Äü*/
  384.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4| GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_11;
  385.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  386.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  387.           GPIO_Init(GPIOC, &GPIO_InitStructure);

  388.           /*PC7,PC8,PC9 ÎaÏ°ëÇűÛ£¬¸′óÃÎaPWMêä3ö*/
  389.           GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 ;
  390.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  391.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  392.           GPIO_Init(GPIOC, &GPIO_InitStructure);

  393.           GPIO_PinRemapConfig(GPIO_FullRemap_TIM3,ENABLE);
  394.           //GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3, ENABLE);

  395. }

  396. //±Õ»·¼ÆËã×ó3ìDò
  397. void CalculateDC(int u,int y)
  398. {
  399.         ek=u-y;
  400.         if(ek>1||ek<-1)
  401.         {
  402.                 duk=kp*(ek-ek1)+ki*ek+kd*(ek+ek2-ek1*2);
  403.                 du=(int)duk;
  404.                 if(duk>1)duk=1;
  405.                 if(duk<-1)duk=-1;
  406.                 if(du>10)du=10;
  407.                 if(du<-5)du=-5;        
  408.                 pwm+=du;   
  409.                 if(pwm<60)
  410.                 {
  411.                         pwm=60;               
  412.                 }
  413.                 if(pwm>0x7FE)
  414.                 {
  415.                         //pwm=2398;
  416.                         pwm=0x7FE;        
  417.                 }
  418.                 //TIM1->CCR1 = pwm;
  419.                 //TIM1->CCR2 = pwm;
  420.                 //TIM1->CCR3 = pwm;
  421.                 ek2=ek1;
  422.                 ek1=ek;
  423.         }
  424. }

  425. /*******************************************************************************
  426. * Function Name  : NVIC_Configuration
  427. * Description    : Configure the nested vectored interrupt controller.
  428. * Input          : None
  429. * Output         : None
  430. * Return         : None
  431. *******************************************************************************/
  432. void NVIC_Configuration(void)
  433. {
  434.         NVIC_InitTypeDef NVIC_InitStructure;
  435.   
  436.         #ifdef  VECT_TAB_RAM  
  437.                 /* Set the Vector Table base location at 0x20000000 */
  438.                 NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
  439.         #else  /* VECT_TAB_FLASH  */
  440.                 /* Set the Vector Table base location at 0x08000000 */
  441.                 NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
  442.         #endif

  443.         /* Configure one bit for preemption priority */
  444.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  445.   
  446.         /* Enable the EXTI9_5 Interrupt */
  447.         NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQChannel;
  448.         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  449.         NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  450.         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  451.         NVIC_Init(&NVIC_InitStructure);
  452.         
  453.         NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQChannel;
  454.         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  455.         NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  456.         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  457.         NVIC_Init(&NVIC_InitStructure);
  458.         
  459.         NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQChannel;
  460.         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  461.         NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
  462.         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  463.         NVIC_Init(&NVIC_InitStructure);         

  464.         
  465.     NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN_RX0_IRQChannel;
  466.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  467.     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
  468.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  469.     NVIC_Init(&NVIC_InitStructure);
  470.          
  471.         
  472.         NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
  473.         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  474.         NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  475.         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  476.         NVIC_Init(&NVIC_InitStructure);                  
  477.                   
  478.         NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel;
  479.         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  480.         NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  481.         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  482.         NVIC_Init(&NVIC_InitStructure);                          

  483.         NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQChannel;
  484.         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  485.         NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
  486.         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  487.         NVIC_Init(&NVIC_InitStructure);                  

  488.         //NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQChannel;
  489.         //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  490.         //NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  491.         //NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  492.         //NVIC_Init(&NVIC_InitStructure);
  493.         
  494.         /* Configure and enable ADC interrupt */
  495.         //NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQChannel;
  496.         //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  497.         //NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
  498.         //NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  499.         //NVIC_Init(&NVIC_InitStructure);

  500.         //Step3.ê1ÄüTIM1μÄêä3ö±è½ÏÆ¥ÅäÖD¶Ï
  501.     //NVIC_InitStructure.NVIC_IRQChannel = TIM3_CC_IRQChannel;
  502.     //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  503.     //NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  504.     //NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  505.     //NVIC_Init(&NVIC_InitStructure);
  506. }

  507. #ifdef  DEBUG
  508. /*******************************************************************************
  509. * Function Name  : assert_failed
  510. * Description    : Reports the name of the source file and the source line number
  511. *                  where the assert_param error has occurred.
  512. * Input          : - file: pointer to the source file name
  513. *                  - line: assert_param error line source number
  514. * Output         : None
  515. * Return         : None
  516. *******************************************************************************/
  517. void assert_failed(u8* file, u32 line)
  518. {
  519.   /* User can add his own implementation to report the file name and line number,
  520.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  521.   /* Infinite loop */
  522.   while (1)
  523.   {
  524.   }
  525. }
  526. #endif

  527. /*******************************************************************************
  528. * Function Name  : SysTick_Config
  529. * Description    : Configure a SysTick Base time to 10 ms.
  530. * Input          : None
  531. * Output         : None
  532. * Return         : None
  533. *******************************************************************************/
  534. void SysTick_Configuration(void)
  535. {
  536.     /* Select AHB clock(HCLK) as SysTick clock source */
  537.     SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
  538.    
  539.     /* Set SysTick Priority to 3 */
  540.     NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 5, 0);
  541.    
  542.     /* SysTick interrupt each 1ms with HCLK equal to 72MHz */
  543.     SysTick_SetReload(900000);
  544.    
  545.     /* Enable the SysTick Interrupt */
  546.     SysTick_ITConfig(ENABLE);
  547. }

  548. /*******************************************************************************
  549. * Function Name  : Delay
  550. * Description    : Inserts a delay time.
  551. * Input          : nCount: specifies the delay time length (time base 10 ms).
  552. * Output         : None
  553. * Return         : None
  554. *******************************************************************************/
  555. void Delay(u32 nCount)
  556. {
  557.   TimingDelay = nCount;

  558.   /* Enable the SysTick Counter */
  559.   //SysTick_CounterCmd(SysTick_Counter_Enable);
  560.   
  561.   while(TimingDelay != 0)
  562.   {
  563.   }

  564.   /* Disable the SysTick Counter */
  565.   //SysTick_CounterCmd(SysTick_Counter_Disable);

  566.   /* Clear the SysTick Counter */
  567.   SysTick_CounterCmd(SysTick_Counter_Clear);
  568. }

  569. /*******************************************************************************
  570. * Function Name  : Decrement_TimingDelay
  571. * Description    : Decrements the TimingDelay variable.
  572. * Input          : None
  573. * Output         : TimingDelay
  574. * Return         : None
  575. *******************************************************************************/
  576. void Decrement_TimingDelay(void)
  577. {
  578.   if (TimingDelay != 0x00)
  579.   {
  580.     TimingDelay--;
  581.   }
  582. }

  583. /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
复制代码
全部资料51hei下载地址:
STM32+BLDC+2012.7.22+新版+资料.7z (711.38 KB, 下载次数: 114)

BLDC MC 00957a_cn.pdf

758.74 KB, 下载次数: 30, 下载积分: 黑币 -5

无感无刷直流电机之电调设计全攻略.pdf

4.58 MB, 下载次数: 35, 下载积分: 黑币 -5

无传感器PSMS马达FOC控制算法详解.pdf

2.12 MB, 下载次数: 32, 下载积分: 黑币 -5

基于STM32的PMSM_FOC软件库培训.pdf

738.56 KB, 下载次数: 32, 下载积分: 黑币 -5

BLDC 2012.7.22.pdf

1.18 MB, 下载次数: 35, 下载积分: 黑币 -5

评分

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

查看全部评分

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

使用道具 举报

沙发
ID:407585 发表于 2020-5-10 23:44 | 只看该作者
有没有无传感器的无刷直流电机测速
回复

使用道具 举报

板凳
ID:733231 发表于 2020-5-18 19:42 | 只看该作者
LNING 发表于 2020-5-10 23:44
有没有无传感器的无刷直流电机测速

没有哦,不好意思~~~今天才看到
回复

使用道具 举报

地板
ID:468240 发表于 2020-5-27 09:46 | 只看该作者
谢谢楼主分享
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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