BV: rename xV to LV and 12V to HV

This commit is contained in:
King Kévin 2018-02-06 21:17:37 +01:00
parent b885553c6c
commit 2df0fbf96f
3 changed files with 161 additions and 162 deletions

View File

@ -70,31 +70,31 @@ void busvoodoo_setup(void)
busvoodoo_safe_state(); // switch off all outputs
// check if this BusVoodoo is a full version
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_12V_CHANNEL)); // enable clock for GPIO domain for 12V channel
gpio_set(ADC12_IN_PORT(BUSVOODOO_12V_CHANNEL), ADC12_IN_PIN(BUSVOODOO_12V_CHANNEL)); // pull ADC 12V high
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_12V_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, ADC12_IN_PIN(BUSVOODOO_12V_CHANNEL)); // set 12V channel as digital input with pull-up capabilities
// on a full version (fully populated board) the ADC 12V signal will be pulled low
if (gpio_get(ADC12_IN_PORT(BUSVOODOO_12V_CHANNEL), ADC12_IN_PIN(BUSVOODOO_12V_CHANNEL))) { // check is ADC 12V is pulled low
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
// on a full version (fully populated board) the ADC HV signal will be pulled low
if (gpio_get(ADC12_IN_PORT(BUSVOODOO_HV_CHANNEL), ADC12_IN_PIN(BUSVOODOO_HV_CHANNEL))) { // check is ADC HV is pulled low
busvoodoo_full = false;
} else {
busvoodoo_full = true;
}
// setup ADC to measure the 5V, 3.3V, xV, and 12V power rails voltages
// 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
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_5V_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_5V_CHANNEL)); // set 5V channel as analogue input for the ADC
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_3V3_CHANNEL)); // enable clock for GPIO domain for 3.3V channel
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_3V3_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_3V3_CHANNEL)); // set 3.3V channel as analogue input for the ADC
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_XV_CHANNEL)); // enable clock for GPIO domain for xV channel
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_XV_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_XV_CHANNEL)); // set xV channel as analogue input for the ADC
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_12V_CHANNEL)); // enable clock for GPIO domain for 12V channel
gpio_set_mode(ADC12_IN_PORT(BUSVOODOO_12V_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(BUSVOODOO_12V_CHANNEL)); // set 12V channel as analogue input for the ADC
rcc_periph_clock_enable(RCC_ADC12_IN(BUSVOODOO_LV_CHANNEL)); // enable clock for GPIO domain for LV channel
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_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 channels[] = {ADC_CHANNEL17, ADC_CHANNEL(BUSVOODOO_5V_CHANNEL), ADC_CHANNEL(BUSVOODOO_3V3_CHANNEL), ADC_CHANNEL(BUSVOODOO_XV_CHANNEL), ADC_CHANNEL(BUSVOODOO_12V_CHANNEL)}; // voltages to convert: internal, 5V, 3.3V, xV, 12V
uint8_t channels[] = {ADC_CHANNEL17, ADC_CHANNEL(BUSVOODOO_5V_CHANNEL), ADC_CHANNEL(BUSVOODOO_3V3_CHANNEL), ADC_CHANNEL(BUSVOODOO_LV_CHANNEL), ADC_CHANNEL(BUSVOODOO_HV_CHANNEL)}; // voltages to convert: internal, 5V, 3.3V, LV, HV
adc_set_regular_sequence(ADC1, LENGTH(channels), channels); // set channels to convert
adc_enable_discontinuous_mode_regular(ADC1, LENGTH(channels)); // convert all channels
adc_power_on(ADC1); // switch on ADC
@ -102,15 +102,15 @@ void busvoodoo_setup(void)
adc_reset_calibration(ADC1); // remove previous non-calibration
adc_calibration(ADC1); // calibrate ADC for less accuracy errors
// setup DAC to control xV and 12V voltage outputs
gpio_set_mode(GPIO(BUSVOODOO_XVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_XVCTL_PIN)); // set xV pin as analog (the DAC will use it as output)
// setup DAC to control LV and HV voltage outputs
gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV pin as analog (the DAC will use it as output)
rcc_periph_clock_enable(RCC_DAC); // enable clock for DAC domain
dac_disable(BUSVOODOO_XVCTL_CHANNEL); // disable output to configure it properly
dac_buffer_enable(BUSVOODOO_XVCTL_CHANNEL); // enable output buffer to be able to drive larger loads (should be per default)
dac_disable(BUSVOODOO_LVCTL_CHANNEL); // disable output to configure it properly
dac_buffer_enable(BUSVOODOO_LVCTL_CHANNEL); // enable output buffer to be able to drive larger loads (should be per default)
if (busvoodoo_full) {
gpio_set_mode(GPIO(BUSVOODOO_12VCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_12VCTL_PIN)); // set 12V pin as analog (the DAC will use it as output)
dac_disable(BUSVOODOO_12VCTL_CHANNEL); // disable output to configure it properly
dac_buffer_enable(BUSVOODOO_12VCTL_CHANNEL); // enable output buffer to be able to drive larger loads (should be per default)
gpio_set_mode(GPIO(BUSVOODOO_HVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_HVCTL_PIN)); // set HV pin as analog (the DAC will use it as output)
dac_disable(BUSVOODOO_HVCTL_CHANNEL); // disable output to configure it properly
dac_buffer_enable(BUSVOODOO_HVCTL_CHANNEL); // enable output buffer to be able to drive larger loads (should be per default)
}
dac_set_trigger_source(DAC_CR_TSEL1_SW); // use software to trigger the voltage change
dac_set_trigger_source(DAC_CR_TSEL2_SW); // use software to trigger the voltage change
@ -129,14 +129,14 @@ void busvoodoo_safe_state(void)
// disable voltage outputs
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable 5V and 3.3V output on connector
gpio_set_mode(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_VOUTEN_PIN)); // set pin as output (open-drain pulled high to disable the pMOS)
gpio_clear(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // disable xV voltage regulator
gpio_set_mode(GPIO(BUSVOODOO_XVEN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_XVEN_PIN)); // set pin as output (push-pull, pulled low for safety)
gpio_set(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // disable 12V voltage regulator
gpio_set_mode(GPIO(BUSVOODOO_12VEN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_12VEN_PIN)); // set pin as output (open-drain pulled high to disable the pMOS)
gpio_clear(GPIO(BUSVOODOO_LVEN_PORT), GPIO(BUSVOODOO_LVEN_PIN)); // disable LV voltage regulator
gpio_set_mode(GPIO(BUSVOODOO_LVEN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_LVEN_PIN)); // set pin as output (push-pull, pulled low for safety)
gpio_set(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // disable HV voltage regulator
gpio_set_mode(GPIO(BUSVOODOO_HVEN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_HVEN_PIN)); // set pin as output (open-drain pulled high to disable the pMOS)
// set DAC channel back to analog
gpio_set_mode(GPIO(BUSVOODOO_XVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_XVCTL_PIN)); // set xV pin as analog
gpio_set_mode(GPIO(BUSVOODOO_12VCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_12VCTL_PIN)); // set 12V pin as analog
gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV pin as analog
gpio_set_mode(GPIO(BUSVOODOO_HVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_HVCTL_PIN)); // set HV pin as analog
// disable embedded pull-ups
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, 0); // disable JTAG (but keep SWD) so to use the underlying GPIOs (PA15, PB3, PB4)
@ -190,10 +190,10 @@ bool busvoodoo_vout_switch(bool on)
float busvoodoo_vreg_get(uint8_t channel)
{
if (channel!=BUSVOODOO_5V_CHANNEL && channel!=BUSVOODOO_3V3_CHANNEL && channel!=BUSVOODOO_XV_CHANNEL && channel!=BUSVOODOO_12V_CHANNEL) { // check channel
if (channel!=BUSVOODOO_5V_CHANNEL && channel!=BUSVOODOO_3V3_CHANNEL && channel!=BUSVOODOO_LV_CHANNEL && channel!=BUSVOODOO_HV_CHANNEL) { // check channel
return NAN;
}
uint16_t channels[5] = {0}; // to start converted values: internal reference 1.2V, 5V rail, 3.3V rail, xV rail, 12V rail
uint16_t channels[5] = {0}; // to start converted values: internal reference 1.2V, 5V rail, 3.3V rail, LV rail, HV rail
adc_start_conversion_regular(ADC1); // start conversion to get first voltage
for (uint8_t channel_i=0; channel_i<LENGTH(channels); channel_i++) { // get all conversions
while (!adc_eoc(ADC1)); // wait until conversion finished
@ -207,10 +207,10 @@ float busvoodoo_vreg_get(uint8_t channel)
case BUSVOODOO_3V3_CHANNEL:
to_return = channels[2]/(10.0/(10.0+10.0));
break;
case BUSVOODOO_XV_CHANNEL:
case BUSVOODOO_LV_CHANNEL:
to_return = channels[3]/(10.0/(10.0+10.0));
break;
case BUSVOODOO_12V_CHANNEL:
case BUSVOODOO_HV_CHANNEL:
to_return = channels[4]/(1.5/(10.0+1.5));
break;
default: // unknown channel
@ -225,40 +225,40 @@ float busvoodoo_vreg_get(uint8_t channel)
float busvoodoo_vreg_set(uint8_t channel, float voltage)
{
if (channel!=BUSVOODOO_XV_CHANNEL && channel!=BUSVOODOO_12V_CHANNEL) { // check channel
if (channel!=BUSVOODOO_LV_CHANNEL && channel!=BUSVOODOO_HV_CHANNEL) { // check channel
return NAN;
}
if (BUSVOODOO_12V_CHANNEL==channel && !busvoodoo_full) { // the 12V voltage regulator is only present on the full version
if (BUSVOODOO_HV_CHANNEL==channel && !busvoodoo_full) { // the HV voltage regulator is only present on the full version
return NAN;
}
float volt = NAN; // common variable for voltages
if (BUSVOODOO_XV_CHANNEL==channel) { // set voltage on xV low drop-out voltage regulator
if (BUSVOODOO_LV_CHANNEL==channel) { // set voltage on LV low drop-out voltage regulator
if (voltage<=0.3) { // disable voltage regulator
gpio_clear(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // disable xV voltage regulator
dac_disable(BUSVOODOO_XVCTL_CHANNEL); // disable xV control
gpio_clear(GPIO(BUSVOODOO_LVEN_PORT), GPIO(BUSVOODOO_LVEN_PIN)); // disable LV voltage regulator
dac_disable(BUSVOODOO_LVCTL_CHANNEL); // disable LV control
} else { // enable voltage regulator
if (voltage>4.85) { // use the 5V directly
gpio_clear(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // put 5V on xV line
gpio_clear(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // put 5V on LV line
} else { // use adjustable voltage regulator (5.0V rail minus LDO and diodes)
gpio_set(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // disable 5V input
volt = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get reference voltage
if (isnan(voltage)) {
return NAN;
}
uint16_t dac_set = BUSVOODOO_XV_SET(voltage)/volt*4095; // DAC value corresponding to the voltage
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOODOO_XVCTL_CHANNEL); // set output so the voltage regulator is set to 2.5V
dac_software_trigger(BUSVOODOO_XVCTL_CHANNEL); // transfer the value to the DAC
dac_enable(BUSVOODOO_XVCTL_CHANNEL); // enable DAC
gpio_set(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // enable xV voltage regulator
uint16_t dac_set = BUSVOODOO_LV_SET(voltage)/volt*4095; // DAC value corresponding to the voltage
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOODOO_LVCTL_CHANNEL); // set output so the voltage regulator is set to 2.5V
dac_software_trigger(BUSVOODOO_LVCTL_CHANNEL); // transfer the value to the DAC
dac_enable(BUSVOODOO_LVCTL_CHANNEL); // enable DAC
gpio_set(GPIO(BUSVOODOO_LVEN_PORT), GPIO(BUSVOODOO_LVEN_PIN)); // enable LV voltage regulator
}
}
sleep_ms(10); // let voltage settle
volt = busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL); // get xV voltage to return
} else if (BUSVOODOO_12V_CHANNEL==channel && busvoodoo_full) {// set voltage on 12V boost voltage regulator
volt = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get LV voltage to return
} else if (BUSVOODOO_HV_CHANNEL==channel && busvoodoo_full) {// set voltage on HV boost voltage regulator
if (voltage<3.29) { // disable voltage regulator
gpio_set(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // disable 12V voltage regulator
dac_disable(BUSVOODOO_12VCTL_CHANNEL); // disable 12V control
gpio_set(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // disable HV voltage regulator
dac_disable(BUSVOODOO_HVCTL_CHANNEL); // disable HV control
} else {
if (voltage>24.0) { // enforce upper voltage limit (diodes limit is 30V, ADC input limit is 25V)
voltage = 24.0;
@ -267,14 +267,14 @@ float busvoodoo_vreg_set(uint8_t channel, float voltage)
if (isnan(voltage)) {
return NAN;
}
uint16_t dac_set = BUSVOODOO_12V_SET(voltage)/volt*4095; // DAC value corresponding to the voltage
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOODOO_12VCTL_CHANNEL); // set output so the voltage regulator is set to desired output voltage
dac_software_trigger(BUSVOODOO_12VCTL_CHANNEL); // transfer the value to the DAC
dac_enable(BUSVOODOO_12VCTL_CHANNEL); // enable DAC
gpio_clear(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // enable 12V voltage regulator
uint16_t dac_set = BUSVOODOO_HV_SET(voltage)/volt*4095; // DAC value corresponding to the voltage
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOODOO_HVCTL_CHANNEL); // set output so the voltage regulator is set to desired output voltage
dac_software_trigger(BUSVOODOO_HVCTL_CHANNEL); // transfer the value to the DAC
dac_enable(BUSVOODOO_HVCTL_CHANNEL); // enable DAC
gpio_clear(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // enable HV voltage regulator
}
sleep_ms(100); // let the voltage regulator start and voltage settle
volt = busvoodoo_vreg_get(BUSVOODOO_12V_CHANNEL); // get 12V voltage
volt = busvoodoo_vreg_get(BUSVOODOO_HV_CHANNEL); // get HV voltage
} else { // don't know about other voltage regulators
volt = NAN;
}
@ -289,7 +289,7 @@ float busvoodoo_embedded_pullup(bool on)
} else { // disable embedded pull-ups
gpio_set(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO(BUSVOODOO_OEPULLUP_PIN)); // switch off embedded pull-up
}
return busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL); // set voltage on adjustable voltage regulator to be used by the embedded pull-ups
return busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // set voltage on adjustable voltage regulator to be used by the embedded pull-ups
}
/** update LED status according to LED flags */
@ -388,13 +388,13 @@ static void busvoodoo_global_lv(void* argument)
if (NULL==argument) {
if (!gpio_get(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN))) { // 5V input enabled
printf("5V power rail used");
} else if (gpio_get(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN))) { // xV voltage regulator used
} else if (gpio_get(GPIO(BUSVOODOO_LVEN_PORT), GPIO(BUSVOODOO_LVEN_PIN))) { // LV voltage regulator used
printf("adjustable voltage regulator used");
} else {
printf("external voltage input");
}
float voltage = busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL); // get xV voltage
// print xV voltage
float voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get LV voltage
// print LV voltage
if (voltage < 0.1) {
printf(": 0.00V\n");
} else {
@ -403,12 +403,12 @@ static void busvoodoo_global_lv(void* argument)
} else {
double voltage = *((double*)argument); // get desired voltage
if (0==voltage) {
printf("xV rail switched off");
printf("LV rail switched off");
} else {
printf("xV rail set to %.2fV", voltage);
printf("LV rail set to %.2fV", voltage);
}
voltage = busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, voltage); // set xV voltage
// print xV voltage
voltage = busvoodoo_vreg_set(BUSVOODOO_LV_CHANNEL, voltage); // set LV voltage
// print LV voltage
if (voltage < 0.1) {
printf(": 0.00V\n");
} else {
@ -427,9 +427,9 @@ static void busvoodoo_global_hv(void* argument)
return;
}
if (NULL==argument) {
printf("high voltage regulator switched %s: ", gpio_get(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)) ? "off" : "on");
float voltage = busvoodoo_vreg_get(BUSVOODOO_12V_CHANNEL); // get 12V voltage
// print xV voltage
printf("high voltage regulator switched %s: ", gpio_get(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)) ? "off" : "on");
float voltage = busvoodoo_vreg_get(BUSVOODOO_HV_CHANNEL); // get HV voltage
// print LV voltage
if (voltage < 0.1) {
printf(": 0.00V\n");
} else {
@ -443,8 +443,8 @@ static void busvoodoo_global_hv(void* argument)
} else {
printf("set to %.2fV", voltage);
}
voltage = busvoodoo_vreg_set(BUSVOODOO_12V_CHANNEL, voltage); // set 12V voltage
// print xV voltage
voltage = busvoodoo_vreg_set(BUSVOODOO_HV_CHANNEL, voltage); // set HV voltage
// print HV voltage
if (voltage < 0.1) {
printf(": 0.00V\n");
} else {

View File

@ -26,10 +26,10 @@
#define BUSVOODOO_5VPULLUP_PIN 4 /**< 5V pull-up enable pin (active low) */
#define BUSVOODOO_OEPULLUP_PORT A /**< bus switch output enable pin to enable embedded pull-ups (active low) */
#define BUSVOODOO_OEPULLUP_PIN 15 /**< bus switch output enable pin to enable embedded pull-ups (active low) */
#define BUSVOODOO_XVEN_PORT A /**< xV enable pin (active high) */
#define BUSVOODOO_XVEN_PIN 6 /**< xV enable pin (active high) */
#define BUSVOODOO_12VEN_PORT A /**< 12V enable pin (active low) */
#define BUSVOODOO_12VEN_PIN 7 /**< 12V enable pin (active low) */
#define BUSVOODOO_LVEN_PORT A /**< low voltage (LV) enable pin (active high) */
#define BUSVOODOO_LVEN_PIN 6 /**< low voltage (LV) enable pin (active high) */
#define BUSVOODOO_HVEN_PORT A /**< high voltage (HV) enable pin (active low) */
#define BUSVOODOO_HVEN_PIN 7 /**< high voltage (HV) enable pin (active low) */
#define BUSVOODOO_VOUTEN_PORT B /**< voltage output (5V and 3.3V) enable pin (active low) */
#define BUSVOODOO_VOUTEN_PIN 3 /**< voltage output (5V and 3.3V) enable pin (active low) */
/** @} */
@ -39,22 +39,21 @@
*/
#define BUSVOODOO_3V3_CHANNEL 12 /**< ADC channel to measure 5V rail */
#define BUSVOODOO_5V_CHANNEL 9 /**< ADC channel to measure 3.3V rail */
#define BUSVOODOO_XV_CHANNEL 11 /**< ADC channel to measure xV rail */
#define BUSVOODOO_12V_CHANNEL 15 /**< ADC channel to measure 12V rail */
#define BUSVOODOO_LV_CHANNEL 11 /**< ADC channel to measure LV rail */
#define BUSVOODOO_HV_CHANNEL 15 /**< ADC channel to measure HV rail */
/** @} */
/** @defgroup busvoodoo_dac DAC output to set voltages of voltage regulators
* @{
*/
#define BUSVOODOO_XVCTL_PORT A /**< pin to control xV output voltage */
#define BUSVOODOO_XVCTL_PIN 4 /**< pin to control xV output voltage */
#define BUSVOODOO_XVCTL_CHANNEL CHANNEL_1 /**< DAC channel to control xV output voltage */
#define BUSVOODOO_XV_SET(x) ((0.8*(1+30.0/10.0)-x)*(10.0/30.0)+0.8) /**< voltage to output for the DAC to set the desired xV output voltage (based on resistor values on the xV adjust pins and xV voltage reference) */
#define BUSVOODOO_12VCTL_PORT A /**< pin to control 12V output voltage */
#define BUSVOODOO_12VCTL_PIN 5 /**< pin to control 12V output voltage */
#define BUSVOODOO_12VCTL_CHANNEL CHANNEL_2 /**< DAC channel to control 12V output voltage */
#define BUSVOODOO_12V_SET(x) ((1.25*(1+100.0/10.0)-x)*(10.0/100.0)+1.25) /**< voltage to output for the DAC to set the desired
12V output voltage (based on resistor values on the 12V adjust pins and 12V voltage reference) */
#define BUSVOODOO_LVCTL_PORT A /**< pin to control LV output voltage */
#define BUSVOODOO_LVCTL_PIN 4 /**< pin to control LV output voltage */
#define BUSVOODOO_LVCTL_CHANNEL CHANNEL_1 /**< DAC channel to control LV output voltage */
#define BUSVOODOO_LV_SET(x) ((0.8*(1+30.0/10.0)-x)*(10.0/30.0)+0.8) /**< voltage to output for the DAC to set the desired LV output voltage (based on resistor values on the LV adjust pins and LV voltage reference) */
#define BUSVOODOO_HVCTL_PORT A /**< pin to control HV output voltage */
#define BUSVOODOO_HVCTL_PIN 5 /**< pin to control HV output voltage */
#define BUSVOODOO_HVCTL_CHANNEL CHANNEL_2 /**< DAC channel to control HV output voltage */
#define BUSVOODOO_HV_SET(x) ((1.25*(1+100.0/10.0)-x)*(10.0/100.0)+1.25) /**< voltage to output for the DAC to set the desired HV output voltage (based on resistor values on the HV adjust pins and HV voltage reference) */
/** @} */
/** @defgroup busvoodoo_rs232 RS-232 transceiver connection definition
@ -131,15 +130,15 @@ bool busvoodoo_vout_switch(bool on);
*/
float busvoodoo_vreg_get(uint8_t channel);
/** set voltage on adjustable voltage regulator
* @warning only xV and 12V are adjustable voltage regulators
* @note for voltages above 4.7V on xV it will use the 5.0V from USB
* @warning only LV and 12V are adjustable voltage regulators
* @note for voltages above 4.7V on LV it will use the 5.0V from USB
* @param[in] channel which voltage regulator to set voltage on @ref busvoodoo_adc
* @param[in] voltage voltage to set on adjustable voltage regulator
* @return voltage output, or NaN if channel is invalid (or error happened)
*/
float busvoodoo_vreg_set(uint8_t channel, float voltage);
/** enable embedded pull-up resistors
* @note the embedded pull-up resistor use the voltage on the xV power rail (set or externally provided)
* @note the embedded pull-up resistor use the voltage on the LV power rail (set or externally provided)
* @param[in] on enable (true) or disable (false) embedded pull-up resistors
* @return voltage applied on pull-up resistors, or NaN if channel is invalid (or error happened)
*/

View File

@ -36,10 +36,10 @@
#include "busvoodoo_oled.h" // OLED utilities
#include "busvoodoo_hiz.h" // own definitions
#define BUSVOODOO_XV_DEFAULT (0.8*(1+30.0/10.0)) /**< default (when not driven) xV voltage regulator output voltage based on R1 and R2 */
#define BUSVOODOO_XV_TEST 2.5 /**< target xV output voltage to test if we can set control the xV voltage regulator */
#define BUSVOODOO_12V_DEFAULT (1.25*(1+100.0/10.0)) /**< default (when not driven) 12V voltage regulator output voltage based on R1 and R2 */
#define BUSVOODOO_12V_TEST 12.0 /**< target 12V output voltage to test if we can set control the 12V voltage regulator */
#define BUSVOODOO_LV_DEFAULT (0.8*(1+30.0/10.0)) /**< default (when not driven) LV voltage regulator output voltage based on R1 and R2 */
#define BUSVOODOO_LV_TEST 2.5 /**< target LV output voltage to test if we can set control the LV voltage regulator */
#define BUSVOODOO_HV_DEFAULT (1.25*(1+100.0/10.0)) /**< default (when not driven) HV voltage regulator output voltage based on R1 and R2 */
#define BUSVOODOO_HV_TEST 12.0 /**< target HV output voltage to test if we can set control the HV voltage regulator */
/** setup HiZ mode
* @param[out] prefix terminal prompt prefix
@ -165,29 +165,29 @@ static bool busvoodoo_hiz_test_self(void)
}
busvoodoo_vout_switch(false); // disable Vout
// check xV voltage regulator
voltage = busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, 0); // disable xV voltage regulator
// check LV voltage regulator
voltage = busvoodoo_vreg_set(BUSVOODOO_LV_CHANNEL, 0); // disable LV voltage regulator
if (voltage>0.2) { // ensure the output is at 0V when the regulator is not enabled
printf("xV voltage is %.2fV instead of 0V when the regulator is disabled\n", voltage);
printf("LV voltage is %.2fV instead of 0V when the regulator is disabled\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // enable xV voltage regulator
gpio_set(GPIO(BUSVOODOO_LVEN_PORT), GPIO(BUSVOODOO_LVEN_PIN)); // enable LV voltage regulator
sleep_ms(5); // let the voltage regulator start and voltage settle
voltage = busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL); // get xV voltage
voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get LV voltage
// without being driven it should be around the default voltage
if (voltage<BUSVOODOO_XV_DEFAULT-0.2) {
printf("xV voltage is lower (%.2fV) than expected (%.2fV) when the regulator is enabled\n", voltage, BUSVOODOO_XV_DEFAULT);
if (voltage<BUSVOODOO_LV_DEFAULT-0.2) {
printf("LV voltage is lower (%.2fV) than expected (%.2fV) when the regulator is enabled\n", voltage, BUSVOODOO_LV_DEFAULT);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_XV_DEFAULT+0.2) {
printf("xV voltage is higher (%.2fV) than expected (%.2fV) when the regulator is enabled\n", voltage, BUSVOODOO_XV_DEFAULT);
} else if (voltage>BUSVOODOO_LV_DEFAULT+0.2) {
printf("LV voltage is higher (%.2fV) than expected (%.2fV) when the regulator is enabled\n", voltage, BUSVOODOO_LV_DEFAULT);
#if DEBUG
while (true);
#else
@ -195,49 +195,49 @@ static bool busvoodoo_hiz_test_self(void)
#endif
}
// check if we can control xV
voltage = busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, BUSVOODOO_XV_TEST); // get xV voltage
if (voltage<BUSVOODOO_XV_TEST-0.2) {
printf("xV voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_XV_TEST);
// check if we can control LV
voltage = busvoodoo_vreg_set(BUSVOODOO_LV_CHANNEL, BUSVOODOO_LV_TEST); // get LV voltage
if (voltage<BUSVOODOO_LV_TEST-0.2) {
printf("LV voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_LV_TEST);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_XV_TEST+0.2) {
printf("xV voltage is highed (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_XV_TEST);
} else if (voltage>BUSVOODOO_LV_TEST+0.2) {
printf("LV voltage is highed (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_LV_TEST);
#if DEBUG
while (true);
#else
goto error;
#endif
}
busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, 0); // disable xV voltage regulator
busvoodoo_vreg_set(BUSVOODOO_LV_CHANNEL, 0); // disable LV voltage regulator
// check 12V voltage regulator
// check HV voltage regulator
if (busvoodoo_full) {
voltage = busvoodoo_vreg_set(BUSVOODOO_12V_CHANNEL, 0); // disable 12V voltage regulator
voltage = busvoodoo_vreg_set(BUSVOODOO_HV_CHANNEL, 0); // disable HV voltage regulator
if (voltage>0.2) { // ensure the output is at 0V when the regulator is not enabled
printf("12V voltage is %.2fV instead of 0V when the regulator is disabled\n", voltage);
printf("HV voltage is %.2fV instead of 0V when the regulator is disabled\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_clear(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // enable 12V voltage regulator
gpio_clear(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // enable HV voltage regulator
sleep_ms(10); // let the voltage regulator start and voltage settle
voltage = busvoodoo_vreg_get(BUSVOODOO_12V_CHANNEL); // get 12V voltage
voltage = busvoodoo_vreg_get(BUSVOODOO_HV_CHANNEL); // get HV voltage
// without being driven it should be around the default voltage
if (voltage<BUSVOODOO_12V_DEFAULT-0.3) {
printf("12V voltage is lower (%.2fV) than expected (%.2fV) when regulator is enabled\n", voltage, BUSVOODOO_12V_DEFAULT);
if (voltage<BUSVOODOO_HV_DEFAULT-0.3) {
printf("HV voltage is lower (%.2fV) than expected (%.2fV) when regulator is enabled\n", voltage, BUSVOODOO_HV_DEFAULT);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_12V_DEFAULT+0.3) {
printf("12V voltage is higher (%.2fV) than expected (%.2fV) when regulator is enabled\n", voltage, BUSVOODOO_12V_DEFAULT);
} else if (voltage>BUSVOODOO_HV_DEFAULT+0.3) {
printf("HV voltage is higher (%.2fV) than expected (%.2fV) when regulator is enabled\n", voltage, BUSVOODOO_HV_DEFAULT);
#if DEBUG
while (true);
#else
@ -245,24 +245,24 @@ static bool busvoodoo_hiz_test_self(void)
#endif
}
// check if we can control 12V voltage regulator
voltage = busvoodoo_vreg_set(BUSVOODOO_12V_CHANNEL, BUSVOODOO_12V_TEST); // set voltage on 12V voltage regulator
if (voltage<BUSVOODOO_12V_TEST-0.3) {
printf("12V voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_12V_TEST);
// check if we can control HV voltage regulator
voltage = busvoodoo_vreg_set(BUSVOODOO_HV_CHANNEL, BUSVOODOO_HV_TEST); // set voltage on HV voltage regulator
if (voltage<BUSVOODOO_HV_TEST-0.3) {
printf("HV voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_HV_TEST);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_12V_TEST+0.3) {
printf("12V voltage is higher (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_12V_TEST);
} else if (voltage>BUSVOODOO_HV_TEST+0.3) {
printf("HV voltage is higher (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_HV_TEST);
#if DEBUG
while (true);
#else
goto error;
#endif
}
voltage = busvoodoo_vreg_set(BUSVOODOO_12V_CHANNEL, 0); // disable 12V voltage regulator
voltage = busvoodoo_vreg_set(BUSVOODOO_HV_CHANNEL, 0); // disable HV voltage regulator
}
// pull all pins down and ensure they are low
@ -358,7 +358,7 @@ static bool busvoodoo_hiz_test_self(void)
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull down to ensure it is not high by accident
}
busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, 5.0); // set xV voltage regulator to use the 5.0V power rail
busvoodoo_vreg_set(BUSVOODOO_LV_CHANNEL, 5.0); // set LV voltage regulator to use the 5.0V power rail
voltage = busvoodoo_embedded_pullup(true); // enable 5V pull-up
if (voltage<4.0) {
printf("5V power rail voltage is too low when used to pull up: %.2fV\n", voltage);
@ -386,24 +386,24 @@ static bool busvoodoo_hiz_test_self(void)
}
}
busvoodoo_embedded_pullup(false); // disable pull-ups
voltage = busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, 0); // disable xV voltage regulator
voltage = busvoodoo_vreg_set(BUSVOODOO_LV_CHANNEL, 0); // disable LV voltage regulator
// test xV pull-up set to 3.3V
// test LV pull-up set to 3.3V
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull down to ensure it is not high by accident
}
busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, 3.3); // set xV voltage regulator
busvoodoo_vreg_set(BUSVOODOO_LV_CHANNEL, 3.3); // set LV voltage regulator
voltage = busvoodoo_embedded_pullup(3.3); // enable pull-up with adjustable regulator
if (voltage<BUSVOODOO_XV_DEFAULT-0.2) {
printf("xV voltage is lower (%.2fV) than expected (%.2fV) when used to pull up\n", voltage, BUSVOODOO_XV_DEFAULT);
if (voltage<BUSVOODOO_LV_DEFAULT-0.2) {
printf("LV voltage is lower (%.2fV) than expected (%.2fV) when used to pull up\n", voltage, BUSVOODOO_LV_DEFAULT);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_XV_DEFAULT+0.2) {
printf("xV voltage is higher (%.2fV) than expected (%.2fV) when used to pull up\n", voltage, BUSVOODOO_XV_DEFAULT);
} else if (voltage>BUSVOODOO_LV_DEFAULT+0.2) {
printf("LV voltage is higher (%.2fV) than expected (%.2fV) when used to pull up\n", voltage, BUSVOODOO_LV_DEFAULT);
#if DEBUG
while (true);
#else
@ -412,7 +412,7 @@ static bool busvoodoo_hiz_test_self(void)
}
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
if (!gpio_get(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin])) { // ensure it really is high
printf("signal %s is low although it is pulled up by xV (embedded)\n", busvoodoo_io_names[pin]); // warn user about the error
printf("signal %s is low although it is pulled up by LV (embedded)\n", busvoodoo_io_names[pin]); // warn user about the error
#if DEBUG
while (true);
#else
@ -420,7 +420,7 @@ static bool busvoodoo_hiz_test_self(void)
#endif
}
}
busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, 0); // disable xV voltage regulator
busvoodoo_vreg_set(BUSVOODOO_LV_CHANNEL, 0); // disable LV voltage regulator
busvoodoo_embedded_pullup(false); // disable pull-ups
to_return = true; // all tests are successful
@ -444,42 +444,42 @@ static bool busvoodoo_hiz_test_pins(void)
bool to_return = false; // test result to return
busvoodoo_safe_state(); // start from safe state with all outputs switched off
const char* xv_to = "connect I/O pin 4 to "; // most outputs will be tested using xV ADC
const char* xv_high = "pin 4 is high while it should be low, other pin might be defective\n"; // error message if expect low output is high
const char* lv_to = "connect I/O pin 4 to "; // most outputs will be tested using LV ADC
const char* lv_high = "pin 4 is high while it should be low, other pin might be defective\n"; // error message if expect low output is high
// test GND on pin 1 by shorting xV_CTL to ground (through 40k resistor) and measure short
gpio_set(GPIO(BUSVOODOO_XVCTL_PORT), GPIO(BUSVOODOO_XVCTL_PIN)); // set pin high
gpio_set_mode(GPIO(BUSVOODOO_XVCTL_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_XVCTL_PIN)); // set xV control pin as output
printf("%sI/O pin 1\n", xv_to);
while (busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL)>0.2) { // wait until pin is shorted to ground
// test GND on pin 1 by shorting LV_CTL to ground (through 40k resistor) and measure short
gpio_set(GPIO(BUSVOODOO_LVCTL_PORT), GPIO(BUSVOODOO_LVCTL_PIN)); // set pin high
gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV control pin as output
printf("%sI/O pin 1\n", lv_to);
while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) { // wait until pin is shorted to ground
sleep_ms(200); // wait for user to make connection
}
gpio_clear(GPIO(BUSVOODOO_XVCTL_PORT), GPIO(BUSVOODOO_XVCTL_PIN)); // set pin low
gpio_set_mode(GPIO(BUSVOODOO_XVCTL_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_XVCTL_PIN)); // set xV control pin as output
gpio_clear(GPIO(BUSVOODOO_LVCTL_PORT), GPIO(BUSVOODOO_LVCTL_PIN)); // set pin low
gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV control pin as output
led_toggle(); // notify user test is almost almost
sleep_ms(200); // wait for voltage to settle an debounce
if (busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL)>0.2) {
printf(xv_high);
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set_mode(GPIO(BUSVOODOO_XVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_XVCTL_PIN)); // set xV control pin back to analog input for DAC
gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV control pin back to analog input for DAC
led_toggle(); // notify user test is complete
// test 5V output on pin 2
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
printf("%sI/O pin 2\n", xv_to);
while (busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL)<0.2) { // wait until pin is connected
printf("%sI/O pin 2\n", lv_to);
while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
}
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL)>0.2) {
printf(xv_high);
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
#if DEBUG
while (true);
#else
@ -490,15 +490,15 @@ static bool busvoodoo_hiz_test_pins(void)
// test 3.3V output on pin 3
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
printf("%sI/O pin 3\n", xv_to);
while (busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL)<0.2 || busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL)>3.5) { // wait until pin is connected
printf("%sI/O pin 3\n", lv_to);
while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 || busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>3.5) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
}
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL)>0.2) {
printf(xv_high);
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
#if DEBUG
while (true);
#else
@ -513,15 +513,15 @@ static bool busvoodoo_hiz_test_pins(void)
if (busvoodoo_io_groups[pin]==io) {
gpio_set(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // set pin high
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, busvoodoo_io_pins[pin]); // set pin to output
printf("%sI/O pin %u\n", xv_to, io+4);
while (busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL)<0.2) { // wait until pin is connected
printf("%sI/O pin %u\n", lv_to, io+4);
while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
}
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // set pin low
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL)>0.2) {
printf(xv_high);
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
#if DEBUG
while (true);
#else
@ -536,23 +536,23 @@ static bool busvoodoo_hiz_test_pins(void)
}
if (busvoodoo_full) {
// test 12V output on RS/CAN pin 1
// test HV output on RS/CAN pin 1
double voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get reference voltage
uint16_t dac_set = BUSVOODOO_12V_SET(5.0)/voltage*4095; // DAC value corresponding to the voltage
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOODOO_12VCTL_CHANNEL); // set output so the voltage regulator is set to desired output voltage
dac_software_trigger(BUSVOODOO_12VCTL_CHANNEL); // transfer the value to the DAC
dac_enable(BUSVOODOO_12VCTL_CHANNEL); // enable DAC
gpio_clear(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // enable 12V voltage regulator
printf("%sRS/CAN pin 1\n", xv_to);
while (busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL)<0.2) { // wait until pin is connected
uint16_t dac_set = BUSVOODOO_HV_SET(5.0)/voltage*4095; // DAC value corresponding to the voltage
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOODOO_HVCTL_CHANNEL); // set output so the voltage regulator is set to desired output voltage
dac_software_trigger(BUSVOODOO_HVCTL_CHANNEL); // transfer the value to the DAC
dac_enable(BUSVOODOO_HVCTL_CHANNEL); // enable DAC
gpio_clear(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // enable HV voltage regulator
printf("%sRS/CAN pin 1\n", lv_to);
while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
}
gpio_set(GPIO(BUSVOODOO_12VEN_PORT), GPIO(BUSVOODOO_12VEN_PIN)); // disable 12V voltage regulator
dac_disable(BUSVOODOO_12VCTL_CHANNEL); // disable 12V control
gpio_set(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // disable HV voltage regulator
dac_disable(BUSVOODOO_HVCTL_CHANNEL); // disable HV control
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle (and debounce)
if (busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL)>0.2) {
printf(xv_high);
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
#if DEBUG
while (true);
#else