PLC Programming Structure Question

kevilay

Member
Join Date
Feb 2009
Location
Ontario
Posts
174
Hello Im building a final project for school and I was looking for some input on how to structure my program, first I'll cover what it does, how it works, then what I need out of a program. Im not asking for it to be done for me just some ideas. i use micrologix 1000 PLC.

http://img706.imageshack.us/i/rockband.png/

This is a diagram I drew in paint. Thats a TV with the Rockband Video game playing on it. The brown is the wood housing for the sensors, the red is the sensors, When A note goes by they turn a PLC input on. The sensing circuitry is extremely fast. (nano seconds). Each sensor is hooked to input from left to right, I:0/0 to I:0/4 respectivly, 5 sensors.

Here is a youtube video of someone playing the game if you are unfamiliar:
http://www.youtube.com/watch?v=mYrqnDe1ENs

The guitar will be controlled by outputs. There will be 6 used outputs. 5 Buttons and 1 strum bar. The outputs will control mechanical relays. O:0/0 to O:0/4 For different colours on guitar, O:0/5 being the strum bar.

What I need from the program:
This is where it gets a little confusion for me because Im not great with PLCs, but heres what I want to do:

Sensors are slighly above where you actually have to strum the notes, this is necessary otherwise the sensors double hit from the small explosion it makes when u hit a note. So there will need to be a delay in the program, with some adjustment.

I was thinking of controlling the program with a bitshift shifting on a very small timer.

Heres the situations it needs to cover:

Green sensor is ON:

Short Delay, Green Button (O:0/0 is pressed Slightly early (5-50ms gotta test)
Strumbar is pressed on the exact time (O:0/6)
Green button stays on. (latching bit?)

The reason for the buttons stay on is that if there is a bunch of the same colour notes in a row it doesnt release and push.

For every other colour it needs to do exactly what is listed above. However its going to unlatch the bit before it presses another button under certain conditions.

If it is a single button, always unlatch button before new button is pressed, unless it is the same button twice in a row.

Make sure that if theres 2 buttons that need to be pressed at once it works under same principle.

Example.

Green note comes, it plays it and holds green..... yellow note comes it unlatches green then plays the yellow.... yellow green pair come at same time, holds yellow still and presses green also and plays it.

Im not sure how fast I can do a timer on a micrologix I gotta check but heres what i had in mind, kinda just restating the above.

For green note:
10ms Intervals
1 0 0 0 0 0 0 1 1 1 0
^ ............. ^ ^ ^ -- Note held for 3 pulses 30ms, Strum on just middle 1
Note detected

Not sure how to do all the latching bits n stuff help will be appreciated, if you read all this thanks so much

Kevin
 
Last edited:
Not to rain on your parade but what you will probably have to look at first is your time. You mentioned nano seconds. A PLC scan is generally in milliseconds. Inputs are also in Milliseconds. So this is going to be your first hurdle.

You said MicoLogix 1000. Take a look at the manul for this PLC and look at your time specs for inputs. A bit a reading here will probably save you later.

The idea sounds cool but you need to do some hardware study to make sure it can do what you want before you worry about how to write the code.
 
It detects fine, The sensors arnt a pulse, their on for the duration of the note, so it would be on for like 10ms as the note went by, Ive tested and had this working 100% the detection part works perfect. Sorry I should have specified that.

Kevin
 
Still kind of fuzzy on what you want to do, but I will take a stab at it anyway.

First lets break it down into what your working with. I am just making this up since I do not know the actual inputs and outputs.

Input 1 detects green
Input 2 detects yellow
Input 3 detects blue
Input 4 detects orange
Input 5 detects purple
Input 6 detects red


Outputs trigger a color associated button plus the strum.

Output 1 green button
Output 2 yellow button
Output 3 blue button
Output 4 orange button
Output 5 purple button
Output 6 red button
Output 7 strum button


Ok now that that is out of the wway lets look at what you want to happen. Pay attention to the way I write your process. This is how I think my way into my code.

If Input 1 is on then start timer 1.
When timer 1 is done then turn output 1 on. Seal in Output 1 until an input OTHER than Input 1 comes on.

repeat this for the other inputs and outputs with the exception of strum

If Input 1 thru Input 6 have timed out then turn output 7 on for a timed amount.


Now notice I used the word Seal instead of latch. A seal is a parallel condiotin to the one you expect to drop out.

You strum is being keyed off the color inputs so each time one times out then strum comes on.

Ok now that we have my guess on what you need to do lets get to what you need to understand.

By my estimation you need the manual again. What you need to look up is TON paying attention to the bits it uses. the TT bit and DN bits are what you want to understand to create the code I just defined.

Best thing you can do is get one color output working the way you want. Once you have this the other color outputs will work EXACTLY the same. The strum output is just a big OR statement.

If Input 1 is on OR Input 2 OR Input 3...etc then turn the strum on.

You will probably want to hold the strum on for a period of time or the mechincal componets may not have time to work.


There is probably several other ways to do this including latches but this is the easiest way I can see myself writing this code.

Hope this helps.

Post your code if you need more help.
 
well you certainly picked an original project. Heres some advise instead of latching when a note comes on use a b3:0 bit to record that.break the project down into managable sections first work on the detection of each note. with the bebounce timing. If your using micrologix one instruction that could help you in this case is the SQL and SQO instructions. I'm assuming that several strings will play at the same time so you may want to have them scan all colors simultaneosly the SQL instruction will allow this to read all masked inputs at the same time. (when it scans will depend on when you set it to scan at your desired rate). now if your merely replicating those inputs as outputs use the same SQL data table for your SQO statement. Just one idea to simplify what I beleive your trying to do here.
 
Random q, whats an immediate input and output do? Are they necessary.

On another note, I wanna just hit the strum very quickly, from testing I never had a problem with it not detecting a strum. A problem with timers on the micrologix is that they dont go down very low.

Kevin
 
I think if i remember the minimum timer is 100ms on the micrologix. I used 500ms as a delay, but it needs to be more accurate then that. If not I have to adjust the calibration on the game, but i rather not.


Someone gave me this example before but It never worked properly, there was almost no delay maybe 10-15ms at maximum delay setting:

"See the attached for th ML1000.

Limitatiuons:-

STI resolution fixed at 10mS so a 1 in the setpoint makes the code in file 3 execute every 10mS.

Data File size limited to 105 elements, and no other data files can be created. So I've made the "shift register" 100 elements long. With a STI of 10mS this will give a maximum delay of 1,000 mS, or 1 sec in 10mS increments.

Indirect addresses are not supported in ML1000, so you will need to edit the source address in rung 2 to get the required delay time:-

N7:99 0mS
N7:98 10mS
N7:97 20mS
etc.

N7:xx

where xx = 99 - (Delay / 10)

so for 500 mS delay

xx = 99 - (500 / 10)

N7:49

http://www.plctalk.net/qanda/attachment.php?attachmentid=11999&d=1257845179
http://www.plctalk.net/qanda/attachment.php?attachmentid=12000&d=1257845179

"

I wasn't quite sure why, it was a little over my head. Im pretty new to this stuff.

Kevin
 
Random q, whats an immediate input and output do? Are they necessary.

On another note, I wanna just hit the strum very quickly, from testing I never had a problem with it not detecting a strum. A problem with timers on the micrologix is that they dont go down very low.

Kevin

An immediate instruction means the associated input or output is updated then instead of during the I/O update part of the scan.

In your PLC reference manual look up the term IOM and IIM.
 
this is one of the reasons i suggested the SQL statement it shortens down the timing by using the same point in scan time to read all inputs at the same instance. then it will be a matter of sending those input conditions to the desired outputs before the next change in inputs also why I suggested the SQO as it helps avoid some cycle timing issues you may have with your tight timing. In short you scan all inputs at the same time deliver those inputs to your outputs before your next strum depeinding on your strum timing.
 
this is one of the reasons i suggested the SQL statement it shortens down the timing by using the same point in scan time to read all inputs at the same instance. then it will be a matter of sending those input conditions to the desired outputs before the next change in inputs also why I suggested the SQO as it helps avoid some cycle timing issues you may have with your tight timing. In short you scan all inputs at the same time deliver those inputs to your outputs before your next strum depeinding on your strum timing.

Hmm a SQO is a sequencer output right?

The biggest problem I found in the programming and why i was thinking of bitshifts is the following:

If you get 2 green notes 300ms apart but there is a yellow note inbetween these 2 green notes, but you have a delay of 500ms from input to output. This 2nd green note would be missed wouldnt it?

Kevin
 
Timers in Micrologic will go down to 10 ms. The problem you run into is your scan time.

If I remeber correctly (big if here) The timer runs and on the scan the accumlated value is equal to or larger than the preset the DN bit is set. On the next scan the DN bit is acted apon.

One way around this is to use a compare function GEQ instead of the DN bit. This elminates the time of the added scan.
It also makes a more accurate timer trigger.

One thing you will have to realize is you can never be faster than the length of 1 scan. Infact the general rule I use is I can not act/react consistantly faster than the sum of 2 scans.

Think of it this way if your input goes on after the part of the scan that reads the input image table then you are going to have to wait until the next scan to see it. Now you have to wait until that scan completes and the output image is updated to see the reaction to the input. So while the lag is not precisly 2 scans it can get pretty close. Scan time is directly related to how yuo write your program. If you look in the reference manual each funtion has a time it takes to complete. The sum of all this processing time for the functions + direct overhead for housekeeping (reading your data images..etc) is your scan time.

This is what Mordred was refering to when he talked about using a sequencer. A sequencer can reduce the amount of code you need to write and make your scan faster. KEy word here is may...depending on what you are trying to do it may make no difference. In something as simple as what you are trying I am not sure it will.
 
Alright, for rockband the fastest you will ever seen notes is every 1/8th of second. I just looked that up. So our timing isnt to critical but it needs to be consistent. Exact time inst of dire importance cause theres no way for me to measure it. So I need something that works and then adjust it till it seems to work best. Id say 500ms delay from input to output. But it has to be setup so the note is held for 100ms and the strum for 50ms. Just by speculation I think those will be good numbers. Does knowing this help? the biggest part im having trouble with is what i said above. with multiple notes within the 500ms delay that are the same colour but with a note switch between. Cause if u set a bit like state above, you would just "return on" the bit before its ever outputted.

Kevin
 
Hmm a SQO is a sequencer output right?

The biggest problem I found in the programming and why i was thinking of bitshifts is the following:

If you get 2 green notes 300ms apart but there is a yellow note inbetween these 2 green notes, but you have a delay of 500ms from input to output. This 2nd green note would be missed wouldnt it?

Kevin

Why would it get missed? Your code should be reacting to the state of the input. If the input is there then set the associated output correct?

If green input is on turn on green output after delay. Hold output until another input comes on without the green input being on.

Basic seal in logic.

Think of it this way:
no green yellow on then just yellow out
Green on, yellow on then yellow green out.
Strum on any input on.

The tricky part I see is the strum. The key here is transistion. If you keep getting repeats of the same color is there a point where the input does go off to on. IF the input just stay high the whole time then you will have no way to know when to strum again.


Simple way to check this is to set up counters and count the number of input pulses on each color. Have a CTU set up that counts each input. THe counter will count up each time it see's a false to true transistion. If this number differs from your count then it will not work.





As for timing: Remember everything adds. The time it takes the input to transistion from an off to on state... The time it takes the scan see this transistion
 
the input will turn on and off every note, even if its ones of the same colour. Im Gonna take all this info and try coming up with a program and see how it works. I got get my old laptop setup again haha its the only one with the software :p

Kevin
 

Similar Topics

Hello colleagues, Some time ago I started my adventure with programming. With your help and the courses, things are starting to come together...
Replies
13
Views
689
Dear All, I need a sample PLC program to count the output pulse of a mass flow meter so that a specific amount of mass (for example 100gm)can be...
Replies
2
Views
152
Hi Please I have zeilo smart relay #SR2A201BD but I don't have it's programming cable. Can I use any general usb/rs232 converter? Or need...
Replies
3
Views
163
Hi, Does anyone have thoughts or know of, can point in the right direction any published materials with a plumbing centric point of you explaining...
Replies
1
Views
166
@ All: what is your best guess on a potential range in increase in efficiency in % (i.e. saved programming hours, greater output, etc.) when...
Replies
5
Views
355
Back
Top Bottom