MarkT:
Well you clearly have a servomotor, not a stepper motor!Anyway the issue is that its using the same step/direction interface as a stepper motor would,
which needs a high rate of pulses for a high speed. You are calling analogRead() which takes a
long time on ATmega microcontrollers - 110µs or so, limiting the pulse rate.Your management of time is poor too - using delayMicroseconds() instead of micros(), so that
the code execution time eats into your performance.Perhaps try replacing
void loop() {
customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
// Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
digitalWrite(stepPin, HIGH);
delayMicroseconds(customDelayMapped);
digitalWrite(stepPin, LOW);
delayMicroseconds(customDelayMapped);
}
byvoid loop() {
static unsigned long last_read= 0 ;
if (millis() - last_read >= 20) // only read pot occasionally
{
last_read += 20 ;
customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
}
// Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
static unsigned long last_step = 0 ;
if (micros() - last_step >= customDelayMapped)
{
last_step += customDelayMapped ; // schedule next pulse without being affected by code execution time
digitalWrite(stepPin, HIGH);
delayMicroseconds(5);
digitalWrite(stepPin, LOW);
}
}
Thanks MarkT for youryour suggestion , it works fine , low revs high revs , ....i am mechanical engineer , i must stydy deeply the electronics, thanks for your valuable help, thank all the guys offered their help
http://www.xinhuanet.com/culture/2018-01/08/c_1122227025.htm?from=timelin
Here some youtube videos about my work on robotics animatronics