PWM normally has a fixed frequency but it can't have a fixed duty cycle. I can't help with the code as I am useless at writing in "C" (I work with assembler.)
The only thing clear is that Arduino board will be sensing voltage between 2 and 4 volts.
You say output of the board is pwm. Then you start talking about adjusting frequency and duty cycle of pwm, and you looose me at this point since you do not clearly state what you want:
- adjust frequency of pwm
- adjust duty cycle of pwm
- adjust both