Map Function and Analog Write Function

Hi All,

Need your expertise in this. We know that "Map" function re-maps the incoming signal from one value to another value. Let us consider this

Say my incoming signal is a 50Hz (with voltage level ranging from 0-2.5 V) PWM signal and I would like to convert it to a higher volt range say 0-3.5V (of steady DC signal) , I would note down the pulse duration of the incoming signal by using "PulseIn" function and with the "Map" function I will convert the range and get the output using "AnalogWrite" function. Say

duration = pulseIn(pin, HIGH);
outputValue = map(duration, 871, 1717, 50, 169);
analogWrite (out, outputValue);

  1. Now what I would like to know what would be the properties of the output signal i.e whether the output signal frequency will be 490Hz PWM (for pin 9 & 10 in Arduino Mega) irrespective of the input signal frequency (50Hz) or the it will change.

I'm new to this and it would be of a great help if you can provide an answer.

Thank you all in advance

I am not familiar with pulseIn(), but the output frequency will be 490Hz, and you can change it to a different frequency by modifying the timer frequency, if you want.

@dptdpt

Thanks for your reply.

Look up what map does. Basically it just applies a scaling factor to a number. It does not do what you seem to think it does.
You are measuring the time of half a cycle and using that number to set the duty cycle of a fixed frequency output.

So there is no factual relationship between the input and output just the rather odd relationship you are imposing on it.

Like so many posts here if you say what you actually want to do you could get better answers, but I suspect what you want to do is a lot harder than you think.