Fellow SO users,
I'm trying to calibrate a resistive humidity sensor that I'm reading values from the ADC. The ADC outputs an 8-bit value. I'm using a Vref value of 5V.
My first step in calibrating is to divide the number by 255 and multiply by the Vref value. Hence, calibrated value = (output / 255) * Vref.
Now, in VHDL, I've come across some VHDL code to divide two numbers. The one I have divides two unsigned numbers so that shouldn't be a problem. It is over here; VHDL divide two unsigned numbers
Now, in my VHDL file, I have the 8 bit ADC value (humidity) and I have defined two constants, max_val (11111111 = 255) and Vref (00000101 = 5) both as unsigned. I'm first converting humidity to an unsigned by using unsigned(humidity) and then passing this value and the max_num value into the division function. With the result, I'm multiplying it by Vref.
Now, my question is;
- Is this a good approach? I.e; the way I'm dividing and multiplying.
- How do I convert the unsigned value back into a std_logic_vector?
Kind regards.