application: add pull detection to type
This commit is contained in:
parent
e5dbb79b0e
commit
f10da7082b
|
@ -238,9 +238,9 @@ static void command_types(void* argument)
|
||||||
{
|
{
|
||||||
(void)argument; // we won't use the argument
|
(void)argument; // we won't use the argument
|
||||||
float* voltages;
|
float* voltages;
|
||||||
print_voltage_target(); // print target voltage (also sets measurement conditions)
|
print_target(); // print target voltage (also sets measurement conditions)
|
||||||
puts("signal voltage pulled pulled\n");
|
puts("signal voltage pulled pull-up pulled pull-down signal\n");
|
||||||
puts(" pin raw down up \n");
|
puts(" name raw (V) down (V) (kOhm) up (V) (kOhm) type \n");
|
||||||
|
|
||||||
// just to be sure, reset measurement conditions
|
// just to be sure, reset measurement conditions
|
||||||
gpio_set(GPIO_PORT(SIGNAL_PD_PIN), GPIO_PIN(SIGNAL_PD_PIN)); // ensure pull-down is not active
|
gpio_set(GPIO_PORT(SIGNAL_PD_PIN), GPIO_PIN(SIGNAL_PD_PIN)); // ensure pull-down is not active
|
||||||
|
@ -252,17 +252,59 @@ static void command_types(void* argument)
|
||||||
puts(" ");
|
puts(" ");
|
||||||
mux_select(i); // select the channel
|
mux_select(i); // select the channel
|
||||||
voltages = measure_voltages(); // measure raw voltages
|
voltages = measure_voltages(); // measure raw voltages
|
||||||
print_voltage(voltages[2], 2);
|
print_fpu(voltages[2], 2);
|
||||||
|
const float raw = voltages[2]; // remember un-pulled voltage
|
||||||
puts(" ");
|
puts(" ");
|
||||||
gpio_clear(GPIO_PORT(SIGNAL_PD_PIN), GPIO_PIN(SIGNAL_PD_PIN)); // pull-down signal
|
|
||||||
|
gpio_clear(GPIO_PORT(SIGNAL_PD_PIN), GPIO_PIN(SIGNAL_PD_PIN)); // pull down signal
|
||||||
voltages = measure_voltages(); // measure pulled down voltages
|
voltages = measure_voltages(); // measure pulled down voltages
|
||||||
print_voltage(voltages[2], 2);
|
|
||||||
gpio_set(GPIO_PORT(SIGNAL_PD_PIN), GPIO_PIN(SIGNAL_PD_PIN)); // remove pull-down
|
gpio_set(GPIO_PORT(SIGNAL_PD_PIN), GPIO_PIN(SIGNAL_PD_PIN)); // remove pull-down
|
||||||
puts(" ");
|
voltages[2] *= 2.0; // pulling creates a voltage divider (to ground)
|
||||||
gpio_clear(GPIO_PORT(SIGNAL_PU_PIN), GPIO_PIN(SIGNAL_PU_PIN)); // pull-up signal
|
const bool low = (voltages[2] < 0.5); // remember if we were able to pull it down
|
||||||
|
const float pullup = (2000.0 * (raw - voltages[2]) / voltages[2]) / 1000.0; // estimate external pull-up
|
||||||
|
print_fpu(voltages[2], 2);
|
||||||
|
puts(" ");
|
||||||
|
if (pullup > 100.0) {
|
||||||
|
puts(">100");
|
||||||
|
} else if (pullup < 1.0) {
|
||||||
|
puts(" <1 ");
|
||||||
|
} else {
|
||||||
|
printf(" %02u ", (uint32_t)round(pullup));
|
||||||
|
}
|
||||||
|
puts(" ");
|
||||||
|
|
||||||
|
gpio_clear(GPIO_PORT(SIGNAL_PU_PIN), GPIO_PIN(SIGNAL_PU_PIN)); // pull up signal
|
||||||
voltages = measure_voltages(); // measure pulled up voltages
|
voltages = measure_voltages(); // measure pulled up voltages
|
||||||
print_voltage(voltages[2], 2);
|
|
||||||
gpio_set(GPIO_PORT(SIGNAL_PU_PIN), GPIO_PIN(SIGNAL_PU_PIN)); // remove pull-up
|
gpio_set(GPIO_PORT(SIGNAL_PU_PIN), GPIO_PIN(SIGNAL_PU_PIN)); // remove pull-up
|
||||||
|
voltages[2] = voltages[2] * 2.0 - voltages[1]; // pulling creates a voltage divider (to target)
|
||||||
|
const bool high = (voltages[2] > 3.2 || voltages[2] > voltages[1] * 0.5); // remember if we were able to pull it up
|
||||||
|
const float pulldown = (2000.0 * voltages[2] / (voltages[1] - voltages[2])) / 1000.0; // estimate external pull-down
|
||||||
|
print_fpu(voltages[2], 2);
|
||||||
|
puts(" ");
|
||||||
|
if (pulldown > 100.0) {
|
||||||
|
puts(">100");
|
||||||
|
} else if (pulldown < 1.0) {
|
||||||
|
puts(" <1 ");
|
||||||
|
} else {
|
||||||
|
printf(" %02u ", (uint32_t)round(pulldown));
|
||||||
|
}
|
||||||
|
puts(" ");
|
||||||
|
|
||||||
|
if (low && high) {
|
||||||
|
if (pullup > 1.0 && pullup < 100.0 && (pulldown < 1.0 || pulldown > 100.0)) {
|
||||||
|
puts("pulled-up");
|
||||||
|
} else if (pulldown > 1.0 && pulldown < 100.0 && (pullup < 1.0 || pullup > 100.0)) {
|
||||||
|
puts("pulled-down");
|
||||||
|
} else {
|
||||||
|
puts("floating");
|
||||||
|
}
|
||||||
|
} else if (low) {
|
||||||
|
puts("low");
|
||||||
|
} else if (high) {
|
||||||
|
puts("high");
|
||||||
|
} else {
|
||||||
|
puts("unknown");
|
||||||
|
}
|
||||||
putc('\n');
|
putc('\n');
|
||||||
}
|
}
|
||||||
mux_select(-1); // disable multiplexer
|
mux_select(-1); // disable multiplexer
|
||||||
|
|
Loading…
Reference in New Issue