xdrv_92_vid6608: Advanced zero routine for analog gauges, library update (#24218)

* VID6608: Add option to skip auto-zero rouitine

* VID6608: Update library to version 1.0.3, add Zero control for Gauge
This commit is contained in:
Petr Golovachev 2025-12-13 11:33:52 +01:00 committed by GitHub
parent 206216cc34
commit 272fd431ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 31 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

View File

@ -13,7 +13,7 @@
"email": "petro@petro.ws",
"url": "https://petro.ws/"
},
"version": "1.0.2",
"version": "1.0.3",
"frameworks": "arduino",
"platforms": "*"
}

View File

@ -1,5 +1,5 @@
name=vid6608
version=1.0.2
version=1.0.3
author=Petr Golovachev
maintainer=Petr Golovachev <petro@petro.ws>
sentence=Arduino library for driving IC VID6608 and clones for Switec X25.168 / X27.168 miniature stepper motors

View File

@ -48,6 +48,7 @@ vid6608::vid6608(int stepPin, int dirPin, uint16_t maxSteps /*= VID6608_MAX_STEP
this->dirPinState = MOVE_NONE; // invalid state to force update on first step
this->currentPosition = 0;
this->targetPosition = 0;
this->targetPositionNext = 0;
this->setAccelTable(defaultAccelTable);
// Setup pins
pinMode(this->stepPin, OUTPUT);
@ -56,16 +57,19 @@ vid6608::vid6608(int stepPin, int dirPin, uint16_t maxSteps /*= VID6608_MAX_STEP
digitalWrite(this->dirPin, LOW);
}
void vid6608::zero(uint16_t delay /*= VID6608_DEFAULT_ZERO_SPEED*/) {
void vid6608::zero(uint16_t initialPos /*= VID6608_DEFAULT_MAX_STEPS/2*/, uint16_t delay /*= VID6608_DEFAULT_ZERO_SPEED*/) {
// We have to optimize the zeroing process to avoid bouncing on end-stops
// Drive makes 1/2 move forward and 1/2 backward to reduce bouncing
// This will reduce bouncing, if the last position was not a zero position
uint16_t halfSteps = this->maxSteps / 2;
// Move to halfSteps forward
for (uint16_t x = 0; x < halfSteps; x++) {
if (initialPos >= this->maxSteps) {
initialPos = this->maxSteps - 1;
}
uint16_t stepsForward = this->maxSteps - initialPos;
// Move forward to defined steps count
for (uint16_t x = 0; x < stepsForward; x++) {
step(MOVE_FORWARD, delay);
}
// Move to halfSteps back
// Move full round back to 0
for (uint16_t x = 0; x < this->maxSteps; x++) {
step(MOVE_BACKWARD, delay);
}

View File

@ -47,9 +47,10 @@ class vid6608 {
* Uses optimized method to reduce bouncing end-stops
* @warning this function is blocking, execution is delayed upon done
*
* @param initialPos initial position to assume zeroing, default is half of maxSteps. If you know the "old" gauge potision, you can provide it here to avoid end-stop bounce
* @param delay single step delay, controls sthe speed of motor, default is deined in VID6608_DEFAULT_ZERO_SPEED
*/
void zero(uint16_t delay = VID6608_DEFAULT_ZERO_SPEED);
void zero(uint16_t initialPos = VID6608_DEFAULT_MAX_STEPS/2, uint16_t delay = VID6608_DEFAULT_ZERO_SPEED);
/**
* @brief Shedules movement to defined absolute position

View File

@ -1132,6 +1132,7 @@
//#define USE_HRE // Add support for Badger HR-E Water Meter (+1k4 code)
//#define USE_A4988_STEPPER // Add support for A4988/DRV8825 stepper-motor-driver-circuit (+10k5 code)
//#define USE_VID6608 // Add support for VID6608 Automotive analog gauge driver (+0k7 code)
// #define VID6608_RESET_ON_INIT true // Reset VID6608 on init (default: true), change if you control this manually
//#define USE_PROMETHEUS // Add support for https://prometheus.io/ metrics exporting over HTTP /metrics endpoint

View File

@ -76,6 +76,16 @@
#define VID6608_RTOS
#endif
/**
* @brief Reset all drives on init?
*
* Disable if you dont want to perform reset/homing operation on driver init,
* usefull for cases, where you have advanced mode (i.e. use saved values from NVRAM to restore and manual reset).
*/
#ifndef VID6608_RESET_ON_INIT
#define VID6608_RESET_ON_INIT true
#endif
#include "vid6608.h"
/**
@ -178,7 +188,7 @@ void CmndGaugeCommand(int32_t command, uint32_t index, int32_t payload) {
ResponseAppend_P(PSTR("\"%d\":{"), (int32_t)(x+1));
switch (command) {
case GAUGE_ZERO:
driver->zero();
driver->zero(payload);
ResponseAppend_P(PSTR("\"cmd\":\"zero\",\"pos\":0"));
break;
case GAUGE_SET:
@ -287,8 +297,12 @@ void VID6608Init() {
vid6608Drives[x] = new vid6608(pinStep, pinDir);
// Perform homing operation
vid6608Drives[x]->zero();
AddLog(LOG_LEVEL_DEBUG, PSTR("VID: zero %d done"), x);
if (VID6608_RESET_ON_INIT) {
vid6608Drives[x]->zero();
AddLog(LOG_LEVEL_DEBUG, PSTR("VID: zero %d done"), x);
} else {
AddLog(LOG_LEVEL_DEBUG, PSTR("VID: zero %d skipped"), x);
}
vid6608Present = true;
} else {
vid6608Drives[x] = nullptr;