Jump to content

Analog input to Digital input


Recommended Posts

Short answer yes.

 

Long answer, depends on what you want to do.

Most digital inputs work on a voltage/current levels to different signal with a gap between them to prevent dither.  I'll use the M91-2-T38 sourcing inputs as an example.  From 0-5 volts the input is recognized as 0 (Off).  From 17-28.8 volts the input is recognized as 1 (On).  Between those numbers your input is floating and you can get unexpected, random results. 

What this means is if you're analog sensor range is a close match the two point ranges is you can "fake" a digital input using an analog sensor.  However, you want to create logic to prevent rapid state changes when you approach the 5v or 17v values.  If there is a lot of noise you could have very high frequency state changes that could cause some nasty problems, such as running a relay faster than it's switching limits.

However, if you want to read the analog input in and use the analog value, the answer is no.  You get can only get On or Off

 

I apologize if the answer feels a bit disjointed.  I'm still caffeinating this morning.

 

*edit*

More proof of lack of caffeine. I may have read your question wrong.

If you want to use an analog in as digital in, you would create logic (assuming analog signal), to turn on above a certain level, off below a certain level.  From there you would want to add some de-bounce logic to prevent noise from the analog input affecting your state. 

You can also connect a digital input switch to the analog input as long as the voltage range is safe.  You'll still need the above code to turn your state on and off though.

 

Link to comment
Share on other sites

  • MVP 2023

Hi Tony,

+1 on Joe &  Cliff, (who posted before your reply became available due to the "moderator lag").

Further to the limiting resistor, I have had the same situation with an AI available when DIs were full.  But I needed a few of them.  With careful selection of resistor values, you can actually make an AI read a few DIs, rather than just one.  It was a bit fiddly getting values just right (due to tolerances), doing code to interpret the various AI amounts, testing in situ of all the combinations etc. but was well worth it to save adding a module.   ie Dig 1 reads 1V, dig 2 & 4 together read 5V etc.  Just something to keep in mind in case you need another one!

cheers,

Aus

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.