Fix diode check limits, allow for two-mode continuity limit

D1 has changed to a 5V1 zener and is loading the circuit a little bit. Adjusted voltage based on tested value on prototype. This value may differ on production units so expect this to possibly change.
This commit is contained in:
true 2023-10-31 19:50:30 -07:00
parent f2d4afce1c
commit 36a55a865b
4 changed files with 99 additions and 25 deletions

View File

@ -16,6 +16,9 @@ void probe_mode_switch(uint8_t mode);
void probe_measure();
void probe_set_thresh(uint8_t set);
uint8_t probe_get_thresh();
#endif /* _INC_PROBE_H */

View File

@ -34,6 +34,9 @@ int16_t userio_get_btn();
uint8_t userio_get_set1_limit();
int16_t userio_get_btn_held();
void userio_set_btn_override();
#endif /* _INC_USERIO_H */

View File

@ -3,6 +3,9 @@
*
* this file is responsible for figuring out the
* continuity and diode tests from the raw analog data.
*
* todo: confirm mathematically that continuity values
* match the measured values
*
* file creation: 20231016 0255
*/
@ -22,29 +25,52 @@
// diode measurements at 3V3
#define DIODE_OPEN 4000 // test unit measures ~4060
#define DIODE_STANDARD 2330 // fairchild 5V2 zener, forward biased
#define DIODE_OPEN 3860 // test unit measures ~4060 no D1, ~3960 with D1
#define DIODE_SCHOTTKY 1960 // vishay 40V 1A SB140
#define DIODE_STANDARD 2330 // fairchild 5V2 zener, forward biased
#define DIODE_LED_BLUE 3190
#define DIODE_LED_GRN 3040 // very dim
#define DIODE_LED_RED 3020
#define DIODE_SHORT 1900 // test unit measures ~1820
#define SHORT_THRESHOLD 2
#define CONT_SHORTED 858 // worst case measured value of short
#define CONT_47OHM 869 // measured value of 47ohm 1% resistor at room temp
#define CONT_100OHM 886 // measured value of 100ohm 1% resistor at room temp
#define CONT_EXTRA_COUNTS 8 // extra raw counts as a fudge factor, post-scaling
#define CONT_LATCH_THRESH 15 // extra raw counts for latching indicator, post-scaling
#define CONT_LATCH_TIMEOUT 4 // probe measurement passes to hold latched indicator
static uint16_t vref;
static uint16_t cont_thresh_set = 0;
static const uint16_t cont_thresh[] = {
CONT_100OHM, CONT_47OHM
};
static uint8_t latch = 0;
static uint8_t buzzer = 0;
void probe_set_thresh(uint8_t set)
{
cont_thresh_set = set;
}
uint8_t probe_get_thresh()
{
return cont_thresh_set;
}
static inline void probe_measure_cont()
{
uint16_t probe, v_ext;
uint32_t x;
uint32_t x, c;
uint8_t g, b;
probe = adc_avg[ADC_PROBE];
v_ext = adc_avg[ADC_VREF_EXT];
@ -54,29 +80,45 @@ static inline void probe_measure_cont()
buzzer ^= 1;
}
// if the button has been held, change the threshold
if (userio_get_btn_held() == 60) {
userio_set_btn_override();
cont_thresh_set ^= 1;
}
// this LED will not set anything,
// but zero it out anyway
led_setrgb(1, 0, 0, 0);
if (vref) {
x = probe << 12; // maximum possible level
x /= vref; // normalize to 4096max
// probe level
x = probe << 12; // maximum possible level
x /= vref; // normalize to 4096max
if (x > 4095) x = 4095;
if (x < 2405) { // roughly 100ohm or lower
latch = 4; // latch any continuity for a while
// threshold level
c = cont_thresh[cont_thresh_set] << 12;
c /= vref;
// are we measuring a lower value?
if (x < (c + CONT_EXTRA_COUNTS)) { // roughly 100ohm or lower
latch = CONT_LATCH_TIMEOUT; // latch any continuity for a while
}
if (latch) {
// indicate continuity
if (x >= 2420) latch--; // hysteresis
b = buzzer ? 100 : 0;
led_setrgb(0, 0, 250, ((buzzer) ? 100 : 0));
if (latch) {
// hysteresis
if (x >= c + CONT_LATCH_THRESH) latch--;
// indicate continuity
led_setrgb(0, 0, 250, b);
led_buzz(0);
if (buzzer) led_buzz(1);
} else {
// idle
led_setrgb(0, 120, 0, ((buzzer) ? 8 : 0));
g = cont_thresh_set ? 40 : 0;
led_setrgb(0, 120, g, b);
led_buzz(0);
}
}
@ -97,23 +139,23 @@ static inline void probe_measure_diode()
if (p < DIODE_SHORT) {
// show off on short
led_setrgb(1, 0, 0, 0);
}
} else
if (p >= DIODE_OPEN) {
// show red on open
led_setrgb(1, 120, 0, 0);
}
} else
if (p >= 1940 && p < 2650) {
// show green on regular or schottky diodes
led_setrgb(1, 0, 200, 0);
}
if (p >= 2650 && p < 3800) {
} else
if (p >= 2650 && p < 3700) {
// show blue on LEDs
led_setrgb(1, 0, 0, 500);
} else
if (p >= 3701) {
// show red+blue if between open and LED
led_setrgb(1, 120, 0, 120);
}
// if we haven't set a value, flash red to indicate error state
}
void probe_measure()

View File

@ -41,6 +41,11 @@
#define MODE_ANALOG_MIN 20
#define BTN_OPEN 0
#define BTN_PUSHED 1
#define BTN_OVERRIDE 2
#ifdef TESTO_REV1
#define SET1_MAX 2199 // 3V net feeding into 1V24 via body diode above this
#else
@ -76,9 +81,12 @@ void userio_parse()
m = adc_avg[ADC_SET_MODE];
if (m < MODE_ANALOG_MIN) {
// button is pushed
btn = 1;
if (btn == BTN_OPEN) btn = 1;
if (btn_held != 0xffff) btn_held++;
} else if (btn == 1) {
} else if (btn) {
// release held count if overridden
if (btn == BTN_OVERRIDE) btn_held = 0;
// button is released
btn = 0;
}
@ -165,8 +173,8 @@ int16_t userio_get_btn()
{
int16_t ret;
if (btn) return -1;
if (!btn) {
if (btn == BTN_PUSHED) return -1;
if (btn == BTN_OPEN) {
if (btn_held) {
ret = btn_held;
btn_held = 0;
@ -177,6 +185,24 @@ int16_t userio_get_btn()
return 0;
}
/*
* returns the button state.
* 0 = not held
* >0 = held for X ticks
*/
int16_t userio_get_btn_held()
{
return btn_held;
}
/*
* overrides and disables the next button release event.
*/
void userio_set_btn_override()
{
btn = BTN_OVERRIDE;
}
/*
* returns true if the right knob is beyond maximum range.
* always returns false on REV2 or later boards.