PWM using Analogue write

analogWrite(pin, value)

does the value have to be an integer between 0 and 255

can it be a float ie 0.01

can it be mapped to use more than 255 steps in duty cycle ?

does the value have to be an integer between 0 and 255

Yes.

can it be a float ie 0.01

No.

can it be mapped to use more than 255 steps in duty cycle ?

No.

The value has to be 0..255. You can use timer1 that has a 16bits register. But you will have to write your own analogWrite function if I'm not wrong. Have a look at analogWrite code.

If you go to hardware/arduino/cores/arduino/wiring_analog.c you can see the source of "analogWrite"

ty

The output is 0-255, but you can start from any value you have if you scale it using the map() call:

x=map(value, fromLow, fromHigh, toLow, toHigh)

(http://www.arduino.cc/en/Reference/Map)

In your case, it would be

x=map(value, fromLow, fromHigh, 0, 255 );

However, this only works for integers - for float, you'd need to write your own, but since they provide the code there, it's pretty simple:

float map(float x, float in_min, float in_max, long out_min, long out_max)
{
  return long ( (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min );
}

If you use float, be aware you may not be able to reach 255 because of floating point roundoff

@David Pankhurst: If the return type is float, returning a long is a bit limiting.

AWOL:
@David Pankhurst: If the return type is float, returning a long is a bit limiting.

In his case, he wanted to limit to 0-255, so clamping to a long would work (even BYTE would be fine) - as well, he'd have to rename the function.

thanks for the ideas guys

so i could have instead of 0-255 > 0 - 10000

would that resolution get outputted to the output voltage ?

ie 0-5 V divided by 10000 ?

Gadget999:
so i could have instead of 0-255 > 0 - 10000

In that case, the code is even simpler:

long value=8700; // for example
value=value*255/10000; 0-10000 -> 0-255

and the reverse

long value=237; // for example
value=value*10000/255;  0-255 -> 0-10000