Jump to content
Sign in to follow this  
tonymony

Analog input to Digital input

Recommended Posts

Hi Joe,

Basically, I have all my digital inputs full and I need to add a new one for an alarm which is 0 or 1, I supposed I need to test the current when the alarm is on and make an interval to consider this MI like an MB inside the program.

KR,

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites
Quote

I supposed I need to test the current when the alarm is on and make an interval to consider this MI like an MB inside the program.

That would be the easiest way.  You'll need to put a limiting resistor on your input.

 

Joe T.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...