busvoodoo: add method to control power output
This commit is contained in:
parent
4f0a09f717
commit
f834f3bd63
|
@ -121,19 +121,42 @@ void busvoodoo_safe_state(void)
|
|||
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, busvoodoo_io_pins[pin]); // set pin back to input (floating)
|
||||
}
|
||||
|
||||
// disable all RS-232 and some RS-485 signals (put back to input floating)
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_TX_PIN));
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RX_PIN));
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RTS_PIN));
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_CTS_PIN));
|
||||
gpio_set(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO(BUSVOODOO_RS232_EN_PIN)); // set high to disable receiver
|
||||
gpio_clear(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO(BUSVOODOO_RS232_SHDN_PIN)); // set low to disable transmitter
|
||||
if (busvoodoo_full) {
|
||||
// disable all RS-232 and some RS-485 signals (put back to input floating)
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_TX_PIN));
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RX_PIN));
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RTS_PIN));
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_CTS_PIN));
|
||||
gpio_set(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO(BUSVOODOO_RS232_EN_PIN)); // set high to disable receiver
|
||||
gpio_clear(GPIO(BUSVOODOO_RS232_SHDN_PORT), GPIO(BUSVOODOO_RS232_SHDN_PIN)); // set low to disable transmitter
|
||||
|
||||
// disable all CAN and some RS-458 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));
|
||||
gpio_set_mode(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_RX_PIN));
|
||||
gpio_set_mode(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_EN_PIN));
|
||||
gpio_set_mode(GPIO(BUSVOODOO_CAN_S_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_S_PIN));
|
||||
// disable all CAN and some RS-458 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));
|
||||
gpio_set_mode(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_RX_PIN));
|
||||
gpio_set_mode(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_EN_PIN));
|
||||
gpio_set_mode(GPIO(BUSVOODOO_CAN_S_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_S_PIN));
|
||||
}
|
||||
}
|
||||
|
||||
bool busvoodoo_vout_switch(bool on)
|
||||
{
|
||||
if (on) { // we need to switch on Vout
|
||||
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
|
||||
} else {
|
||||
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
|
||||
}
|
||||
|
||||
bool to_return = true;
|
||||
sleep_ms(1); // wait a bit for voltage to settle
|
||||
float voltage = busvoodoo_vreg_get(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
|
||||
if (voltage<4.0 || voltage>5.5) {
|
||||
to_return = false; // voltage output is not ok
|
||||
}
|
||||
voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get 3.3V power rail voltage
|
||||
if (voltage<3.0 || voltage>3.6) {
|
||||
to_return = true; // voltage output is not ok
|
||||
}
|
||||
return to_return;
|
||||
}
|
||||
|
||||
float busvoodoo_vreg_get(uint8_t channel)
|
||||
|
|
|
@ -48,14 +48,10 @@
|
|||
#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_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_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_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_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) */
|
||||
/** @} */
|
||||
|
@ -106,6 +102,11 @@ extern bool busvoodoo_full;
|
|||
void busvoodoo_setup(void);
|
||||
/** set safe state by disabling all outputs */
|
||||
void busvoodoo_safe_state(void);
|
||||
/** switch 3V3 and 5V power outputs on I/O connector
|
||||
* @param[in] on switch on (true) or off (false) power output
|
||||
* @return if switching succeeded. else it means there is a probably a short on one of the outputs
|
||||
*/
|
||||
bool busvoodoo_vout_switch(bool on);
|
||||
/** read voltage from power rail
|
||||
* @param[in] channel which power rail to read voltage from @ref busvoodoo_adc
|
||||
* @return voltage, or NaN if channel is invalid (or error happened)
|
||||
|
|
|
@ -34,6 +34,11 @@
|
|||
#include "busvoodoo_global.h" // BusVoodoo definitions
|
||||
#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 */
|
||||
|
||||
bool busvoodoo_hiz_test_self(void)
|
||||
{
|
||||
bool to_return = false; // success of the self-test
|
||||
|
@ -93,8 +98,7 @@ bool busvoodoo_hiz_test_self(void)
|
|||
}
|
||||
|
||||
// test 5V and 3.3V outputs
|
||||
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
|
||||
sleep_ms(1); // wait a bit for voltage to settle
|
||||
busvoodoo_vout_switch(true); // enable Vout
|
||||
voltage = busvoodoo_vreg_get(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
|
||||
if (voltage<4.0) {
|
||||
printf("5V power rail voltage is too low when 5V output is enabled: %.2fV\n", voltage);
|
||||
|
@ -127,7 +131,7 @@ bool busvoodoo_hiz_test_self(void)
|
|||
goto error;
|
||||
#endif
|
||||
}
|
||||
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
|
||||
busvoodoo_vout_switch(false); // disable Vout
|
||||
|
||||
// check xV voltage regulator
|
||||
voltage = busvoodoo_vreg_set(BUSVOODOO_XV_CHANNEL, 0); // disable xV voltage regulator
|
||||
|
|
Loading…
Reference in New Issue