Porting C code using GX Developer

Frosty_4th

Member
Join Date
Jan 2005
Posts
5
We've been asked by a client of ours to convert an old application we originally wrote in "C" for use on an embedded processor to now run on a Mitsubishi Melsec Q-Series PLC. The development environment will be GX Developer. We've written ladder logic before, but never on a Mitsubishi PLC and never using GX Developer. We've downloaded the trial version of GX, however the help files have not been very helpful. Below is a summary of our application:

1. Its purpose is to detect and profile objects that pass through a series of sensors. The sensors will appear as digital inputs to the PLC by using the Q-Series QX40-S1 input module. The sensors used to profile the object passing by are basically proximity sensors. A signal from a light curtain is used to indicate when the object has cleared the area where the proximity sensors are mounted which completes the profiling for that object.

2. In total there are digital 7 inputs. 6 are proximity sensors, and one is the light curtain.

3. Depending upon the order in which the proximity signals turn ON/OFF, decisions are made for certain attributes of the object being profiled. I.e., sensor A turning on before sensor B means one thing, whereas sensor B turning on before sensor A means something else.

4. Profile data is also calculated using the relative time each sensor is in its on or off state. Our "C" code currently accomplishes this by time stamping the transitions of each signal down to the millisecond and comparing the relative time of one sensor against another. We haven't found any references to GX supporting timestamps so implementing this part of our current "C" logic in GX is an unknown.

5. When the light curtain signal changes from ON to OFF, it means the object has cleared the area where the sensors are mounted. That causes our logic to send the profile results for the object that just passed by. Currently these results are sent using a serial protocol but will need to be ported to use shared memory within the PLC to “talk” to another CPU mounted on the same base unit. The design of our client's PLC setup will include 2 CPUs (both are model Q02). Our profiling logic will run on one CPU, and other existing logic related to the overall application will run on the other CPU. We will send the profile data gathered for the object to an area of shared memory. Our clients program running on the 2nd CPU will read our profile results and use it in the existing logic for their application.

Our questions are:

1) Can GX be used for the type of logic used by our application, especially given that we need timestamps (relative or absolute) for sensor transitions?

2) Approximately how long would it take to port the logic to a Q Series PLC using GX Developer? This is of course a loaded question as you don’t have access to the original code, but I believe we have outlined the areas in the code that may cause the most problem (i.e., time-stamping).

3) What kind of timeframe is the learning curve for GX Developer provided we take some training classes? Are we talking weeks, months, or years?

4) Are there any GX Developer users out there that are available on a contract basis to aid in the porting and to help get us over the learning curve?

5) Is there emulation software available for windows that would allow testing of the program as it is developed, or will the program need to be downloaded to a PLC and run?

Thanks in advance
John
 
Some answers

1. Yes. Most all PLC's have time clocks these days but they are standards time clocks. If you require millisecond resolution, you can use millisecond timers for that. There a many ways innovative programmers can do this sort of thing.

2. How long is a piece of string? There is very little in the way of physical I/O but it appears that there would be quite a bit of data to be accumulated in a usable manner and ported to the second CPU. This would entail a fair bit of work. I have not used Mitsubishi extensively for years and there are others around that would be better able to answer this.

3. Once again, how long is a piece of string? The basics are pretty simple but the Mitsubishi data areas are flexible and have to be set up as retentive and non-retentive, etc etc. I do not know about the latest processors but the last time I used Mitsubishi they did not even have a shift register and one had to make one using lots of shift bit left and right instructions. Length of time would be relevant to experience with other PLC software, applications, and the difficulties of the task at hand.

4. Cannot help there.

5. I purchased GX-Developer some time ago here in Australia and it came with a simulator. I had no need to use it so I do not know how good, or bad, it is.
 
The Q series PLC from Mitsubishi is ideal for this job. It's a piece of cake setting up multi CPUs.

But if you want to get 1 millisecond resolution use a high speed input card like the QI60 instead of the QX40-S1. This will allow you to select a sub-milisecond I/O response time.

Someone with knowledge of the Q series PLC could write and simulate the code you have described in one week. Double that value to be safe.

I managed to pick up the basics on this PLC pretty quickly after spending several years on other PLCs.

The main thing is to get access to all the relevant manuals (there are many many of them) and learn which manual to look in for information. Be patient, the answer is normally in a manual somewhere.

Try GX Simulator if you want to test some logic without the PLC hardware. But it would probably save you time in the long run if you could do your testing on real hardware.

Please post again, it sounds like an interesting project.

P.S. is it a Q02 (basic) or Q02H (high performance) CPU?
 
The application: Recognition of form (perimeter)and size of objects.
It confirms???


If the speed will go elevated. will have difficulty. The restraint is not the capacity of processing, but the quantity of signs captured can be prosecuted in assemblies, interelacions.

The problem, that for obtain an action, should relate the signs before with the subsequent, in this time does not produce results.

If possible in the machine, should position the groups of sensors in not multiple distances. It must, study details an attetion, as prosecute the signs,.

Case, contrary, obtain a delay acumulative by SCAN until lose the synchronization after hundreds of pieces OR peaks SCAN high time, and fail this moment.

Also important, it verify the combinations of distances between the pieces. They can produce the effects of the phrase above.
 
Thank you all for the replies.

Bob, I especially like the answer "how long is a piece of string?" I will be using this from now on :)

In talking with a friend of mine, he suggested a timestamping technique where the system clock could be copied to a data register and preform calculations with other such data registers. This sounds like what I am doing in my C code. What is the resoulution of the system clock?

Ushidayo
We chose the QX40-S1 based on the stated response time of 1ms and the number of channels. Is a QI61 an input module or some type of interrupt generating moudule?

The CPU is a Q02 basic. What are the advantages of the high speed version?

Thanks again for the responses. Every bit of information makes me feel a little more confident.

Frosty
 
Yes you're right, the input module (QI60) is a high speed interrupt module. Depending on the size of your program you might want your sensor inputs to "interrupt" the general program. It's a question of response time really. What sort of resolution in the timestamp is required? (milliseconds, tens of milliseconds, etc) If it's milliseconds, then you will need an input card that can respond in less than a millisecond.

The system clock only goes down to seconds, so you will need to use high speed timers instead.

Q02H (high high(?) performance version) has faster processing speed and bigger internal ram drive capacity. According to the latest documentation I've just seen, the Q02 is a high performance CPU. Which seems odd to me because all other high performance CPU's have an "H" after "Qxx". Sorry I'm babbling, the only difference between the two CPU's appears to be speed and RAM drive size.

regards

P.S. If you don't already have it, make sure you get this manual (QCPU User's Manual - Function Explanation, Program Fundamentals). The reference number is SH(NA)-080484ENG-A. This manual is the starting point for all other manuals for the Q series. PM me if you need a copy.
 
Wow, I've done something very similar to this. We where detecting pavers on a conveyor ... seperating and then stacking them.

Our questions are:

1) Can GX be used for the type of logic

You bet!

2) Approximately how long would it take to port the logic to a Q Series PLC using GX Developer?

40 hours (WAG)

3) What kind of timeframe is the learning curve for GX Developer provided we take some training classes? Are we talking weeks, months, or years?

Kill the classes... for the price, purchase a CPU and PLAY for 2 days.

4) Are there any GX Developer users out there that are available on a contract basis to aid in the porting and to help get us over the learning curve?

Yap! :cool:

5) Is there emulation software available for windows that would allow testing of the program as it is developed, or will the program need to be downloaded to a PLC and run?

There emulator is a piece of $hit. for the price, purchase a CPU and PLAY for 2 days.
 
I had a bit more time to think about your application (and read your original post more carefully).

It appears that the timestamping is used to determine some dimensions (or relative dimensions if speed is not know) of the object. I think that if the speed of the object varies while passing under the sensors, then you could get variation in the profile data.

Have you considered using an encoder? if an encoder was attached to the conveyor it would be possible to count the pulses then copy the current count value to the profile data address (A) when the sensor is on, and to profile data address (B) when the sensor goes off. Duration of sensor on could be evaluated as B - A, order in which sensors are turned on can also be identified by the pulse counts. It would be necessary to receive some sort of a signal when the object is about to come into range of the sensors so that the count could be reset. The encoder has the benefit of allowing the object to travel at a non-constant speed without losing accuracy of the profile data.

Obviously it is more expensive, but it might make the machine more flexible and bring increased accuracy. It all depends on what accuracy is actually required and the speed of the object I guess.

regards
 
The encoder is a good idea, except our client expects us to use the sensors already in place, so we have to work with what we have. The objects are in fact traveling at non determinate speeds which is one of the reasons we are profiling them.

Will I be able to use the encoder idea using a high speed timer (1ms) that increments a counter and then use the counter as my relative timestamp. As you posted, our logic timestamps the rising edge (A) and falling edge (B) and then records B-A as a sample. We store the last x samples in an array and then look for a specific pattern to decide which signals were garbage and which can be further processed.

>>Kill the classes... for the price, purchase a CPU and PLAY for 2 days.
We will be buying the equipment to develop on, so I guess I won't even look into the simulator. I will be taking some classes though. At this point I don't even know what I don't know about the Mitsu controllers, so if thats all that I get out of the class it will be money and time well spent. The rest I can find in the manuals.


Thanks again
Frosty
 
Counter for timestamp

Shame about the encoder (maybe on your next project, eh?).

If you need a timestamp down to milliseconds, then the maximum count value for a counter device (in PLC memory) might not be big enough. Incrementing a double integer would probably work better.

Also, this PLC can run a fixed scan "task" (scan time selectable), which should give you an accurate counter for your timestamp (and you wouldn't need a millisecond timer either). You could then put the timestamping in the fixed scan "task" and the array handling and handshaking with the other CPU in your main task (which will have a variable scan time).
 
Thanks for the ideas. Setting the scan time on a task by task basis was definetly one of the features I didn't know. That sounds like a perfect solution.

Now go get some sleep ushidayo :)

Frosty
 
why are you looking into milisecond range? how fast this has to be?
because if you need result every 1ms then you have to take a different approach and think of interrupts.
I ve done couple of jobs with Q02H and it's very nice PLC.
With pretty large program and all ladder scanned all the time,
servo motion, analog I/Os, two fieldbus networks, two Ethernet connection, two RS232 connections, three station poling,
lot's of continuous type of access to buffer of special cards,
lot's of math and more, scan time was around 3.8ms while online editing and 3.6ms without...
about the classes... I don't know how good are the guys who offer classes but I would also rather have PLC and spend two days trying things out. be prepared though to download and read some manuals so bookmark mitsubishi website and start downloading...
 
Last edited:
The reason for the 1 ms timestamping is accuracy. The objects that pass the sensor are about 7 inches wide and may be traveling as fast as 60 mph. 60 mph translates to 1.06 inches per msec. This means I will get 6 or 7 samples per object. any slower and the sample rate drops and profiling becomes less accurate.

I've written interrupt handlers in C, but never used them on a PLC. Do interrupt handlers on the PLC run outside the main scan loop? What is the possibility of re-entrance while processing interrupts, or are interrupts disabled while inside the handler?

Frosty
 
If your sensors were used as interrupts then you can only run an interrupt routine on either the on condition or off condition but not both. As you will be timestamping when the sensor goes on and off, I don't think it will be possible to use the sensors as interrupts.

(I am reading the manual as I'm writing this) I mentioned fixed scan tasks before, apparently there is also a function to run an interrupt program based on a high speed interrupt I49. This interrupt runs on a fixed cycle that can be set between 0.2 and 1.0 ms. This function has the bonus of refreshing I/O before and after the interrupt program runs. BUT this is only available on Q02H or higher CPUs, the Q02 can't do it. If you haven't ordered the CPU yet, then hold fire for a little while until you are sure what you want to do.

I'll try to send you a copy of the relevant manual when I can work out how to do it on this forum.

[Edit; the file is 17.7MB - too big to post in the download area. Send me a personal message with your email if you need it.

P.S. the manuals on www.meau.com are out of date

]
 
Last edited:

Similar Topics

The ladder logic changes I've made need to be reviewed. Is there a feature/function in GX developer for exporting code (i.e...
Replies
20
Views
4,879
Hello, I have a customer who has a Siemens step 5 PLC. He wants to upgrade the system to something else. Is there an easy way to save the step...
Replies
2
Views
4,199
Hi, I'am not used to RSlogix5000 so not sure if this is a dumb question. Is there an easy way of creating the tag names when i copy and paste...
Replies
2
Views
4,469
I've got some code running on a Compact Logix/Control Logix using CIP Generic Message instructions. Service Type is Custom Service Code is 45...
Replies
22
Views
5,674
Hi, Quick question. I have received a few .RP1 files and need to be able to open them. I have RS500 and RS5000, but not 5. Is there a way to...
Replies
3
Views
1,843
Back
Top Bottom