PWM output Values fluctuating

I am taking input from a receiver's IBus protocol, getting the inputs perfectly, but while printing it to control servos, its fluctuating weirdly

#include <IBusBM.h>
#include <Servo.h>
IBusBM IBus;
# define C1 2 // to read the servo output from pin 6
int CH1 = 0;
int RCVAlue;
Servo esc1;
void setup() 
{
  Serial.begin(115200);
  IBus.begin(Serial);
  esc1.attach(6, 1000, 2000);
}
void loop() 
{
  RCVAlue = CH1;
  esc1.write(1500);
  CH1 = IBus.readChannel(0);
  if(RCVAlue>1600 || RCVAlue<1400)
  {
    esc1.write(RCVAlue);
  }
  int RCV = pulseIn(C1, HIGH);
  Serial.print(RCV);
  Serial.print("; ");
  Serial.println(CH1);
  delay(1000);
}

PWM values are fluctuating

What is? Post examples.

1 Like

Welcome to the forum

What exactly is fluctuating ?

 esc1.write(1500);

Why are you doing this ?

2 Likes

PWM values are,
Screenshot 2024-04-14 090031
first image is when i haven't plugged my RC, you can see the initial value is 968, which is the servo output. its meant to be 1500 but i am getting 968.
Screenshot 2024-04-14 090108
and when I plug my RC, you can see the variation, input pwm value is in the right, and output pwm is in the right.

I am using a bidirectional ESC to control my BLDC, I have to set the PWM in the mid value so it doesn't start

Do you really have to do that each time through loop() ? No wonder

Why not do it just once in setup() ?

Maybe, but still the the fluctuations won’t stop, what’s happening between the input and output, it’s simply reading and writing, but still getting a variation up to 300

i am getting my PWM output varying a lot, like it jumps from 1500 to 1200 even when there is no change in the input, its just from the output side, I measured the input and output at the same time. is my arduino nano broken or my code has problems

Suppose that the value of RCVAlue is 1200

At the start of loop() you do

esc1.write(1500);

then almost immediately you do

    esc1.write(1200);

One second later you repeat the same outputs so is it any wonder that

see if we remove

esc1.write(1500);

and i am giving the input 1200, after resting the value between 1600 and 1400, it will still be in 1200 because of the IF statement thats why we require to state the resting PWM.
I dont think you are getting the idea of what the problem i am facing, it would be great if you refer to the output screen shots above

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.