67 lines
1.2 KiB
C++
67 lines
1.2 KiB
C++
/**** Includes ****/
|
|
#include "../utils/utils.h"
|
|
#include "board.h"
|
|
|
|
/**** Private definitions ****/
|
|
/**** Private constants ****/
|
|
/**** Private variables ****/
|
|
/**** Private function declarations ****/
|
|
|
|
/**** Public function definitions ****/
|
|
void board_init(void)
|
|
{
|
|
// MCU setup
|
|
// ADC clock must be 50kHz to 200kHz
|
|
// ADC clock = 8MHz/ADC_DIV
|
|
// PWM frequncy = 8MHz/(2*TOP*TIM_DIM)
|
|
mcu::startupCfg_t mcu_cfg;
|
|
mcu_cfg.adc_clk = mcu::ADC_DIV64; //125kHz /13.5 = 9259 samples/s
|
|
mcu_cfg.pwm_clk = mcu::TIM_DIV1; // 8MHz
|
|
mcu_cfg.pwm_top = 1000; // 4kHz
|
|
mcu_cfg.pwm_ch1_en = 1;
|
|
|
|
mcu::startup(&mcu_cfg);
|
|
|
|
// Board setup
|
|
// Fixed function AIN mV and mA scale
|
|
dccd_i.mul = 215;
|
|
dccd_i.div = 22;
|
|
dccd_i.offset = 0;
|
|
dccd_i.last_read = 0;
|
|
|
|
dccd_u.mul = 20;
|
|
dccd_u.div = 1;
|
|
dccd_u.offset = 0;
|
|
dccd_u.last_read = 0;
|
|
|
|
bat_u.mul = 20;
|
|
bat_u.div = 1;
|
|
bat_u.offset = 0;
|
|
bat_u.last_read = 12000;
|
|
|
|
bat_i.mul = 235;
|
|
bat_i.div = 6;
|
|
bat_i.offset = 0;
|
|
bat_i.last_read = 0;
|
|
}
|
|
|
|
void board_read(void)
|
|
{
|
|
dccd_i.read();
|
|
dccd_u.read();
|
|
bat_u.read();
|
|
bat_i.read();
|
|
ain1.read();
|
|
ain2.read();
|
|
|
|
din1.read();
|
|
din2.read();
|
|
din3.read();
|
|
din4.read();
|
|
hvdin1.read();
|
|
hvdin2.read();
|
|
hvdin3.read();
|
|
}
|
|
|
|
/**** Private function definitions ****/
|