0-5V Ramp Output

Hi guys, i'm new to arduino and its programming.

I begin a project, i buy a Arduino Pro mini and i want to time pulse of a PWM signal. And with the time measured, i want to output a 0-5V

Exemple of code i begin :

int ch1; // Entrée RSSI
int ch2; //Entrée Qualité du Lien

void setup() {

  pinMode(12, INPUT); // Entrée Qualité du Lien
  pinMode(13, INPUT); // Entrée RSSI
  
}

void loop() {

  ch1 = pulseIn(13, HIGH, 5000); //Je met 5000, mais suite à mes essais, je crois qu'on  
  ch2 = pulseIn(12, HIGH, 5000); // peut diminuer cette valeur.

So with time less than 1000us i want my output to be 0V, and when time is more than 2000us the output at 5V. And add a "ramp" to have a voltage between 0 and 5V as time of PWM signal will change.

First it is possible ?
And second, did my code is well started ? =p

thanks all !

I'm no programming expert (Mech Engineer here), but you could do something like:

IF (pulseIn > 1000 & pulseIn < 2000)
map(1000, 2000, 1%, 99%)
ELSE IF ( pulseIn > 2000)
pwm = 100%
ELSE
pwm = 0%

Obviously my syntax is poor, but you get the idea.

The Arduino doesn't have a variable voltage output - the 'analog' outputs produce pulse width modulated square waves which are often used to make LEDs and so on display variable brightness, but this is done by switching them on and off very rapidly and not by outputting a variable DC voltage. In order to achieve that, you'd need to connect a digital to analog converter, digital potentiometer or some other way to convert a digital signal to your required analog voltage.

I believe you can use a PWM output with a low pass filter as a pseudo-analog out.

i will do some test, and tell you my result !

thanks a lot guys !

I do not think you are using pulseIn() correctly. The pulseIn() function is used to measure how long between when the pin goes LOW and when it goes HIGH again, or between when it goes HIGH and when it goes LOW again.

It is not meant to measure any kind of elapsed time. The millis() function is for that.

What do you have connected to pins 12 and 13?

The comments indicate that ch1 is supposed to be some measure of RSSI. Timing how long a pulse is won't tell you that.

ok i see.

In Pin 12 and 13, i connect 2 PWM signal, and i want to measure how long is the pulse.

If i use your language, measure time between when pulse goes High and when it goes Low.

With this time i want to build a ramp output that will provide a 0-5V

example :

if time < 1000usec. output will be 0Volt
if time > 2000usec. output will be 5Volt
if time is about 1500usec. output will be around 2.5Volt

hope it is more clear now =)

Is this for a R/C car?

yes to read RSSI signal of my Plane Receiver to flight FPV