I know I shouldn't start a second thread for the same question, so I hope it's ok that I'm just asking a question here that we can't get resolved in the other thread. - If that's not ok, I ask a moderator to delete the thread here.
Why does the engine behave the way it behaves? - Why does the motor twitch when the stick input goes to the left?
Post
I would be grateful for an explanation.
Matt_Hias
Schematics and code please.
That is all controlled by the program you wrote. Now you need to debug your program, step by step. Best to begin with the "stick".
kolaha
August 15, 2023, 3:31pm
5
what is that strange circuit?
does your driver need of discrete pulse wires? why you does not mentioned it?
yes it is, separated wires.
it can be reason why one way it run smooth, other way motor jitters
Do you really have a +12V and -12V line but no GND anywhere but USB?
You code: are you sure you read the PWM signal without jitter?
That looks okey but the anonymous 5/12 converter as well as driver are unknown devices.
Are You still updating the post? It looks like ghosts are flying in.
The 5/12 Konverter is a Mauch Power Cube V3
Link
The powersource ist a 6S lipo battery. The Voltage should be high enough for mauch as well as the motor.
The 12V are powering the herelink-airunit.
I do not understand what U are meaning. With that ?
With the Jitter: I am not sure how tho check this, Serial slows it to much down.
If i check it with serial, not Jitter is visible but motor runs only a fraction of his speed.
Maybe, i have to close the browser in my phone?
Please add new information in new replies. Updating old replies makes the conversation disturbed for new readers.
loop(): du blockierst Interrupts und erlaubst sie dann wieder --> deine Messung der Pulsbreite ist zufällig.
kolaha
August 16, 2023, 3:48am
14
I think it's easy to fix.
kolaha
August 16, 2023, 9:29am
16
no, the issue is something other. i thought i just add a max function to be sure that length of high impulse not exceed the length of period, but now i remember the code already contain such check
if (!(pulse_Lenght > 1000 && pulse_Lenght < 2000))pulse_Lenght = 0;
...
if (pulse_Lenght)temp = pulse_Lenght - Mitte;
kolaha
August 16, 2023, 9:45am
17
ok, just to be sure:
#define PWM_Pin 2
#define DIR 4
#define STEP 5
volatile uint32_t lastPulseTime = 0;
volatile uint32_t pulse_Lenght = 0;
volatile uint32_t PulseTime = 0;
void setup() {
// Serial.begin(250000);
attachInterrupt(digitalPinToInterrupt(PWM_Pin), Pulse, CHANGE);
pinMode(DIR , OUTPUT);
pinMode(STEP , OUTPUT);
}
void Pulse() {
if (digitalRead(PWM_Pin))lastPulseTime = micros();
else {
PulseTime = micros();
pulse_Lenght = PulseTime - lastPulseTime;
if (!(pulse_Lenght > 1000 && pulse_Lenght < 2000))pulse_Lenght = 0;
}
}
void loop() {
const int Mitte = 1500;
static int channelValue = 0;
static unsigned long previousMotorTime = 0;
static unsigned long MotorInterval = 0xFFFFFFFF;
static long temp = Mitte;
//Serial.print("channelValue");
//Serial.println(channelValue);
//Serial.print("MotorInterval ");
noInterrupts();
if (pulse_Lenght)temp = (temp + pulse_Lenght - Mitte) / 2;
delay(2);
interrupts();
// Serial.print(" ");
// Serial.print(pulse_Lenght);
// Serial.print(" ");
// Serial.print(temp);
digitalWrite(DIR, temp >= 0);
channelValue = constrain(abs(int(temp)), 0, 400);
// Serial.print(" ");
// Serial.print(channelValue);
if (channelValue > 5)MotorInterval = (405 - channelValue) * 5;
else MotorInterval = 0x0FFFFFFF;
// Serial.print(" ");
// Serial.println(MotorInterval);
if (micros() - previousMotorTime >= MotorInterval) {
digitalWrite(STEP, !digitalRead(STEP));
previousMotorTime += MotorInterval;
}
// delay(10);
}
Sorry, but there is no change at the Output.
I checked it with this code,
Post#77
there is change at the output.
If i out-comment the
kolaha:
delay(2);
the Code works. It runs smother than the code from Post#77 but has still the same issue.
Can U please point it out how U would solve the issue? Danke!