TIA Portal convert Profinet Gray Code absolute encoder to revs and part rev

BryanG

Member
Join Date
Feb 2005
Location
Manchester
Posts
1,970
First time I have used an absolute encoder and it is definitelyo_O. I have a Siemens 6FX2001-5FN25 https://support.industry.siemens.co...pid=308011&mlfb=6FX2001-5FN25&mfn=ps&lc=en-CZ attached to a Siemens S7-1214 via Profinet. The encoder output is 27 bit, the right hand 13 bits give the angular position and the rest gives the number of turns. I could go through everything I have tried but the post would be very long, so probably simpler just to ask how to convert the encoder output to a value of 0-8191 for the angular position, and how to get the number of revs. Also if anybody can tell me where the heck I find the TIA equivalent of the Step 7 manual picture below I would be grateful, the encoder may be running backwards.

Encoder parameter.jpg
 
Are there no library blocks for the encoder ?

If not, after looking in the manual, I believe you have the variable G1_x, which is a 32-bit register, formatted as you describe.
Bits 0-12 are the position.
Bits 13-31 are the rev counter.

Use a mask (DW#16#1FFFF = 1111111111111 binary) to AND and copy the position to another DINT variable.

Use SHR (shift right) to push the bits to the right 13 places and copy to yet another DINT variable.

You have then split the position and rev counter into 2 variables.

* edited, due to I mistakenly thought it was 10 + 22 bits.
 
Last edited:
Hi Jesper, thanks for the reply. I am reading G1_XIST1 through telegram 860 which comes in to ID2 (Encoder) on the PLC as a double word, I seem to get data from the encoder OK.

The encoder gives out Gray Code and I found a download 109479728_LGF_LIB_TIAV14SP1_V4_0_2 for TIA 14 that includes a Gray Code to Binary converter. I declared my mask as 8191 which is the same as DW#16#1FFF though I have now tried your method. I have tried masking first and then converting, and also converting first and then masking. But I am not getting sensible decimal data, for example as I turn the encoder the data that should be decimal will move from 3857 to 4020 but then back to 3973.

Code:
//  Calculate the pipe OD from the encoder data
//  

#EncValMask := DW#16#1FFF;

"EncRevsTestMasked" := "Encoder" & #EncValMask;
"EncRevsTestToDec" := "LGF_GrayToBinary"("EncRevsTestMasked");
I am using M memory just for testing, "EncRevsTestMasked" and "EncRevsTestToDec" are both declared as DWord.
 
Your want the revs.
The revs is in bits 13-31. So if you use the mask, you get bits 0-12 which is wrong.
You don't need to mask, just use SHR to shift the bits as suggested. Shifting the bits will push the rev bits so they start from bit 0, and at the same time the position bits are discarded.

edit:
First shift to make the rev value start from bit 0.
Then convert from gray code to integer.

edit again:
In my 1st post, I didn't make it clear that the first suggestion (mask) would isolate the position bits.
And the second suggestion (shifting) would isolate the rev bits.
 
Last edited:
Further along than I was. I don't need to use the Gray Code converter, that was me not being able to see the trees because there was a forest in the way. So using the mask I get a value of between 0 and 8191, though for some reason the angle value increase as the rev count decreases, or the other way round, I can fix it by subtracting the output from 8191.

The Rev Counter isn't working as I would hope, it changes value part way through the 0-8191 sequence rather than at the start/end. Will have to work on that. Maybe this is normal for absolute encoders?

I did however find the Encoder Properties by right clicking on Module Access Point and selecting Properties.

Encoder Properties.jpg
 
I have reached the conclusion that the encoder is faulty. Picture below shows the value received from the encoder, surely that should be as straight a line as allowed by me turning the encoder and not a jagged like this.

Encoder Output.jpg
 
Show us your code.
edit:
And monitor the raw data from the encoder in a Watch table.
Display it as HEX and Binary.
Post a couple of screenshots with comments on what how the encoder has moved between the screenshots.
 
The above graph is the raw data from the encoder, I was slowly turning the encoder clockwise. Got a hospital appointment this afternoon, so will likely be tomorrow before I can post the other parts. Thanks again for the help.
 
I does nook like there is a jump for every time the encoder value drops by 8192, which corresponds with the position range for 1 revolution.
And then the greater part which should be the revs should also drop by 1.
But it looks like revs increases instead. So it does look very odd.
 
Thanks again for the interest and help.

I got in touch with Siemens tech support and they just sent me a copy of the Manual, which I guess is karmic revenge for the times I have posted FTFM. I emailed back explaining that I had already been reading the manual for two days and was still stuck.

Have you tried turning it CCW?
If you flip the chart left to right, that is what I get. The angle of rotation starts counting up, but the number of revs counts down.

Have you read this?
Did find that in one of my searches of the Siemens website, it was from 2015, and the encoder does sort of work.

But it looks like revs increases instead. So it does look very odd.
I am on shaky ground because I this is the first time I have used one of these, but 'very odd' covers what I think.

I will wait to see if tech support come back to me, and I will 'play' some more today.
 
Sorry I can't offer any more help, that result was stumbled upon when looking for the manual.

I haven't used a Siemens branded absolute encoder before. However the profinet ones I do use I just read directly the PIW or PID relevant. Never had to look into the "grey code"
 
Hey Jesper does the Bit trace below show what you want? Trace names are on the right of the trace. Encoder4(4) is bit 13 and the last of the standard bits, Encoder4(5) is the first of the rotation bits. I can see that Encoder4(5) and onwards have a different bit pattern to a standard binary output, I don't know enough to know if that is normal. If it is normal how the heck do I convert that to Revs?

Bit trace.jpg
 

Similar Topics

My PLC (S7-1200 with CPU-1212C) has now been delivered to customer site. They've asked me to do some updates to the software. I can do that on my...
Replies
21
Views
323
Does anyone know why the connection interface is greyed out and says why I can only use Teleservice instead of the other options like PN/IE? I am...
Replies
0
Views
44
Hi guys I after a bit of advice on Tia portal graphics, I would like to add a conveyor belt graphic to a hmi and the conveyor in the basic...
Replies
3
Views
130
Hi I used to be able to launch PLCsim without any problem. Now it tells me " STEP 7 Professional Licence is required to simulate this PLC"...
Replies
15
Views
452
Hi all Trying to remotely connect to a TIA Portal PLC. I can ping it without a problem but can't get my software to connect. I've opened port...
Replies
8
Views
279
Back
Top Bottom