Analog signal conversion

J2009

Member
Join Date
Dec 2016
Location
South Carolina
Posts
23
I am using an analog point I/O input card with a 4-20mA signal. The number comes to an INT tag. I am trying to convert the value to a percent 0-100. Im using the CPT instruction to accomplish this by dividing and multiplying by 100. I need the destination of the compute instruction to be an integer but it always reads 0. What I am doing is creating a real tag as the destination of the compute instruction and then moving that value to an integer tag. Is there a way to accomplish this without having to create a real tag and then moving to an integer tag?
 
the CPT instruction should be all that you need (specifically - no REAL/Floating Point location should be required) ...

quick question:

are you sure that the CPT rung is actually being scanned/executed by the processor? ... if you've put this into a new Routine/Ladder File then you probably need a JSR instruction to tell the processor to service the new code ...

troubleshooting tip:

go to the Destination of the CPT instruction - and manually type in a bogus number (example: 88) ... if the bogus number "sticks" then the CPT is not being scanned/executed ...
 
Last edited:
Yes I added a JSR to the main routine but if I look at the INT tag that I'm sending the value to it is always 0 no matter what the value of the inputs of the CPT expression. That's when I created the real tag as the destination of the CPT and the value was there as a decimal number. I do not need the value to be that accurate all I need is the integer value.

Is there a reason that the value only shows up in the real tag and not the INT?
 
how small is the REAL number? ... if it's less than 0.5 then it gets "rounded off" to 0 when you try to put it into an INT ...

if nothing else seems to work, try posting your code and we'll take a look at it ...
 
It's not that small, I simulated a 12mA signal into the input module. The module is scaled to approx. 3000-16000 for 4-20mA. When I input 12mA to the module the INT tag associated with that input changes to approx. 9000 I can't remember the exact values. Then I use the following expression
(input value/lowest value)/(highest value/lowest value)*100

The output of the CPT value was about 49.996 in the REAL tag but it only showed 0 when I was sending to the INT
 
It's not that small, I simulated a 12mA signal into the input module. The module is scaled to approx. 3000-16000 for 4-20mA. When I input 12mA to the module the INT tag associated with that input changes to approx. 9000 I can't remember the exact values. Then I use the following expression
(input value/lowest value)/(highest value/lowest value)*100

The output of the CPT value was about 49.996 in the REAL tag but it only showed 0 when I was sending to the INT


Your formula is incorrect ( although you probably have it right in your logic to get 49.996)

(input value-lowest value)/(highest value-lowest value)*100
(9000-3000)/(16000-3000)*100=46.153
Post your code or a screen shot of all the logic involved.

I was sending to the INT
How are you doing this "sending"
 
Sorry, yes that's the code I used. I'm not looking at the code now but it works correctly the way I have it set up which is the destination of the CPT instruction as the Real tag. Then I use a MOV to move the value from the Real tag to an INT tag. The problem is that I would rather not have to send send "destination of CPT" to a Real tag and then MOV to and INT if it's not necessary because of confusion to someone troubleshooting in the future.
 
Sorry, yes that's the code I used. I'm not looking at the code now but it works correctly the way I have it set up which is the destination of the CPT instruction as the Real tag. Then I use a MOV to move the value from the Real tag to an INT tag. The problem is that I would rather not have to send send "destination of CPT" to a Real tag and then MOV to and INT if it's not necessary because of confusion to someone troubleshooting in the future.


What PLC are you using?

The "CPT" instruction should accept an INT as it's destination. Have you tried?

But there is no reason the "MOV" instruction should not work. As Ron pointed out.
 
Last edited:
I'm using a Controllogix 5571 processor. I did try an INT and the value was always 0 no matter what signal I sent to the input module.

I'll try it again next week, maybe I had something incorrect.

Thanks
 
For Multiply and Div the CPT evaluates left to right....so if you are using all INTs, if the numerator is smaller than the denominator in the divide portion of the equation, then that evaluates to 0 and when you multiply by 100, 0* 100 = 0. You have to multiply the numerator by 100 first in the CPT expression to insure that the numerator is larger before you divide. That's why it's best to use REALs if possible in CPT instructions...if you need to then convert it to an INT or DINT, just MOV the REAL into the INT after the CPT.
 
Last edited:
For Multiply and Div the CPT evaluates left to right....so if you are using all INTs, if the numerator is smaller than the denominator in the divide portion of the equation, then that evaluates to 0 and when you multiply by 100, 0* 100 = 0. You have to multiply the numerator by 100 first in the CPT expression to insure that the numerator is larger before you divide. That's why it's best to use REALs if possible in CPT instructions...if you need to then convert it to an INT or DINT, just MOV the REAL into the INT after the CPT.

Plenty of examples of AOI for the missing SCP instruction, ... just saying...
 
This is what I like about GE PLC. It converts its analog inputs at 0-32000 counts.....Easier to work with.
In your situation just convert input to real and divide by 320...easy 0-100%.
 
Last edited:

Similar Topics

Hello, I have a compact Logix plc and I have been task with configuring alarms into our SCADA when an Analog signal stops moving. The analog...
Replies
6
Views
235
I'm pretty new to PLC's, so forgive me if I use the wrong terminology and whatnot. We have an issue at work where we have a flow meter that is...
Replies
10
Views
287
I need assistance in the form of some example programs pertaining to analog read and write. Thanks in advance. Sangli
Replies
1
Views
176
Hello folks, Hope everyone is doing well. I am a beginner at working in analog signals with PLC Analog module: 1769-IF4 ( 4 analog inputs ) PLC...
Replies
9
Views
1,348
I need to change my program to increase a IP transducer by 0.5 psi every 5 seconds. I am making a automated pressure tester using a pump, IP...
Replies
6
Views
1,040
Back
Top Bottom