BV: rename revision to version

This commit is contained in:
King Kévin 2018-02-26 12:13:45 +01:00
parent 0f712e5c0a
commit 02be8b122e
2 changed files with 40 additions and 42 deletions

View File

@ -49,11 +49,8 @@ static volatile bool busvoodoo_global_led_blue = false;
/** red LED status */
static volatile bool busvoodoo_global_led_red = false;
/** existing hardware revisions identifiable with voltages */
static const uint8_t busvoodoo_revision_numbers[] = {27};
/** hardware revision voltages (calculated from divider ratios) */
static const float busvoodoo_revision_voltages[] = {100.0/(10.0+100.0)*3.3};
/** hardware version voltages, calculated from divider ratios, starting with version A */
static const float busvoodoo_version_voltages[] = {100.0/(10.0+100.0)*3.3}; // version A start with revision 27
const char* busvoodoo_global_pinout_io[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
const char* busvoodoo_global_pinout_rscan[5] = {NULL, NULL, NULL, NULL, NULL};
@ -64,7 +61,7 @@ const uint32_t busvoodoo_io_pins[13] = {GPIO12, GPIO2, GPIO13, GPIO11, GPIO11, G
const uint8_t busvoodoo_io_groups[13] = {6, 6, 4, 4, 1, 1, 5, 5, 2, 2, 3, 3, 3};
bool busvoodoo_full = false;
uint8_t busvoodoo_revision = 0;
char busvoodoo_version = '0';
void busvoodoo_setup(void)
{
@ -76,7 +73,7 @@ void busvoodoo_setup(void)
rcc_periph_clock_enable(RCC_AFIO); // enable clock for alternate function (for communication)
busvoodoo_safe_state(); // put pins in safe state (for common light version)
// check if this BusVoodoo is a full version
// check if this BusVoodoo is a full flavor
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_HV_CHANNEL)); // enable clock for GPIO domain for HV channel
gpio_set(ADC12_IN_PORT(BUSVOODOO_HV_CHANNEL), ADC12_IN_PIN(BUSVOODOO_HV_CHANNEL)); // pull ADC HV high
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HV_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, ADC12_IN_PIN(BUSVOODOO_HV_CHANNEL)); // set HV channel as digital input with pull-up capabilities
@ -88,47 +85,47 @@ void busvoodoo_setup(void)
busvoodoo_safe_state(); // also put the full version pins in safe state
}
// setup ADC to measure hardware revision voltage
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_HW_REV_CHANNEL)); // enable clock for GPIO domain for hardware revision channel
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HW_REV_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_HW_REV_CHANNEL)); // set hardware revision channel as analogue input for the ADC
// setup ADC to measure hardware version voltage
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_HW_VERSION_CHANNEL)); // enable clock for GPIO domain for hardware version channel
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HW_VERSION_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_HW_VERSION_CHANNEL)); // set hardware version channel as analogue input for the ADC
rcc_periph_clock_enable(RCC_ADC1); // enable clock for ADC domain
adc_off(ADC1); // switch off ADC while configuring it
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC); // use 28.5 cycles to sample (long enough to be stable)
adc_enable_temperature_sensor(ADC1); // enable internal voltage reference
adc_enable_external_trigger_regular(ADC1, ADC_CR2_EXTSEL_SWSTART); // use software trigger to start conversion
uint8_t rev_channels[] = {ADC_CHANNEL17, ADC_CHANNEL(BUSVOODOO_HW_REV_CHANNEL)}; // voltages to convert: internal, hardware revision
adc_set_regular_sequence(ADC1, LENGTH(rev_channels), rev_channels); // set channels to convert
adc_enable_discontinuous_mode_regular(ADC1, LENGTH(rev_channels)); // convert all channels
uint8_t version_channels[] = {ADC_CHANNEL17, ADC_CHANNEL(BUSVOODOO_HW_VERSION_CHANNEL)}; // voltages to convert: internal, hardware version
adc_set_regular_sequence(ADC1, LENGTH(version_channels), version_channels); // set channels to convert
adc_enable_discontinuous_mode_regular(ADC1, LENGTH(version_channels)); // convert all channels
adc_power_on(ADC1); // switch on ADC
sleep_us(1); // wait t_stab for the ADC to stabilize
adc_reset_calibration(ADC1); // remove previous non-calibration
adc_calibration(ADC1); // calibrate ADC for less accuracy errors
adc_start_conversion_regular(ADC1); // start conversion to get first voltage
uint16_t channels[LENGTH(rev_channels)] = {0}; // to store the values measured on the channels
uint16_t channels[LENGTH(version_channels)] = {0}; // to store the values measured on the channels
for (uint8_t channel_i=0; channel_i<LENGTH(channels); channel_i++) { // get all conversions
while (!adc_eoc(ADC1)); // wait until conversion finished
channels[channel_i] = adc_read_regular(ADC1); // read voltage value (clears flag)
}
float revision_voltage = channels[1]*1.2/channels[0]; // calculate voltage
float version_voltage = channels[1]*1.2/channels[0]; // calculate voltage
// find out revision of the board
gpio_set_mode(GPIO(BUSVOODOO_HW_REV_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(BUSVOODOO_HW_REV_PIN)); // use pull up and down to check if a voltage divider is present on the pin
gpio_set(GPIO(BUSVOODOO_HW_REV_PORT), GPIO(BUSVOODOO_HW_REV_PIN)); // pull up
bool rev_up = (0!=gpio_get(GPIO(BUSVOODOO_HW_REV_PORT), GPIO(BUSVOODOO_HW_REV_PIN))); // check if the signal is still up
gpio_clear(GPIO(BUSVOODOO_HW_REV_PORT), GPIO(BUSVOODOO_HW_REV_PIN)); // pull down
bool rev_down = (0==gpio_get(GPIO(BUSVOODOO_HW_REV_PORT), GPIO(BUSVOODOO_HW_REV_PIN))); // check if the signal is still down
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HW_REV_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_HW_REV_CHANNEL)); // put back to analog input
// get revision
if (rev_up && rev_down) { // no voltage divider on pin
busvoodoo_revision = 18; // the pin is floating only for revision 18
// find out version of the board
gpio_set_mode(GPIO(BUSVOODOO_HW_VERSION_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(BUSVOODOO_HW_VERSION_PIN)); // use pull up and down to check if a voltage divider is present on the pin
gpio_set(GPIO(BUSVOODOO_HW_VERSION_PORT), GPIO(BUSVOODOO_HW_VERSION_PIN)); // pull up
bool version_up = (0!=gpio_get(GPIO(BUSVOODOO_HW_VERSION_PORT), GPIO(BUSVOODOO_HW_VERSION_PIN))); // check if the signal is still up
gpio_clear(GPIO(BUSVOODOO_HW_VERSION_PORT), GPIO(BUSVOODOO_HW_VERSION_PIN)); // pull down
bool version_down = (0==gpio_get(GPIO(BUSVOODOO_HW_VERSION_PORT), GPIO(BUSVOODOO_HW_VERSION_PIN))); // check if the signal is still down
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HW_VERSION_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_HW_VERSION_CHANNEL)); // put back to analog input
// get version
if (version_up && version_down) { // no voltage divider on pin
busvoodoo_version = '0'; // the pin is floating only for version 0 (= revision 18)
} else { // voltage divider on pin
for (uint8_t i=0; i<LENGTH(busvoodoo_revision_numbers) && i<LENGTH(busvoodoo_revision_voltages); i++) { // go through expected revision voltages
if (revision_voltage>busvoodoo_revision_voltages[i]-0.2 && revision_voltage<busvoodoo_revision_voltages[i]+0.2) { // verify if voltage matches
busvoodoo_revision = busvoodoo_revision_numbers[i]; // remember revision number for matching voltage
for (uint8_t i=0; i<LENGTH(busvoodoo_version_voltages); i++) { // go through expected version voltages
if (version_voltage>busvoodoo_version_voltages[i]-0.2 && version_voltage<busvoodoo_version_voltages[i]+0.2) { // verify if voltage matches
busvoodoo_version = 'A'+i; // remember version name for matching voltage
break; // stop searching
}
}
}
}
// setup ADC to measure the 5V, 3.3V, LV, and HV power rails voltages
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_5V_CHANNEL)); // enable clock for GPIO domain for 5V channel
@ -139,8 +136,8 @@ void busvoodoo_setup(void)
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_LV_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_LV_CHANNEL)); // set LV channel as analogue input for the ADC
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_HV_CHANNEL)); // enable clock for GPIO domain for HV channel
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HV_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_HV_CHANNEL)); // set HV channel as analogue input for the ADC
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_HW_REV_CHANNEL)); // enable clock for GPIO domain for hardware revision channel
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HW_REV_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_HW_REV_CHANNEL)); // set hardware revision channel as analogue input for the ADC
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_HW_VERSION_CHANNEL)); // enable clock for GPIO domain for hardware version channel
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_HW_VERSION_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_HW_VERSION_CHANNEL)); // set hardware version channel as analogue input for the ADC
rcc_periph_clock_enable(RCC_ADC1); // enable clock for ADC domain
adc_off(ADC1); // switch off ADC while configuring it
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC); // use 28.5 cycles to sample (long enough to be stable)
@ -217,7 +214,7 @@ void busvoodoo_safe_state(void)
gpio_set_mode(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_DE_PIN)); // there is also an external pull-down resistor to disable per default
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating
gpio_set_mode(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_RX_PIN)); // set pin to floating
// disable CAN transceiver and signals (put back to input floating)
gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_TX_PIN)); // set pin to floating
gpio_set_mode(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_RX_PIN)); // set pin to floating
@ -270,10 +267,11 @@ float busvoodoo_vreg_get(uint8_t channel)
break;
}
adc_set_regular_sequence(ADC1, LENGTH(channels), channels); // set channels to convert
adc_enable_discontinuous_mode_regular(ADC1, LENGTH(channels)); // convert all channels
adc_enable_discontinuous_mode_regular(ADC1, LENGTH(channels)); // convert all channels
ADC_SR(ADC1) = 0; // reset flags
adc_start_conversion_regular(ADC1); // start conversion to get first voltage
uint16_t values[LENGTH(channels)] = {0}; // to store converted values
for (uint8_t channel_i=0; channel_i<LENGTH(channels); channel_i++) { // get all conversions
for (uint8_t channel_i=0; channel_i<LENGTH(channels); channel_i++) { // get all conversions
while (!adc_eoc(ADC1)); // wait until conversion finished
values[channel_i] = adc_read_regular(ADC1); // read voltage value (clears flag)
}
@ -509,9 +507,9 @@ static void busvoodoo_global_hv(void* argument)
float voltage = busvoodoo_vreg_get(BUSVOODOO_HV_CHANNEL); // get HV voltage
// print LV voltage
if (voltage < 0.1) {
printf(": 0.00V\n");
printf("0.00V\n");
} else {
printf(": %.2fV\n", voltage);
printf("%.2fV\n", voltage);
}
} else {
double voltage = *((double*)argument); // get desired voltage

View File

@ -97,11 +97,11 @@
#define BUSVOODOO_CAN_RX_PIN 8 /**< CAN Receive input pin */
/** @} */
/** @defgroup busvoodoo_revision ADC pin used to identify hardware revision based on voltage
/** @defgroup busvoodoo_version ADC pin used to identify hardware version based on voltage
*/
#define BUSVOODOO_HW_REV_PORT B /**< pin to identify hardware revision */
#define BUSVOODOO_HW_REV_PIN 0 /**< pin to identify hardware revision */
#define BUSVOODOO_HW_REV_CHANNEL 8 /**< ADC to identify hardware revision */
#define BUSVOODOO_HW_VERSION_PORT B /**< pin to identify hardware version */
#define BUSVOODOO_HW_VERSION_PIN 0 /**< pin to identify hardware version */
#define BUSVOODOO_HW_VERSION_CHANNEL 8 /**< ADC to identify hardware version */
/** @} */
/** BusVoodoo mode interface */
@ -125,8 +125,8 @@ extern const uint8_t busvoodoo_io_groups[13]; /**< which I/O pin (group) does th
/** is the BusVoodoo board fully populated (with HV voltage regulator, RS-232, RS-485, CAN transceiver on the back side) */
extern bool busvoodoo_full;
/** revision of the hardware board */
extern uint8_t busvoodoo_revision;
/** version of the hardware board */
extern char busvoodoo_version;
/** list of supported commands */
extern const struct menu_command_t busvoodoo_global_commands[4];