Thank you very much dc 42!. The problem is exacltly what you explain (there is no discharge path for the capacitor). Adding a 2,2k resistor I have a variable output depending on the pwm value, but not an 0-10V value. I thought a new design (attached) tha cen be works as I expected, and I want to know if somebody can give me a feed back before construc it.
The idea is to use other 4N25 (U3) for invert the signal of PWM, and give this inverted signal to 4N25 (U2). When the PWM of arduino is High U1 charges the capacitor, and when the PWM of arduino is low U2 gives a path for discharge the capacitor directly to GND.
Jonisonvespaa, I think that the circuit wit an opamp is more easy (I have do it and it works really fine), but I have a noise problem. My circuit regualtes an inverter with temperature sensors DS18B20, and when I connect the inverter and motor, I lose the temperatures from DS18B20. For do it I connect an RC filter at the output of the arduino’s PWM output for get an analogic 0-5V signal. After that I connect this signal to an opamp for get 0-10V. If you need more detail ask me.
Have a nice day!