board.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef __BOARD_H
  2. #define __BOARD_H
  3. /* MACROs for SET, RESET or TOGGLE Output port */
  4. #define GPIO_HIGH(a,b) a->ODR |= b
  5. #define GPIO_LOW(a,b) a->ODR &= ~b
  6. #define GPIO_TOGGLE(a,b) a->ODR ^= b
  7. /* ADC */
  8. #define ADC_PORTU GPIOD
  9. #define ADC_PINU GPIO_PIN_3
  10. #define ADC_CHNLU ADC1_CHANNEL_4
  11. #define ADC_SCHTU (uint8_t)ADC1_SCHMITTTRIG_CHANNEL4
  12. #define ADC_PORTI GPIOC
  13. #define ADC_PINI GPIO_PIN_4
  14. #define ADC_CHNLI ADC1_CHANNEL_2
  15. #define ADC_SCHTI (uint8_t)ADC1_SCHMITTTRIG_CHANNEL2
  16. #define ADC_SMPLS 64
  17. // Supply voltage in mili volts
  18. #define ADC_VREF 3333UL
  19. // Сопротивление резисторов делителя входного напряжения, кОм/100
  20. #define VOLTAGE_MULT_TOP 383UL
  21. #define VOLTAGE_MULT_BOT 100UL
  22. #define VOLT_MUL_MUL 1000UL
  23. #define VOLTAGE_MUL_DIV (1024UL * VOLTAGE_MULT_BOT)
  24. #define VOLTAGE_MUL (uint32_t)((VOLT_MUL_MUL * ADC_VREF * (VOLTAGE_MULT_TOP+VOLTAGE_MULT_BOT)) / VOLTAGE_MUL_DIV)
  25. // shunt resistance in Ohms
  26. #define CURRENT_SHUNT (1/0.01)
  27. // Сопротивление резисторов ОУ усилителя сигнала шунта, кОм/100
  28. #define CURRENT_MULT_TOP 180UL
  29. #define CURRENT_MULT_BOT 12UL
  30. #define CURR_MUL_MUL 1000UL
  31. #define CURRENT_MUL_DIV (1024UL * (CURRENT_MULT_TOP + CURRENT_MULT_BOT))
  32. #define CURRENT_MUL (uint32_t)(((CURR_MUL_MUL * ADC_VREF * CURRENT_SHUNT * CURRENT_MULT_BOT)) / CURRENT_MUL_DIV)
  33. // Current commutator
  34. #define SWITCH_PORT GPIOD
  35. #define SWITCH_PIN GPIO_PIN_6
  36. #define SWITCH_ON SWITCH_PORT->ODR |= SWITCH_PIN
  37. #define SWITCH_OFF SWITCH_PORT->ODR &= ~SWITCH_PIN
  38. #endif /* __BOARD_H */