I have a stepper motor driving a air pressure reg. with a pressure sensor as feedback in a closed loop , right now I am using a pot to 3.3vdc for the set point , it works good BUT the motor jitters after it sleeps for a while ( I use a deadband to disable the motor after it hits its target ) after waking up it jitters to position , after 3-5 changes in setpoint it clears up ??
Any idea what is causing this to happen ?? ( I have tried not serialprinting anything and that makes no
difference )
#include <Arduino.h>
#include "BasicStepperDriver.h"
#include "A4988.h"
#include <MovingAverage.h>
MovingAverage average(0.1f);
#define MOTOR_STEPS 200
#define RPM 80
#define MICROSTEPS 1
#define DIR 8
#define STEP 9
#define ENABLE 10
//#define MOTOR_ACCEL 200
//#define MOTOR_DECEL 1000
A4988 stepper(MOTOR_STEPS, DIR, STEP, ENABLE);
const int ANALOG_PIN0 = A2; // sensor
const int ANALOG_PIN1 = A3;//pot
int sensorValue0 = analogRead(A2); // sensor
int sensorValue1 = analogRead(A3); // pot
int val0 = 0;
int val1 = 0;
float deadBand;
double error;
void setup() {
Serial.begin(115200);
average.reset( analogRead(A2) );
stepper.begin(RPM, MICROSTEPS);
// stepper.setSpeedProfile(stepper.LINEAR_SPEED, MOTOR_ACCEL, MOTOR_DECEL);
deadBand = 25.0; //stop moving when error < deadBand
}
void measurePressure() {
int raReading = analogRead(A2);
float psi0 = ((30 - 0) / (902.0 - 127.3)) * (raReading - 20);
Serial.println(psi0);
Serial.println("psi");
}
void loop() {
//analogReadResolution(12);// set to 12bit ACD
( average.update( analogRead(0) ) );
val0 = analogRead(A2); // read the input pin
Serial.println(val0); // debug value
//Serial.println("sensor");
val1 = analogRead(A3); // read the input pin
Serial.println(val1); // debug value
//Serial.println("pot");
error = val0 - val1;
Serial.println(error);
if (abs(error) < deadBand ) error = 0;
measurePressure();
delay (1);
stepper.enable();
stepper.move(-error);
stepper.disable();
delay(1);
}