Add stall-based pingpong return mode and calibration improvements
- Add MIN_PWM_PERCENT (20%) to ensure motor starts reliably - Add CURRENT_CALIBRATION factor (0.33) for accurate current readings - Add stall-based return option for pingpong mode (returns on stall instead of time) - Update stall detection: 7A threshold, 1000ms confirm time - Add DISABLE_STALL_DETECT config option - Keep last speed setting when motor stops (UI improvement) - Update webserver UI with 'Return on stall only' checkbox
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#define PWM_RESOLUTION 8 // 8-bit resolution (0-255)
|
||||
#define PWM_CHANNEL_R 0 // LEDC channel for RPWM
|
||||
#define PWM_CHANNEL_L 1 // LEDC channel for LPWM
|
||||
#define MIN_PWM_PERCENT 20 // Minimum PWM when motor is running (%)
|
||||
|
||||
// Current Sense Configuration
|
||||
// BTS7960 current sense ratio: 8500:1 (kilo-amps)
|
||||
@@ -33,8 +34,10 @@
|
||||
#define SENSE_RESISTOR 1000.0f // 1kΩ sense resistor (ohms)
|
||||
#define ADC_MAX 4095.0f // 12-bit ADC max value
|
||||
#define ADC_VREF 3.3f // ADC reference voltage
|
||||
#define STALL_CURRENT_THRESHOLD 4.0f // Current (amps) that indicates stall
|
||||
#define STALL_DETECT_TIME_MS 2500 // Time to confirm stall (ms) - accounts for startup inrush
|
||||
#define CURRENT_CALIBRATION 0.33f // Calibration factor (measured current / reported current)
|
||||
#define STALL_CURRENT_THRESHOLD 7.0f // Current (amps) that indicates stall
|
||||
#define STALL_DETECT_TIME_MS 1000 // Time to confirm stall (ms) - accounts for startup inrush
|
||||
#define DISABLE_STALL_DETECT false // Set to true to disable stall detection
|
||||
|
||||
// Web Server
|
||||
#define HTTP_PORT 80
|
||||
|
||||
@@ -23,13 +23,14 @@ public:
|
||||
void setStallCallback(void (*callback)(float current));
|
||||
|
||||
// Pingpong mode
|
||||
void startPingpong(int speed, int timeMs, int speedRandomPercent, int timeRandomPercent);
|
||||
void startPingpong(int speed, int timeMs, int speedRandomPercent, int timeRandomPercent, bool useStallReturn);
|
||||
void stopPingpong();
|
||||
bool isPingpongActive();
|
||||
int getPingpongSpeed();
|
||||
int getPingpongTime();
|
||||
int getPingpongSpeedRandom();
|
||||
int getPingpongTimeRandom();
|
||||
bool getPingpongStallReturn();
|
||||
|
||||
private:
|
||||
int _speed = 0;
|
||||
@@ -50,6 +51,7 @@ private:
|
||||
int _pingpongCurrentTime = 2000;
|
||||
unsigned long _pingpongLastSwitch = 0;
|
||||
int _pingpongDirection = 1;
|
||||
bool _pingpongUseStallReturn = false; // Return only after stall detection
|
||||
|
||||
void applyMotorState();
|
||||
float readCurrentSense(int pin);
|
||||
|
||||
Reference in New Issue
Block a user