Solution
The circuitry behind an Analog Input port is quite different from the circuitry behind the Digital Input. In this way, we need to understand how the Digital Input port is going to react giving certain input voltage to determine if its functionality is what adequate for our application. To deduce what behavior this port is going to have we must refer to the particular datasheet of the device. As an example, if we want to know how is going to react the NI-9401 module, which is a bidirectional DIO, we should analyze its Input/Output Characteristics, particularly the Input Digital Logic levels, refer to the following image.
What these characteristics say is that any Voltage below 0.8V will be considered as a logical 0 (LOW), and any Voltage above 2V will be considered as a logical 1 (HIGH). Any other Voltage between 0.8V and 2V will show up undeterminated behaviors. Additionally, the maximum Voltage recommended is 5.25V, which is the higher safe Voltage the device would resist. To evaluate the behavior to any other device just repeat the same reasoning with it datasheet.
So now that we can predict the behavior we are going to receive giving certain input voltage we can determine if we can use these Digital Input ports as Analog Input ports. So you can use it in this way within the following considerations:
- The input signal will be discrete, in other words, it will be just 1 or 0. Therefore, if you are just interested in measuring if the analog output of any device is higher than 0 this option can be suitable. However, if you want to measure a continuous analog output this port will be unuseful.
- You must be really careful with the maximum magnitude of the Analog Output signal that is being measured, to make sure that it will never be higher than the maximum safe voltage of the Digital Input indicated on its datasheet.
- It is always recommended to use ports to perform the task they were created for, therefore is highly recommended to acquire more devices with Analog Input ports rather than using permanently Digital Input ports to perform a task they were not designed to for.