mirror of https://github.com/rusefi/bldc.git
Axiom: configurable current sensor gain
Signed-off-by: Marcos Chaparro <mchaparro@powerdesigns.ca>
This commit is contained in:
parent
1d08745376
commit
4d93f2fef1
|
@ -28,6 +28,7 @@
|
|||
#include "utils.h"
|
||||
#include "terminal.h"
|
||||
#include "commands.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#include "hw_axiom_fpga_bitstream.c" //this file ONLY contains the fpga binary blob
|
||||
|
||||
|
@ -51,11 +52,14 @@
|
|||
#define AXIOM_FPGA_RESET_PIN 4
|
||||
#endif
|
||||
|
||||
#define EEPROM_ADDR_CURRENT_GAIN 0
|
||||
|
||||
#define BITSTREAM_SIZE 104090 //ice40up5k
|
||||
//#define BITSTREAM_SIZE 71338 //ice40LP1K
|
||||
|
||||
// Variables
|
||||
static volatile bool i2c_running = false;
|
||||
static volatile float current_sensor_gain = 0.0;
|
||||
//extern unsigned char FPGA_bitstream[BITSTREAM_SIZE];
|
||||
|
||||
|
||||
|
@ -68,6 +72,8 @@ static const I2CConfig i2cfg = {
|
|||
|
||||
// Private functions
|
||||
static void terminal_cmd_reset_oc(int argc, const char **argv);
|
||||
static void terminal_cmd_store_current_sensor_gain(int argc, const char **argv);
|
||||
static void terminal_cmd_read_current_sensor_gain(int argc, const char **argv);
|
||||
static void spi_transfer(uint8_t *in_buf, const uint8_t *out_buf, int length);
|
||||
static void spi_begin(void);
|
||||
static void spi_end(void);
|
||||
|
@ -76,6 +82,8 @@ void hw_axiom_init_FPGA_CLK(void);
|
|||
void hw_axiom_setup_dac(void);
|
||||
void hw_axiom_configure_brownout(uint8_t);
|
||||
void hw_axiom_configure_VDD_undervoltage(void);
|
||||
float hw_axiom_read_current_sensor_gain(void);
|
||||
inline float hw_axiom_get_current_sensor_gain(void);
|
||||
|
||||
void hw_init_gpio(void) {
|
||||
|
||||
|
@ -186,9 +194,23 @@ void hw_init_gpio(void) {
|
|||
"Reset latched FPGA faults.",
|
||||
0,
|
||||
terminal_cmd_reset_oc);
|
||||
|
||||
terminal_register_command_callback(
|
||||
"axiom_store_current_sensor_gain",
|
||||
"Store new current sensor gain.",
|
||||
0,
|
||||
terminal_cmd_store_current_sensor_gain);
|
||||
|
||||
terminal_register_command_callback(
|
||||
"axiom_read_current_sensor_gain",
|
||||
"Read current sensor gain.",
|
||||
0,
|
||||
terminal_cmd_read_current_sensor_gain);
|
||||
|
||||
// Send bitstream over SPI to configure FPGA
|
||||
hw_axiom_configure_FPGA();
|
||||
|
||||
current_sensor_gain = hw_axiom_read_current_sensor_gain();
|
||||
}
|
||||
|
||||
void hw_setup_adc_channels(void) {
|
||||
|
@ -492,3 +514,59 @@ static void spi_delay(void) {
|
|||
__NOP();
|
||||
__NOP();
|
||||
}
|
||||
|
||||
static void terminal_cmd_store_current_sensor_gain(int argc, const char **argv) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
eeprom_var current_gain;
|
||||
if( argc == 2 ) {
|
||||
sscanf(argv[1], "%f", &(current_gain.as_float));
|
||||
|
||||
// Store data in eeprom
|
||||
conf_general_store_eeprom_var_hw(¤t_gain, EEPROM_ADDR_CURRENT_GAIN);
|
||||
|
||||
//read back written data
|
||||
current_sensor_gain = hw_axiom_read_current_sensor_gain();
|
||||
|
||||
if(current_sensor_gain == current_gain.as_float) {
|
||||
commands_printf("Axiom current sensor sensor gain set as %.8f", (double)current_sensor_gain);
|
||||
}
|
||||
else {
|
||||
current_sensor_gain = 0.0;
|
||||
commands_printf("Error storing EEPROM data.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
commands_printf("1 argument required. For example: axiom_store_current_sensor_gain 0.003761");
|
||||
commands_printf(" ");
|
||||
}
|
||||
commands_printf(" ");
|
||||
return;
|
||||
}
|
||||
|
||||
static void terminal_cmd_read_current_sensor_gain(int argc, const char **argv) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
//read back written data
|
||||
current_sensor_gain = hw_axiom_read_current_sensor_gain();
|
||||
|
||||
commands_printf("Axiom current sensor sensor gain is set as %.8f", (double)current_sensor_gain);
|
||||
commands_printf(" ");
|
||||
return;
|
||||
}
|
||||
|
||||
float hw_axiom_read_current_sensor_gain() {
|
||||
eeprom_var current_gain;
|
||||
|
||||
conf_general_read_eeprom_var_hw(¤t_gain, EEPROM_ADDR_CURRENT_GAIN);
|
||||
|
||||
if( (current_gain.as_float <= 0) || (current_gain.as_float >= 1) )
|
||||
current_gain.as_float = DEFAULT_CURRENT_AMP_GAIN;
|
||||
return current_gain.as_float;
|
||||
}
|
||||
|
||||
inline float hw_axiom_get_current_sensor_gain() {
|
||||
return current_sensor_gain;
|
||||
}
|
||||
|
|
|
@ -101,6 +101,8 @@
|
|||
#define HVDC_TRANSFER_FUNCTION 185.0 //[V/V]
|
||||
#define PHASE_VOLTAGE_TRANSFER_FUNCTION 185.0 //[V/V]
|
||||
#endif
|
||||
#define DEFAULT_CURRENT_AMP_GAIN 0.003761 //Transfer Function [V/A] for ISB-425-A
|
||||
|
||||
|
||||
// Component parameters (can be overridden)
|
||||
#ifndef V_REG
|
||||
|
@ -113,7 +115,8 @@
|
|||
#define VIN_R2 1.0
|
||||
#endif
|
||||
#ifndef CURRENT_AMP_GAIN
|
||||
#define CURRENT_AMP_GAIN 0.003761 //Transfer Function [V/A] for ISB-425-A
|
||||
#define CURRENT_AMP_GAIN hw_axiom_get_current_sensor_gain()
|
||||
//#define CURRENT_AMP_GAIN 0.003761 //Transfer Function [V/A] for ISB-425-A
|
||||
//#define CURRENT_AMP_GAIN 0.001249 //Transfer Function [V/A] for HTFS 800-P
|
||||
//#define CURRENT_AMP_GAIN 0.0008324 //Transfer Function [V/A] for HASS 600-S
|
||||
#endif
|
||||
|
@ -286,5 +289,6 @@
|
|||
char hw_axiom_configure_FPGA(void);
|
||||
void hw_axiom_DAC1_setdata(uint16_t data);
|
||||
void hw_axiom_DAC2_setdata(uint16_t data);
|
||||
float hw_axiom_get_current_sensor_gain(void);
|
||||
|
||||
#endif /* HW_AXIOM_H_ */
|
||||
|
|
Loading…
Reference in New Issue