Author Topic: Set up Custom Function for ADC input  (Read 10081 times)

Thesis

  • Guest
Set up Custom Function for ADC input
« on: July 17, 2004, 07:12:13 AM »
I need to set up an A/D converter which is unipolar, 8 bits , and 10 volts full scale. Max numeric value from ADC would be 2^8-1 or 255.

I need to compare the ADC value to 25 , if less nothing happens, if greater or equal to 25 for more than 5 seconds the ouputs are activated.  If during the 5 second time period the value falls below 25 no alarms occur and timer is reset.It is ok to be above 25 as long as it doesn't stay there for more than 5 seconds in short...


I am hammering myself over how I'd write this function, any help would be appreciated.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Set up Custom Function for ADC input
« Reply #1 on: July 19, 2004, 09:28:56 PM »
You need to use two resistor to build a voltage divider to divide the 0-10V into 0-5V. (Two 10K ohm resistors in series will make a good voltage divider for this purpose).

You can then read the ADC value using:
 
  A = ADC(1)/16 (scale the input to 0-255)

Set up a 1.0 second clock pulse to execute a custom function that contains the above statement. Increment a variable (act as a counter) when A > 25. Set the counter to 0 if A < 25. When the counter goes above 5, then activate the output.

E.g.

    A = ADC(1)/16
   IF A > 25  
        N = N+1 ' N as event counter
        IF N > =5  
             .......  ' do what you want
     
        ENDIF
   ELSE
        N = 0    ' reset counter
   ENDIF

Should be an interesting exercise.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS