Analog to PWM question

Is it possible to have the PWM level increase in steps, based on a voltage range within 0-10V.
My 0-10V source increases in steps of 0.1V. Arduino is reading somewhere between the lines, thus, causing almost negligible flickering of my lights which are controlled by the PWM output. I already have a low pass RC filter, which is a 30K resistor and 4.7uf cap...nevertheless it still has a slight flicker.

For example -
0-0.1V = 1-2 (PWM - 1-2 out of the total 255)
0.1-0.2V = 3-4
ect.

This is what I am using now:

int val = 0;         // variable to store the read value
    
void setup()  {
  // declare pin 9 to be an output:
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop()  {
 int val = analogRead(0);
val = map(val, 0, 1023, 0, 255);
analogWrite(9, val);  

val = analogRead(1);
val = map(val, 0, 1023, 0, 255);
analogWrite(10, val);

val = analogRead(2);
val = map(val, 0, 1023, 0, 255);
analogWrite(11, val);

val = analogRead(3);
val = map(val, 0, 1023, 0, 255);
analogWrite(3, val);

val = analogRead(4);
val = map(val, 0, 1023, 0, 255);
analogWrite(5, val);

val = analogRead(5);
val = map(val, 0, 1023, 0, 255);
analogWrite(6, val);

}

Thanks!

The Arduino is a 5V system- you can't just feed 10V into it.

Although baum is correct, I'll assume you've used a simple voltage divider to make it safe for the arduino to read....

Perhaps it's just the last bit of the adc that is causing you problems. If this is so you might want to consider smoothing the values you read in. Firstly, store your value as a float and only convert to 255 as you write out:

const float smoothing = 0.9;
float val0;
void setup()
{
  val0 = analogRead(0); //read the initial value
}
void loop()
{
  val0 = analogRead(0)*(1-smoothing) + val0*smoothing;
  analogWrite(9, (int)(val0/1023.0*255.0));  
...
}

Hopefully this should keep you out of trouble.

Interesting problem. I don't see any reason in your code for this. Have you used the serial monitor to check values right at the flicker point? It's a little hard to debug that way. But you can set up your input to change from, say, 0V to 0.1V, and then in your code check for that transition. Then print out values to see if you catch anything odd.

My gut feeling, though, is that it sounds like an input problem rather than an output problem. Can you tell if the slight flicker is going to high or going to low? Does the only flicker happen right at the transition stepping up 0.1V?

Finally, are you sure your source of from 0V to 10V is rock steady at the transition point? If it is a wire-wound potentiometer, sometimes they give a transient as the wiper makes the step from one wire to the next. You might be able to catch that by filtering your input using software, as cmroanirgo suggests. I've got a software low-pass filter written up if you need the code.

EDIT: I assume your RC low-pass filter is on your PWM output, not your input. Is that correct?

I did this to smooth out my inputs form a pot for some RGB led's under the door handles of my truck. The the Serial print at the end was just for when i was playing with the code so i could watch it and see how smooth it is.

totalValue = 0; //reset variables at beginning of loop
trueValue = 0;

for (int i=1; i<=50 ; i++){ //take 50 readings from Analog Input pin
trueValue = analogRead(colorIn);
totalValue = trueValue + totalValue;
sampleTotal = i;
}

colorValue = totalValue/sampleTotal; //get average of 50 readings pulled in from loop

Serial.println(colorValue); // Print average color value to serial port

Then I just mapped colorValue down to the 0-255 range and wrote it to the proper pin.

Hope this might help you out.