Analog input to digital output using structured text or one of IEC 61131-3 standard

clueless_plc

Member
Join Date
Jun 2022
Location
India
Posts
7
Hello, I have a small programming task that I need help solving.
I have to:
* Create an analog input (4-20v)and a digital output
* The analog input must be scaled to 1 to 1000 in the code.
* If the rounded, scaled value is a prime number, the digital output should be set to TRUE for 5 seconds, regardless of what the analog value changes to during these 5 seconds.
I would like to use twincat or rslogix to solve this.

I could really use some help going about this or some sources to help me get going. Thank you in advance.
 
Last edited:
Whenever a new member posts a school assignment, we ask you to show what you've already done before offering advice on how to make improvements.
The challenging part of your assignment will be determining when your scaled result is a prime number. I don't know of any PLC which has an IsPrime() function. Since your range is only up to 1000 you could use a lookup table. Are you expected to determine whether or not the scaled value is prime within a single PLC scan or are you allowed to iterate over multiple scans?
 
What should happen if after the 5 seconds the analogue value is still a prime number - the output stays true for another 5 secs?


Look up {6k+/-1} optimisation for determining if a number is prime.
 
There are only 168 prime numbers between 1 and 1000 (same as the number of hours in a week, but I digress), so putting together a sorted array of them is not overly difficult (e.g. cut and paste 10 lists from here). Then, see if you are one of the top 10% of programmers (see here).

It will take but eight passes through a short loop to determine if a integer from 1 to 1000 is prime. Of course you can also eliminate 499 of them with a check of 1 bit.
_
 

BST XIC isitprime XIO timer.TT NXB XIC timer.TT BND XIO timer.Q BST TON timer 5000 0 NXB OTE itisprime BND


N.B. I think this assumes the the output should go to 0 for one scan if the value is prime when the timer expires, and then start another 5s if it is still prime on the scan after that.

Now all we need is to do is assign the value of [isitprime].
_
 
Last edited:
I was thinking of a lookup table with 1000 boolean entries with trues for the prime number entries :geek:
 
Have an array of integers, copy and paste prime numbers into this array.

Then do a FOR loop, if the scaled analogue input = array element then turn the output on.

That's if the PLC doesn't have a prime number function already.

5 minute job
 
You may want to check if that is really a 4-20v (sic) analog input. An analog signal of 4-20 mA is common in the industry. Also, the abbreviation for voltage is "V".
 
Surprised nobody has asked the question, what is the purpose of using only prime numbers in a PLC ? I can think of a few in other applications i.e. encryption or for gearing but not much else ?.
 
What should happen if after the 5 seconds the analogue value is still a prime number - the output stays true for another 5 secs?


Look up {6k+/-1} optimisation for determining if a number is prime.
There is no mention of what to do after the 5 seconds so i'm assuming its single scan
 
There are only 168 prime numbers between 1 and 1000 (same as the number of hours in a week, but I digress), so putting together a sorted array of them is not overly difficult (e.g. cut and paste 10 lists from here). Then, see if you are one of the top 10% of programmers (see here).

It will take but eight passes through a short loop to determine if a integer from 1 to 1000 is prime. Of course you can also eliminate 499 of them with a check of 1 bit.
_
Ok, thank you for the info
 
Have an array of integers, copy and paste prime numbers into this array.

Then do a FOR loop, if the scaled analogue input = array element then turn the output on.

That's if the PLC doesn't have a prime number function already.

5 minute job

Thank you, this is simple and should work well
 
Surprised nobody has asked the question, what is the purpose of using only prime numbers in a PLC ? I can think of a few in other applications i.e. encryption or for gearing but not much else ?.
It's just part of the assignment and nothing else.
 

Similar Topics

Hello everybody. for an asignment we are using a s7 1200 siemens starterkit to connect sensores to create a program. we were hoping to save some...
Replies
14
Views
6,422
On a Micrologix 1100 analog input, I appear to be getting an internal offset of about 11 counts out of 1023. Running the program from RSLogix...
Replies
5
Views
4,328
Hi, hope this is not too boring of a question but wondering can a analog input on a micrologix 1400 be used as a digital input? thank you in...
Replies
3
Views
2,445
Within a Chemical/Process Plant what type of instrumentation is considered Digital Input, Digital Output, Analog Input or Analog Output? Where...
Replies
5
Views
3,862
Hi How i can program Analog input 4-20mA to control digital output module with setpoints? I need to create control circuit example for heater...
Replies
4
Views
3,193
Back
Top Bottom