Step 7 counter card turn over problem

Bratt

Lifetime Supporting Member
Join Date
Nov 2003
Location
West Sweden
Posts
726
I have a problem with a resolver connected to a ET200s counter module. I want to convert the value from the resolver to 0-->359 degrees and then start over. The axis can turn both backwards and forwards.

The following formula works the only problem is when the counter card hits the max value of +2147483647 its starts over and begins counting from -2147483648. The problem is that the value then reverses and begin counting backwards. The same goes when it hits min value -2147483648 then it starts over from +2147483647.

Anyone got any ideas?

Code:
      L     #Encoder.Feedback.Count_Val // Value from counter card
      L     L#1040                      // One turn on the resolver will give 1040 pulses
      /D    
      L     L#360    // Mod to get it to count from 0 to 359 and then start over
      MOD   
      T     #oVALUE  // Value 0 to 359
 
The following formula works the only problem is when the counter card hits the max value of +2147483647 its starts over and begins counting from -2147483648.
Not if you shift it right once before using the counter. Now all the numbers are positive but you gave away half your resolution.
What kind of encoder returns 1040 counts per revolution?
Usually there are so many bits per turn and an upper turn counter. You should have something like 10 bits per revolution or 1024 counts, not 1040.

Anyone got any ideas?
Many
 
Take advantage of signed integer math.

Every single scan:

Code:
Count_Delta = Current_Counter_Val - Last_Scan_Counter_Val

Last_Scan_Counter_Val = Current_Counter_Val

Encoder_Counts = Encoder_Counts + Count_Delta
 
If you are getting 1040 pulses per rev (odd number?) why not set the counter up in periodic counting mode rather than continuous count mode then angle becomes (count/1040)*360.

Nick
 
Code:
      L     #Encoder.Feedback.Count_Val // Value from counter card
      L     DW#16#7FFFFFFF     // Get rid of negative sign??
      AD
      L     L#1040      // One turn on the resolver will give 1040 pulses
      /D    
      L     L#360   // Mod to get it to count from 0 to 359 and then start over
      MOD   
      T     #oVALUE  // Value 0 to 359
But then again, would only work if the actual counts per revolution was 1024, which I thought was standard?
Would give you quite a few revs before it resets.

If the actual count is 1040 per 1°....well then you need to adjust your math a bit.

The part I added will get rid of the sign. (last time I checked it worked like that...)
 
Last edited:
Getting rid of the sign might work i just need to keep track of the boundaries and adjust the degree value when the boundaries get crossed. I'll give it a try
 
If you are getting 1040 pulses per rev (odd number?) why not set the counter up in periodic counting mode rather than continuous count mode then angle becomes (count/1040)*360.

Nick

I can only adjust the max value in periodic counting mode when counting either negative or positive not both or am i missing something?
 
Using a delta calculation (if this is a true, 32 bit signed counter) will also eliminate worrying about the sign.

Subtracting as I suggested will always give an appropriate value, and as a bonus, you never have to play with zeroing out a counter module, it's easy to pause, even easy to derive multiple virtual counters from.

To demonstrate with 8 bit signed math:
Code:
NEWCOUNT   OLDCOUNT   NEW-OLD (Delta)
25         15          10
127        126         1
-128       126         2
 
Using a delta calculation (if this is a true, 32 bit signed counter) will also eliminate worrying about the sign.
[/code]

(y)
Thank you!

I tried it seems to work for me. I'll try more tomorrow!
Seems like the best solution so far.
 

Similar Topics

can you help me with this one guys using fluid sim. This is for my bring home exam. providing a problem description, schematic...
Replies
5
Views
2,467
Hello Guys, I am new the forums ad well as a novice programmer/troubleshooter. My software is Siemens S-7 for a 300 PLC. My problem: Coding, I...
Replies
3
Views
1,699
I need to set a Z_RUECK counter using data from HMI: in particular, the ZW input must be set by user (this data is saved in DB7). What is the data...
Replies
2
Views
1,503
Hello I need to have a variable PV for a counter in Siemens Step 7. I need to fill in a variable such as C#5 as PV. Where 5 is the number of...
Replies
3
Views
5,378
I need to know how to use the Up/Down counter in Step 7 STL. Just need the basics IE: How to call to it in STL and how to increment/decrement...
Replies
8
Views
19,197
Back
Top Bottom