board.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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_PORT GPIOD
  9. #define ADC_PINU GPIO_PIN_2
  10. #define ADC_CHNLU ADC1_CHANNEL_3
  11. #define ADC_SCHTU ADC1_SCHMITTTRIG_CHANNEL3
  12. #define ADC_PINI GPIO_PIN_3
  13. #define ADC_CHNLI ADC1_CHANNEL_4
  14. #define ADC_SCHTI ADC1_SCHMITTTRIG_CHANNEL4
  15. #define ADC_SMPLS 64
  16. #define ADC_RES (1023UL << 3)
  17. // Supply voltage in mili volts * fixed coeeficient
  18. #define ADC_VREF 3030UL
  19. // Voltage channel
  20. #define VOLTAGE_MULT_TOP 15UL
  21. #define VOLTAGE_MULT_BOT 100UL
  22. #define VOLT_MUL_K 100UL
  23. #define VOLT_MUL_KD 110UL
  24. #define VOLT_MUL_DIV (VOLTAGE_MULT_TOP * ADC_RES)
  25. #define VOLTAGE_MUL (uint16_t)((VOLT_MUL_K * (VOLTAGE_MULT_BOT * ADC_VREF) + (VOLT_MUL_DIV/2)) / VOLT_MUL_DIV)
  26. // Current channel
  27. #define CURREN_SHUNT (1/0.01)
  28. #define CURRENT_MULT_TOP 15UL
  29. #define CURRENT_MULT_BOT 1UL
  30. #define CUR_MUL_K 100UL
  31. #define CUR_MUL_KD 136UL
  32. #define CUR_MUL_DIV (CURRENT_MULT_TOP * ADC_RES)
  33. #define CURRENT_MUL (uint16_t)((CUR_MUL_K * (CURRENT_MULT_BOT * ADC_VREF * CURREN_SHUNT) + (CUR_MUL_DIV/2)) / CUR_MUL_DIV)
  34. #endif /* __BOARD_H */