Customizable 0-5V output
Posted: 16 Apr 2020 22:49
Warning! Make sure you verify any signals before connecting it to sensitive equipment. Use at your own risk!Mario wrote:How can I get a 0-5V output signal compatible with YourDyno?
The example code already have a PWM function to output an analog signal.
Code: Select all
void UpdateAnalogOutput() {
//Local constants.
const float AirFuelRatioOctane = 14.70;
const int maximumOutput = 51; /* 1V */
const int minimumOutput = 0; /* 0V */
//Local variables.
int analogOutput = 0;
float lambdaAFR = Lookup_Lambda(adcValue_UA) * AirFuelRatioOctane;
//Convert lambda value to PWM output.
analogOutput = map(lambdaAFR * 100, 2000, 1000, minimumOutput, maximumOutput);
//Make sure we do not exceed maximum values.
if (analogOutput > maximumOutput) analogOutput = maximumOutput;
if (analogOutput < minimumOutput) analogOutput = minimumOutput;
//Set PWM output.
analogWrite(ANALOG_OUTPUT_PIN, analogOutput);
}
const int maximumOutput = 255; /* 5V */
analogOutput = map(lambdaAFR * 100, 735, 2239, minimumOutput, maximumOutput);
maximumOutput need to reflect the maximum output voltage 0 = 0V; 51 = 1V; 255 = 5V.
The map function is modified with the AFR max and min values * 100. 7.35 AFR at minimumOutput (0V) and 22.39 AFR at maximumOutput (5V). At this point the signal is a PWM signal adjusting the duty cycle with the map function. To filter the signal to a DC-voltage we need to add a RC-filter to the output as the following schematic describes.
To improve response time, reduce resistance from 1k to 470R.
Here is the output signal at 22.39 AFR (5V):
Also check out our video of a 0-1V output for a Lambda Gauge.