config.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // globals definition
  2. //------------------------
  3. // Configuration section
  4. // How many slots do we currently support?
  5. // use 1 for debugging, 4 for production
  6. #define NUM_SLOTS 4
  7. //Battery Tolerance
  8. // how much tolerance do we allow if we charge / discharge before we
  9. // trigger the control loop to adjust the value
  10. #define BATTERY_CURRENT_THRESHOLD 5
  11. // Mainloop sleep time
  12. // Time to sleep between two mainloop intervals
  13. // We have a 32 MHz clock
  14. // debugging e.g. 32000000*5 -> 5s
  15. // production e.g. 320000 (10ms) (Validate that this is really the case!)
  16. // should be large for debugging, (e.g. )
  17. // small for production
  18. #define MAINLOOP_DELAY (3200)
  19. // i2c address for acting as target
  20. // (based on the GPIO 1 integer is added)
  21. #define I2C_TARGET_BASE_ADDRESS 0x48
  22. // PWM Initalization delay
  23. // in order to ensure they don't go in exactly the same frequency to
  24. // avoid EMV peaks
  25. #define PWM_INITIALIZATION_DELAY 100
  26. // PWM Define max CC period
  27. #define MAX_PWM_CYCLE 320
  28. //------------
  29. // Section for configuring debugging outputs
  30. //------------
  31. // printf ADC outputs
  32. #define DEBUG_ADC 1
  33. // printf DAC outputs
  34. #define DEBUG_DAC 1
  35. // printf control loop outputs
  36. #define DEBUG_CTRL 1
  37. // printf trace: put also the transition messages
  38. #define DEBUG_TRACE_CTRL 1
  39. // printf i2c errors
  40. #define DEBUG_I2C_ERR 1
  41. // printf i2c traffic (tx)
  42. //#define DEBUG_I2C_TX 1
  43. // printf target i2c interrupts (where the mcu is the i2c target)
  44. #define DEBUG_TARGET 1
  45. // debug temperature sensor
  46. //#define DEBUG_TEMPERATURE
  47. //------------
  48. // Section for configuring error tresholds
  49. //------------
  50. // soft overvoltage treshold before getting into the soft overvoltage state
  51. #define SOV_THRESHOLD_MV 6000
  52. // hard overvoltage treshold for getting into the hard overvoltage state (error)
  53. #define HOV_THRESHOLD_MV 8000
  54. // define the temperature error state
  55. #define OVERTEMPERATURE_TRESHOLD 43
  56. //------------
  57. // Section for configuring i2c master values
  58. //------------
  59. // dac address
  60. #define DAC_TARGET_ADDRESS 0x60
  61. // ADC base address
  62. // it is assumed the slots are ADC ADC_TARGET_BASE_ADDRESS slot 0,
  63. // other addresses follow the address table of the MCP3428
  64. #define ADC_TARGET_BASE_ADDRESS 0x68
  65. // ADC Measurement mode:
  66. // can be single shot or continuous
  67. // if used continuous, a matching delay cycles needs to be set in order to
  68. // ensure that the measurement is ready. (set the define to 0 if it should be one-shot)
  69. // (it could be the case that the channel is switched and wrong data is fetched)
  70. #define ADC_MEASUREMENT_IS_CONTINUOUS 1
  71. #define ADC_CONTINUOUS_DELAY_CYCLES_VOLTAGES (32000*10) // 32000 is 1ms (32MHz clock)
  72. #define ADC_CONTINUOUS_DELAY_CYCLES_SHUNT (32000*75)
  73. // Packet buffer sizes for RX and TX for the
  74. // controller mode only
  75. // (target for the other MCU is treated differently)
  76. #define I2C_TX_MAX_PACKET_SIZE 5
  77. #define I2C_RX_MAX_PACKET_SIZE 5
  78. // how many cycles do we wait until a tx message is completed?
  79. #define MAX_I2C_WAIT_RX 32000*10