YAMFPP (Yet Another My First PLC Program)

drbitboy

Lifetime Supporting Member
Join Date
Dec 2019
Location
Rochester, NY
Posts
8,097
Howdy,

Summary

Rank beginner here. I don't have anything more than [RSLogix Micro Starter Lite], so I am using that for it's editing environment.

I am fiddling with writing a random number generator (RNG).

If you have some spare time, please look over the attached file; as noted below I am primarily interested in critique of style and implementation, but all comments are of course welcome.

Thank you.

Details

I did look at past PLC RNG posts (the clock thing is WAY cool), but chose to re-invent the wheel anyway, with an eye toward developing some actual PLC skills; mine are similar to what my father said at an interview almost seven decades ago when asked what he knew about the Mollier diagram: "I can spell it," to which the interviewer said "Well, that's better than some of my engineers."

The context is that I am helping my brother, who has a lot of experience with PLCs in industry; I'm quick with the math side so sometimes I bug him enough that he asks me to help out. We didn't talk much about why he wanted an RNG, but I think he is doing some demos or training and wants to add noise to a model being controlled by a PID.

I am not tied to the LCG/Box-Muller framework so feel free to make other suggestions along those lines, but what I am far more interested in is critique of my implementation, style, how many instructions are on each rung, etc. I'd like to be able to help out more than putting equations on a page that my brother has to translate into ladder logic, AOIs, etc.

See the caveats in the comments over the second rung:
  • I have not yet grokked the addressing yet,
  • nor how persistent non-device data ("variables?") are stored.
  • As you can probably gather, I am far more comfortable in C/C++/Python/Fortran/Node.js/etc., and some of that baggage will certainly be polluting my approach.

P.S. At https://github.com/drbitboy/plc_rng/tree/master/zz_miscellany there are some .L5X files where we did some work in something (Studio 5k, maybe?) better than [* Starter Lite] while my brother was visiting for the holidays: the LCG/RNG is in an AOI, but we never really got to the gaussian distribution.

View attachment 52974
 
Howdy,

Summary

Rank beginner here. I don't have anything more than [RSLogix Micro Starter Lite], so I am using that for it's editing environment.

I am fiddling with writing a random number generator (RNG).

Mark II: I've learned some things; many thanks to the writer of the [LEARN PLCS] pages.

  • Outputs have to go last, so one vertical run or branch per operation
  • LN, SIN and COS unary functions have all been replaced with NEG
  • The LCG/RNG portion now works
 
RNG success and other updates

My brother was able to take the 16-bit Random Number Generator code I wrote for MicroLogix 1100, re-implement it using AOIs and 32-bit DINTs for ControlLogix/CompactLogix, and test it on a CompactLogix 1768-L45. We also tested 1000 of the random numbers it generated using the Anderson-Darling normality test, and we can reject the null hypothesis that they are not normally distributed.

All of our work is now on Github: https://github.com/drbitboy/plc_rng - the READMEs are sparse, so let me know if you are having trouble navigating what is there.

I updated the MicroLogix version of the Uniform-Distribution RNG, mostly in the comments. I next plan to add the gaussian distribution, without native natural logarithm, sine or cosine instructions.

Thanks in advance for any feedback on the implementation, coding style, etc.
 

Details

I did look at past PLC RNG posts (the clock thing is WAY cool), but chose to re-invent the wheel anyway, with an eye toward developing some actual PLC skills; mine are similar to what my father said at an interview almost seven decades ago when asked what he knew about the Mollier diagram: "I can spell it," to which the interviewer said "Well, that's better than some of my engineers."

The context is that I am helping my brother, who has a lot of experience with PLCs in industry; I'm quick with the math side so sometimes I bug him enough that he asks me to help out. We didn't talk much about why he wanted an RNG, but I think he is doing some demos or training and wants to add noise to a model being controlled by a PID.

I am not tied to the LCG/Box-Muller framework so feel free to make other suggestions along those lines, but what I am far more interested in is critique of my implementation, style, how many instructions are on each rung, etc. I'd like to be able to help out more than putting equations on a page that my brother has to translate into ladder logic, AOIs, etc.

See the caveats in the comments over the second rung:
I have not yet grokked the addressing yet,
nor how persistent non-device data ("variables?") are stored.
As you can probably gather, I am far more comfortable in C/C++/Python/Fortran/Node.js/etc., and some of that baggage will certainly be polluting my approach.

View attachment 52974

Well that was a lie.
 
Anyway, I think I finished the Chebyshev-based sine and cosine in MicroLogix, so the Box-Muller is half done.

Does anyone know how to save values to disk in a [RSLogix Micro Starter Lite] environment?
 
I did not see the point of the first 3 rungs?, perhaps I'm missing something?
B3:0/0 is only one used in the array so if off then it will be off why bit reset?
 
Thank you

I did not see the point of the first 3 rungs?, perhaps I'm missing something?
B3:0/0 is only one used in the array so if off then it will be off why bit reset?

Yes, I probably have many unnecessary steps in there. Thanks for the feedback!

Summary

I am not sure exactly which rungs you are referring to (see caveat below), but in my coding of other languages I tend to be cautious, if not anal-retentive, about initialization, so here dealing with a new (to me) language (plus hardware!) I was probably trying to be really really really sure the first scan was an "even" scan i.e. B3:0/0 cleared. With a few days of this under my belt I think that I could either RTFM/trust the hardware or use summat like this

Code:
   S:1/15    B3:0/0     B3:0/0
  ---| |------| |--------(U)----


Details

Caveat: I have been grinding on this for a while*, learning from this forum and from my brother and from my mistakes, so this thread is a mess. I am not sure which .ZIP you are referring to, so I'll try to guess. If this does not make any sense, feel free to send me a screenshot (or the .ZIP) that you are looking at; you can get the current version here, although I am about to update it to get around some buggy software (probably the RSLogix 500 emulator).

The first rung is to hold program overview comments; [RSL Micro Starter Lite] would not let me leave that rung empty, so I added a non-functional output. Also, my brother has the convention that he puts a dummy (i.e. unused) output as the final branch of any rung with a comment, and attaches the comment to that dummy output instead of to the File/rung; that way, if he inserts or appends a rung above or below that one, it does not get the same comment automatically. After having a few moving experiences with comments, I chose to follow that same convention; I mention the use of B3:9 bits for comment attachments in that first comment, although that mention is possibly in a later version than you were looking at.

The rung with the B3:0/0 hijinx was from before my brother told me about the [First Pass] bit in S1:15 and how outputs are initialized, so it was my belt-and-suspenders attempt to intialize the first pass to be an "even" pass.

* I discovered yesterday that I cannot rely on the accuracy of the result of a multiplication of two words; is MUL an analog instruction(;-)?
 
Yes, I probably have many unnecessary steps in there. Thanks for the feedback!

Summary

I am not sure exactly which rungs you are referring to (see caveat below), but in my coding of other languages I tend to be cautious, if not anal-retentive, about initialization, so here dealing with a new (to me) language (plus hardware!) I was probably trying to be really really really sure the first scan was an "even" scan i.e. B3:0/0 cleared. With a few days of this under my belt I think that I could either RTFM/trust the hardware or use summat like this

Code:
   S:1/15    B3:0/0     B3:0/0
  ---| |------| |--------(U)----


Details

Caveat: I have been grinding on this for a while*, learning from this forum and from my brother and from my mistakes, so this thread is a mess. I am not sure which .ZIP you are referring to, so I'll try to guess. If this does not make any sense, feel free to send me a screenshot (or the .ZIP) that you are looking at; you can get the current version here, although I am about to update it to get around some buggy software (probably the RSLogix 500 emulator).

The first rung is to hold program overview comments; [RSL Micro Starter Lite] would not let me leave that rung empty, so I added a non-functional output. Also, my brother has the convention that he puts a dummy (i.e. unused) output as the final branch of any rung with a comment, and attaches the comment to that dummy output instead of to the File/rung; that way, if he inserts or appends a rung above or below that one, it does not get the same comment automatically. After having a few moving experiences with comments, I chose to follow that same convention; I mention the use of B3:9 bits for comment attachments in that first comment, although that mention is possibly in a later version than you were looking at.

The rung with the B3:0/0 hijinx was from before my brother told me about the [First Pass] bit in S1:15 and how outputs are initialized, so it was my belt-and-suspenders attempt to intialize the first pass to be an "even" pass.

* I discovered yesterday that I cannot rely on the accuracy of the result of a multiplication of two words; is MUL an analog instruction(;-)?

I use an AFI---NOP in the first rung for diagnostics or commenting. That way you're not enabling bits for no reason.
 
Double negative (no NOP)

I use an AFI---NOP in the first rung for diagnostics or commenting. That way you're not enabling bits for no reason.

That was my first choice, but there is no NOP in the environment I am using (Lite + Emulator).

I dunno why: maybe it's hard to emulate in software(;-).
 

Similar Topics

Any news on Studio 5000 Designer V34 yet? I assume it is going to be released late summer early fall. Has anyone heard anything about new...
Replies
107
Views
56,915
So, after adding a second PC, purchasing another server license and setting up to function as a redundant server for FTV SE, I think I've...
Replies
2
Views
2,179
Starting Oct. 1, 2020 UL508A panels shops have to have at least one person on staff that has passed this exam. I plan on doing it within a few...
Replies
70
Views
75,876
Opto is hyping these like crazy but I'm wondering what the experiences are of someone whose actually installed and commissioned one in the real...
Replies
3
Views
1,843
What software are you using or would recommend for drawing interlock, control and sequence diagrams? A full blown CAD feels over the top to me...
Replies
10
Views
3,234
Back
Top Bottom