hal.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _HAL_H__
  2. #define _HAL_H__
  3. #include "stm32f3xx_hal.h"
  4. #define Start_Stop_Pin GPIO_PIN_13
  5. #define Start_Stop_GPIO_Port GPIOC
  6. #define PWM_UH_Pin GPIO_PIN_8
  7. #define PWM_UH_GPIO_Port GPIOA
  8. #define PWM_VH_Pin GPIO_PIN_9
  9. #define PWM_VH_GPIO_Port GPIOA
  10. #define PWM_WH_Pin GPIO_PIN_10
  11. #define PWM_WH_GPIO_Port GPIOA
  12. #define PWM_EN_U_Pin GPIO_PIN_10
  13. #define PWM_EN_U_GPIO_Port GPIOC
  14. #define PWM_EN_V_Pin GPIO_PIN_11
  15. #define PWM_EN_V_GPIO_Port GPIOC
  16. #define PWM_EN_W_Pin GPIO_PIN_12
  17. #define PWM_EN_W_GPIO_Port GPIOC
  18. #define CURR_AMPL_W_Pin GPIO_PIN_0
  19. #define CURR_AMPL_W_GPIO_Port GPIOC
  20. #define CURR_AMPL_V_Pin GPIO_PIN_1
  21. #define CURR_AMPL_V_GPIO_Port GPIOC
  22. #define TEMPERATURE_Pin GPIO_PIN_2
  23. #define TEMPERATURE_GPIO_Port GPIOC
  24. #define CURR_AMPL_U_Pin GPIO_PIN_0
  25. #define CURR_AMPL_U_GPIO_Port GPIOA
  26. #define BUS_VOLTAGE_Pin GPIO_PIN_1
  27. #define BUS_VOLTAGE_GPIO_Port GPIOA
  28. #define GAS_SENSOR_Pin GPIO_PIN_1
  29. #define GAS_SENSOR_GPIO_Port GPIOB
  30. #define M1_OCP_Pin GPIO_PIN_11
  31. #define M1_OCP_GPIO_Port GPIOA
  32. #define HALL_1_PIN GPIO_PIN_15
  33. #define HALL_1_GROUP GPIOA
  34. #define HALL_2_PIN GPIO_PIN_3
  35. #define HALL_2_GROUP GPIOB
  36. #define HALL_3_PIN GPIO_PIN_10
  37. #define HALL_3_GROUP GPIOB
  38. #define UART_TX_Pin GPIO_PIN_2
  39. #define UART_TX_GPIO_Port GPIOA
  40. #define UART_RX_Pin GPIO_PIN_3
  41. #define UART_RX_GPIO_Port GPIOA
  42. #define CURRENT_U_ADC_CHANNAL 1
  43. #define CURRENT_V_ADC_CHANNAL 7
  44. #define CURRENT_W_ADC_CHANNAL 6
  45. #define TEMP_SENSOR_ADC_CHANNEL 8
  46. #define VBUS_SENSOR_ADC_CHANNEL 2
  47. #define SPEED_SENSOR_ADC_CHANNEL 12
  48. #define ADC_REFERENCE_VOLTAGE 3.30f
  49. #define READ_HALL1() (HAL_GPIO_ReadPin(HALL_1_GROUP, HALL_1_PIN) == GPIO_PIN_SET ?1:0)
  50. #define READ_HALL2() (HAL_GPIO_ReadPin(HALL_2_GROUP, HALL_2_PIN) == GPIO_PIN_SET ?1:0)
  51. #define READ_HALL3() (HAL_GPIO_ReadPin(HALL_3_GROUP, HALL_3_PIN) == GPIO_PIN_SET ?1:0)
  52. #define SYSTEM_CLOCK (72000000L)
  53. #define TIM_CLOCK (SYSTEM_CLOCK * 2) /*SystemClock_Config中TIM1的clk从sys PLL 过来,固定2倍的PLL频率*/
  54. #define TIM_CLOCK_MHz (144)
  55. #define ADC_CLOCK (SYSTEM_CLOCK)
  56. #define ADC_CLOCK_MHz (72)
  57. #define NS_PER_TCLK (7) /* (1/144000000 * 1000000000) */
  58. #define NS_2_TCLK(ns) ((ns/NS_PER_TCLK) + 1) //ns 转为pwm使用的那个TIM的clk count
  59. #define FOC_PWM_FS (30 * 1000)
  60. #define FOC_PWM_period (TIM_CLOCK/FOC_PWM_FS)
  61. #define FOC_PWM_Half_Period (FOC_PWM_period/2)
  62. #define MAX_VBUS (12.f) //12v
  63. #define ADC_TRIG_CONV_LATENCY_CYCLES 3.5f
  64. #define ADC_SAMPLING_CYCLES 7.5f
  65. #define HW_DEAD_TIME_NS 800
  66. #define HW_RISE_TIME_NS 50
  67. #define HW_NOISE_TIME_NS 50
  68. #define TDead NS_2_TCLK(HW_DEAD_TIME_NS/2)/* 死区时间 */
  69. #define TRise NS_2_TCLK(HW_RISE_TIME_NS)/* MOS 开关时间*/
  70. #define TNoise NS_2_TCLK(HW_NOISE_TIME_NS)/* MOS开关引入的开关噪声时间 */
  71. #define TADC ((uint16_t)((ADC_TRIG_CONV_LATENCY_CYCLES + ADC_SAMPLING_CYCLES) * 2 * TIM_CLOCK_MHz) / ADC_CLOCK_MHz + 1u)/* ADC 采样时间 */
  72. #define START_RAMP_DURATION (100)//ms
  73. #define SPEED_SAMPLE_INVAL (100) //转把采集的间隔,ms
  74. #define SPEED_RAMP_DURATION SPEED_SAMPLE_INVAL //设置速度的斜波时间,速度平滑上升或下降
  75. #define MAX_VBUS_VOLTAGE 24.0f
  76. #define MAX_CURRENT 50.0F
  77. void Error_Handler(void);
  78. void SystemClock_Config(void);
  79. void HAL_GPIO_init(void);
  80. void HAL_NVIC_Init(void);
  81. void HAL_EXIT_Enable(void);
  82. #endif /* _HAL_H__ */