Author Topic: ADC simulation  (Read 13130 times)

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
ADC simulation
« on: August 20, 2012, 08:56:50 AM »
Hi I do try out ADC function by using variable resistor 5K.
I just assume this

Temp C          Voltage         ADC
-20C               0                  0
+200C            5                  4096

By linear relationship
(T+20)/(200 +20) =(A-0)/(4096-0)
T = (A/4096)*220 - 20

while try with value A=0 , i do get T = -20C and when A=4096 then T = 200C. mathematically correct

In my custom function i do wrote as
B = ADC(1) *220 - 20

When i do adjust the variable to minimum end, do get -20C but in maximum end i do get 900C instead of 220C. May i know what cause the error. Thanks


support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:ADC simulation
« Reply #1 on: August 20, 2012, 11:27:53 AM »
You B formula is incorrect:

B = ADC(1) *220/4096 - 20
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
Re:ADC simulation
« Reply #2 on: August 20, 2012, 09:42:48 PM »
 ;) Cheers

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
Re:ADC simulation
« Reply #3 on: August 22, 2012, 08:28:45 PM »
Hi, I am using 5K variable resistor to simulate height of water level from 0 to 10 m

A = ADC(1)*10/4096
SETLCD 1,1,"Wtr Level = "+STR$(A)+ " m"

my intention is to display in LCD with 2 decimal place. Is that possible? Currently its just display in integer format.
« Last Edit: August 22, 2012, 08:31:23 PM by Tito »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:ADC simulation
« Reply #4 on: August 23, 2012, 02:07:37 PM »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
Re:ADC simulation
« Reply #5 on: August 24, 2012, 08:12:23 PM »
Superb, thank you.

A = ADC(1)*1000/4096 'changed from 10 to 1000
SETLCD 1,1,"Wtr Level = "+STR$(A/100) +"."+STR$(A mod 100,2)+ " m"