tonymony Posted October 15, 2016 Report Share Posted October 15, 2016 Hi Sirs, There is anyway to convert an analog input to a digital input? KR, Link to comment Share on other sites More sharing options...
MVP 2023 Joe Tauser Posted October 16, 2016 MVP 2023 Report Share Posted October 16, 2016 You're going to have to get a lot more specific with that question. Joe T. Link to comment Share on other sites More sharing options...
tonymony Posted October 17, 2016 Author Report Share Posted October 17, 2016 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, Link to comment Share on other sites More sharing options...
cantcliff Posted October 17, 2016 Report Share Posted October 17, 2016 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 More sharing options...
MVP 2023 Joe Tauser Posted October 18, 2016 MVP 2023 Report Share Posted October 18, 2016 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. Link to comment Share on other sites More sharing options...
MVP 2023 Ausman Posted October 18, 2016 MVP 2023 Report Share Posted October 18, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now