busvoodoo: add method to control embedded pull-up resistors
This commit is contained in:
parent
f834f3bd63
commit
4a8bf5d2a1
|
@ -209,18 +209,20 @@ float busvoodoo_vreg_set(uint8_t channel, float voltage)
|
|||
gpio_clear(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // disable xV voltage regulator
|
||||
dac_disable(BUSVOODOO_XVCTL_CHANNEL); // disable xV control
|
||||
} else { // enable voltage regulator
|
||||
if (voltage>4.5) { // enforce upper voltage limit (5.0V rail minus LDO and diodes)
|
||||
voltage = 4.5;
|
||||
}
|
||||
volt = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get reference voltage
|
||||
if (isnan(voltage)) {
|
||||
return NAN;
|
||||
if (voltage>4.7) { // use the 5V directly
|
||||
gpio_clear(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // put 5V on xV 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 pull-up
|
||||
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_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
|
||||
}
|
||||
sleep_ms(5); // let voltage settle
|
||||
volt = busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL); // get xV voltage to return
|
||||
|
@ -250,3 +252,13 @@ float busvoodoo_vreg_set(uint8_t channel, float voltage)
|
|||
|
||||
return volt; // return measured voltage
|
||||
}
|
||||
|
||||
float busvoodoo_embedded_pullup(bool on)
|
||||
{
|
||||
if (on) { // enable embedded pull-ups
|
||||
gpio_clear(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO(BUSVOODOO_OEPULLUP_PIN)); // switch on embedded pull-ups
|
||||
} 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
|
||||
}
|
||||
|
|
|
@ -113,8 +113,16 @@ bool busvoodoo_vout_switch(bool on);
|
|||
*/
|
||||
float busvoodoo_vreg_get(uint8_t channel);
|
||||
/** set voltage on adjustable voltage regulator
|
||||
* @note only vV and 12V are adjustable voltage regulators
|
||||
* @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
|
||||
* @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)
|
||||
* @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)
|
||||
*/
|
||||
float busvoodoo_embedded_pullup(bool on);
|
||||
|
|
|
@ -165,7 +165,6 @@ bool busvoodoo_hiz_test_self(void)
|
|||
|
||||
// check if we can control xV
|
||||
voltage = busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, BUSVOODOO_XV_TEST); // get xV voltage
|
||||
// check if it matched desired voltage
|
||||
if (voltage<BUSVOODOO_XV_TEST-0.2) {
|
||||
printf("xV voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_XV_TEST);
|
||||
#if DEBUG
|
||||
|
@ -327,10 +326,8 @@ 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
|
||||
}
|
||||
gpio_clear(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // enable 5V pull-up
|
||||
gpio_clear(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO(BUSVOODOO_OEPULLUP_PIN)); // switch on embedded pull-ups
|
||||
sleep_ms(1); // wait a bit for voltage to settle
|
||||
voltage = busvoodoo_vreg_get(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
|
||||
busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, 5.0); // set xV 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);
|
||||
#if DEBUG
|
||||
|
@ -356,18 +353,16 @@ bool busvoodoo_hiz_test_self(void)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
gpio_set(GPIO(BUSVOODOO_5VPULLUP_PORT), GPIO(BUSVOODOO_5VPULLUP_PIN)); // disable 5V pull-up
|
||||
gpio_set(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO(BUSVOODOO_OEPULLUP_PIN)); // switch off embedded pull-up
|
||||
busvoodoo_embedded_pullup(false); // disable pull-ups
|
||||
voltage = busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, 0); // disable xV voltage regulator
|
||||
|
||||
// test xV 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
|
||||
}
|
||||
gpio_set(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // enable xV voltage regulator
|
||||
gpio_clear(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO(BUSVOODOO_OEPULLUP_PIN)); // switch in embedded pull-up
|
||||
sleep_ms(5); // let the voltage regulator start and voltage settle
|
||||
voltage = busvoodoo_vreg_get(BUSVOODOO_XV_CHANNEL); // get xV voltage (without being driven it should be around 3.2V)
|
||||
busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, 3.3); // set xV 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 DEBUG
|
||||
|
@ -393,8 +388,8 @@ bool busvoodoo_hiz_test_self(void)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
gpio_set(GPIO(BUSVOODOO_OEPULLUP_PORT), GPIO(BUSVOODOO_OEPULLUP_PIN)); // switch off embedded pull-up
|
||||
gpio_clear(GPIO(BUSVOODOO_XVEN_PORT), GPIO(BUSVOODOO_XVEN_PIN)); // disable xV voltage regulator
|
||||
busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, 0); // disable xV voltage regulator
|
||||
busvoodoo_embedded_pullup(false); // disable pull-ups
|
||||
|
||||
to_return = true; // all tests are successful
|
||||
#if DEBUG
|
||||
|
|
Loading…
Reference in New Issue