Debounce direction as well as step
This commit is contained in:
parent
4463e2b945
commit
1af9eacefb
|
|
@ -156,6 +156,7 @@ int main (void)
|
||||||
uint16_t spinner = 0;
|
uint16_t spinner = 0;
|
||||||
int r;
|
int r;
|
||||||
int32_t rv;
|
int32_t rv;
|
||||||
|
uint8_t input_lastreading;
|
||||||
|
|
||||||
// setup inputs
|
// setup inputs
|
||||||
DDR_STEP &= ~MASK(PIN_STEP);
|
DDR_STEP &= ~MASK(PIN_STEP);
|
||||||
|
|
@ -210,21 +211,33 @@ int main (void)
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
// check logic inputs
|
// check logic inputs
|
||||||
if ((READ_STEP & MASK(PIN_STEP)) == 0) {
|
if (1) {
|
||||||
if (stepdebounce >= 128) {
|
uint8_t input_thisreading = (READ_STEP & (MASK(PIN_STEP) | MASK(PIN_DIR)));
|
||||||
if (stepdebounce == 128) {
|
// if same as last time
|
||||||
if (READ_DIR & MASK(PIN_DIR))
|
if (input_thisreading == input_lastreading) {
|
||||||
npos++;
|
// if we're near debounce threshold
|
||||||
else
|
if (stepdebounce >= 32) {
|
||||||
npos--;
|
// if we're exactly on the threshold
|
||||||
stepdebounce++;
|
if (stepdebounce == 32) {
|
||||||
|
// adjust target position
|
||||||
|
if (input_thisreading & MASK(PIN_DIR))
|
||||||
|
npos++;
|
||||||
|
else
|
||||||
|
npos--;
|
||||||
|
// go over threshold so inputs must change before next move
|
||||||
|
stepdebounce++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// approach threshold
|
||||||
|
else {
|
||||||
|
stepdebounce++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
// if input changed, reset debouncer
|
||||||
stepdebounce++;
|
else {
|
||||||
|
stepdebounce = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
stepdebounce = 0;
|
|
||||||
|
|
||||||
// check serial input
|
// check serial input
|
||||||
if (serial_rxchars()) {
|
if (serial_rxchars()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue