3 added 11 characters in body

Arduino ADC is 10 bit which is 5000/1024 = 4.8mV. Which means it is sensitive for each 4.5mV. In my case power ripple was causing sometimes around 15mV difference.

Arduino ADC is 10 bit which is 5000/1024 = 4.8mV. Which means it is sensitive for each 4.5mV. In my case power ripple was causing sometimes around 15mV.

Arduino ADC is 10 bit which is 5000/1024 = 4.8mV. Which means it is sensitive for each 4.5mV. In my case power ripple was causing sometimes around 15mV difference.

2 added 541 characters in body

Edit:

The problem was the Arduino being supplied by laptop's USB output. I checked the potentiometer and 3.3V pins with AC coupling and here is what I got:

Arduino ADC is 10 bit which is 5000/1024 = 4.8mV. Which means it is sensitive for each 4.5mV. In my case power ripple was causing sometimes around 15mV.

I tried with a non-USB 9V power supply from Arduino's power barrel jack, the issue solved. Thanks to Anklon for his intuition.

Edit:

The problem was the Arduino being supplied by laptop's USB output. I checked the potentiometer and 3.3V pins with AC coupling and here is what I got:

Arduino ADC is 10 bit which is 5000/1024 = 4.8mV. Which means it is sensitive for each 4.5mV. In my case power ripple was causing sometimes around 15mV.

I tried with a non-USB 9V power supply from Arduino's power barrel jack, the issue solved. Thanks to Anklon for his intuition.

1

# Arduino - Pulses get unstable when updating PWM duty-cycle

I'm trying to obtain stable pulse trains when adjusting the duty cycles wth an Arduino Uno board. In my actual project I need to use 4 adjustable PWM output pins at a fixed 25kHz frequency to control four pwm controlled DC motors.

But to point the issue easier I want to ask my question with an easy setup and with an easy short code.

Lets say the goal is to vary PWM duty-cycle of pulses with a fixed frequency. A potentiometer can be used to vary the input voltage at A3 pin which than is scaled to duty cycle of PWM pin 9. The simple setup is illustrated below:

To explain the issue in a clear way, I would like to show you couple of simple codes and short video records from the scope screen.

Here is the code which adjusts the duty-cycles from potentimeter readings at A3:

void setup()
{
pinMode(9, OUTPUT);
}

void loop()
{
float volt =(5.0 * val) / 1023; //convert the value to voltage
val = 255 * (volt / 5); //scale the voltage for pwm duty-cycle
analogWrite(9, val);

}


And with this code uploaded to the uC, below is the video record for the output:

As you see on the scope, the pulses are flickering. They are not stable. By the way the issue is not related to the poti output since I also tried fixed 3.3V pin out with an int cast. It seems to me it happens each time analogWrite updates.

And here is another code where analogRead and analogWrite functions are still continuously active in the loop. The only difference this time the analogWrite has a fixed value here as 24:

void setup()
{
pinMode(9, OUTPUT);
}

void loop()
{
float volt =(5.0 * val) / 1023; //convert the value to voltage
val = 255 * (volt / 5); //scale the voltage for pwm duty-cycle
analogWrite(9, 24);

}


And now with this one uploaded, below is the video record for the new output: