PLC Programming Structure Question

Hey guys, I finally got some time now that I'm done exams to work on this a bit. I came up with the attached picture and had a few questions. I was using a higher S bit to give me more time between shifts, but that dont work out accurate enough so I wanna lower it right down to S4:0 which will mean i need 50 shifts per seconds. How can I use a bit shift to control more then 15 bits? do I need multiple shifts? Could someone shoot me an example it would be much appreciated.

http://img697.imageshack.us/i/bitshift.png/

Kevin
 
Wow. This is a fascinating topic. I don't have much to add, but I like to keep things simple if possible. How about using the timer enable bit (TT.EN) as a note output? You will always get the minimum time set by the timer, and the note will hold until the input to the timer goes false.

That takes care of my "point of failure" with that stupid game, lol!
 
I think i got all that figured out, but if you read my above post I asked how to do a bit shift of more then 50 bits that would be most helpful.

Kevin
 
Your question needs clarification - You can shift a bit for any number of positions - 50, 100, up to 255 in a Micrologix standard file length, even more if you set up to shift across file boundaries.

However, being familar with what you are doing, now you want to shift 50 bits in parallel at one time. To do that, you have to use something other than a BSR or BSL. FIFO-type instructions (FFL and FFU for the MicroLogix)) will shift words (16-bits) at a time, so you would need 3 of them working together to shift 48 bits as a block. However, the mechanics will be difficult.

Other commands that will move 16-bits from one place to another are COP, MOV, and MVM. Using 3 or more instructions working in parallel will allow you to move any number of bits, if that is what you must do.

Why 50 bits? I thought you only needed 5 digital outputs for your project, which could be done with five BSR's triggered by some timed pulse. Of course in your case you are only needing to shift the bits ONE position, the bit distance-time between (sensing input and when output is needed). To shift a bit only one position seems kind of a trivial use of a Bit-shift register. A timer will do the same function with a lot less trouble. But maybe you are wanting to demonstrate advanced techniques with your student project.

If so, I can help with that. First you have to understand what a bit-shift register is and how it can be used. Like I said, you need to use an EVENT to trigger the shifting of the bits. If you use a pulse from the free-running clock (S:4) then your shift will not take place at the right time (PLC clock and your Rockband music are not synched together), so your output will never happen at the right time.

To make it happen at the right time, you must use your 5 Inputs as triggers for 5 BSRs (not S:4/0), one for each color. You shift the bits one position each time a new input happens. That way the game is controlling the timing. Your outputs will occur then at the correct time (the same time as it take for the next input, whatever it may be). If this makes sense to you, then there is some hope that you will get it working.

Also, in addition to using your Inputs to pulse the BSR, you must insert your Color Input into the BSR at the Bit Address. I see that you are inserting B3:5/0 into the Bit Address. I cannot tell what you have going into B3:5/0 (could be correct or not). Your BSR output is definitely not set up correctly, as you are using B3:0/0 to turn on your Green Output and B3:0/1 to turn on Strum. That means that Green will come on during the first PLC scan (when clock bit S:4/0 goes on), and will go on/off every tick of the PLC clock. I doubt that is what you want. Your music will be playing at an incrediably fast rate, and will have no relation at all to when your Inputs appear.

Attached is an example of a BSR instruction. The bits are shifted by Input I:1/6. Bits I:1/7 (Tall Bottle) and I:1/8 (Broke Bottle) are fed into locations B3:4/0 (Tall Bottle Register) and B3:6/0 (Broken Bottle Register). When the Broken Bottle bits shift 21 times and reach addresses B3:7/5 through B3:7/8 (21 encoder ticks later), we DO SOMETHING. Notice that the Encoder Input I:1/6 is controlled by the movement of a bottle conveyor belt. In your program, the time between your music note inputs IS NOT controlling the movement (shifting) of your bits. It is going to take a miracle for it to work like that.

BSR Example.jpg
 
Last edited:
Of course in your case you are only needing to shift the bits ONE position, the bit distance-time between (sensing input and when output is needed).

First you have to understand what a bit-shift register is and how it can be used. The idea is to simulate the movement of SOMETHING real, but do it in the PLC's memory. In other words, as something (say musical note inputs) move on a simulated "light conveyor in a game", we want a bit for each note to move inside the PLC memory at the SAME time and for the SAME distance as the real ones. Your EVENT is the appearance of a note. Your BSR Length should be set to 1 (the distance and time until the next note pops up), only 1 bit position, then you are ready to use it, to output the sounds and strum the guitar! When the next note appears, you want the previous one to be playing!

Which note plays depends on the value (1 or 0) of the Inputs that should go to the Bit Address of each of the 5 BSR's. The output then will be the second bit of each BSR File Address, and for Strum, all 5 will be paralled and fed to the Strum Output. For each note output, only its BSR File Address second bit will be used to control the note output.
 
What I was meaning is can I use a shift of more then 15 bits. I liked how mine was setup where an input goes into bit 15 then shifts right 15 times and on bit 0 it sends it to the output. Instead of it shifting 15times I would like it to shift 50+ times.

Kevin
 
If that is what you really want to do (shift a BSR 50 times), then put your data in 50 up bits from B3:0/0. There are 16 bits per word, so 48 bits up would be address B3:3/0, then add 2 more bits, so your new Bit Address would be bit B3:3/2. That is where you would need to input your data that needs shifting 50 times and come out at B3:0/0. Your BSR Length would need to be set to 50 also.

Although I can't imagine how you are going to make this perform your original stated function....Perhaps you have redefined your project now to be something else.

Here is a LogixPro Simulator program that performs your original project description. I tested it out, and it does delay the outputs for 1X times the distance between your input location and your output location.
 
Last edited:
If that is what you really want to do (shift a BSR 50 times), then put your data in 50 up bits from B3:0/0. There are 16 bits per word, so 48 bits up would be address B3:3/0, then add 2 more bits, so your new Bit Address would be bit B3:3/2. That is where you would need to input your data that needs shifting 50 times and come out at BS:0/0. Your BSR Length would need to be set to 50 also.

Although I can't imagine how you are going to make this perform your original stated function....Perhaps you have redefined your project now to be something else.

I tried doing that and it didnt shift the bits that wernt on the B3:1,2, and 3 but maybe ill try it again.

Kevin
 
To make a bit-shift register work, all parameters have to be set EXACTLY right. You can't be off a bit or two and expect it to work. It can't read your mind, so only knows what you put into it. GI-GO.
 
To make a bit-shift register work, all parameters have to be set EXACTLY right. You can't be off a bit or two and expect it to work. It can't read your mind, so only knows what you put into it. GI-GO.

I was just looking at your program, I dont understand the purpose of the bit shift?

Kevin
 
Yes, I can see that you don't. The purpose of any bit-shift is to match the movement of something in the real world, except do it inside the PLC's memory. The key is first figuring out the real situation: what is moving, and how can I track that movement inside the PLC memory? If you do not have inputs that tell you when the real-world item moves, then your PLC internal memory movement will not work. In your case you are using a timer to simulate events for which you do not know the real times (and besides the real times are changing all the time). So you need a way to measure that time using the Inputs that you do have. (That is simple to do by using a PLC timer to start when an Input goes on, and stop when the next input goes on). When you see that, you will know how my version of your program works. Actually it works the same way as the first one I wrote back several days ago, except now I converted it to use 5 BSRs because you seem to be hung up on using that instruction.

If you run my program in LogixPro, and open up a Data Monitor window for B3, you will see the bits get inserted at B3:1/1, B3:2/1, B3:3/1, B3:4/1, and B3:5/1. Then the next note that comes along shifts all the bits again and they go out at B3:1/0, B3:2/0, (and so on) and then trigger your outputs.
 
Last edited:
Kevin,

If you get your input sensor working, then this program should play a song with fewer errors than most human players.

The first flaw in my BSR version are that the last note at the end of the song will not get played (because there is not a NEXT note to drive it out of the bit-shift register). My first version using the timers does not have this flaw.

The second flaw is that if there is a rapid change in the time between notes, the note at the change may be missed (played too late if the time is speeding up, or played too quick if the tempo is slowing down). That is about what a human player would do during a rapid change-up!

There are probably fixes to these two problems that you could work on once you get the basic program running. At least I can see where you could in theory fix the last-note-missed problem. You could save the Time-Between-Notes to a temporary memory location (named "Last-Time-Between-Notes) that gets updated each cycle. Then use a Greater Than comparison of the current Time-Since-Last-Note and (Last-Time-Between-Notes + 3). When GRT is true, then a note has not played within Last Time + 3, so go ahead and shift the BSR one last time, then stop the BSR and the program cycle. That would cover the last note of the song.

Actually the "+ 3" above needs to be 1 more than the maximum time difference of the slowest change-up in the Rockband game. I know no way to determine that except trial-and-error (or in the PLC world it is called testing out a program).
 
Last edited:

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
687
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