Jump to content

Need help with convert pulses to end value

Recommended Posts

Hello everyone. As first I will told, that my English is very bad,but I try to explain what I want to do.

I'm busy with project for my ham radio shack. I have samba 43 and visilogic program. My idea was make the logic controller for Antenna rotator, and relay to choice 1 of 6 antennas.

Relay is clear, also with HMI screen etc.

I have also clear the hmi for antenna rotate control.

But I have a problem with ladder program. I don't know witch function I need to use. Explain to idea and result.

I will rotate antenna on 360 degrees

I have diy rotator with DC motor, and gearbox 1:80. On the motor shaft is mounted metal star with 11 teeth and pulse sensor. With help of counter, for full rotate of gearbox(360dg) came 889 pulses to PLC.

Now is the question, which function I need to use that my PLC know where is antenna? Hi must convert the pulses for degrees. 

I try few functions but never good result.

I use the power up bit to set antenna to home,always CCW, when antenna is at 0dg(home switch) then output ccw go reset. 

On hmi I will use variable to set the azimuth from 0 to 359 degrees(target).

I'm not professional programmer, only for my own projects, if you want to help me, which functions I need to use, I be very grateful.

If I see good convert result, than I can further with A<B functions.

Greetings! Damian



Link to comment
Share on other sites

  • Damianq changed the title to Need help with convert pulses to end value

So, then I think good, but had problem with put the values in linearization. 

Yes, rotator can be used cw and ccw. 

With quadrature encoder in setup, you mean setup in HSC? (Shaft encoder x4 or x2)?

Sorry for my maby stupid questions but this is really new for me. All what I can, I make with help of unitronics example projects or YouTube, or help file from unitronics. Thx in advance!

Link to comment
Share on other sites

  • MVP 2023
19 minutes ago, Damianq said:

With quadrature encoder in setup, you mean setup in HSC? (Shaft encoder x4 or x2)?

You must have both - quadrature enoder on the shaft (+24 V PNP type with A, B signal)  and Shaft encoder x2 or x4 in HW configuration (A,B encoder wire  connected to I0,I1 HS input).

And Zero sensor for antenna homing.

You can save antena position (encoder count) via ladder and do not need for homing every Power ON.

Link to comment
Share on other sites

This work! Only one question yet. Because I think you don't understand me correctly. For counting pulses, I use contact less switch. Connected to I4 in my PLC. I use counter INC. This is what you say earlier, counting work only for CW en work perfectly. Now I will use, with the same input I4 for counter DEC when antenna rotate to CCW. I see that doesn't work. I will the inc and dec activate with AND (Counter Inc active with output CW and dec active with output CCW.) But if I will set parameters in AND, I can't set Input or Output to activate inc or dec. How I can make this? I think I really complicated the project because I don't know every function of this big PLC machine.  For me is this a bit black magic. Big respect for professional programmer's! 

If this is helpfull I can also upload here my project, but you sure go laughing 😃 

Link to comment
Share on other sites

  • MVP 2023
5 minutes ago, Damianq said:

If this is helpfull I can also upload here my project, but you sure go laughing 😃 

All off Unitronics forum user start from the first project. It is OK to make mistakes.

Like you, I once tried to build a reversible pulse counter with one sensor. Due to the imperfection of the mechanics and the inaccuracy of the sensor installation, pulses were lost and the calculation was not stable. That is why I asked if you will reverse your engine.

P.S. In Visilogic Help Example projects present Function example V120 Step in Range function. It can be used for pulse count in both direction with defined range.

Maybe it can be useful for your application


Link to comment
Share on other sites

Thx. Yes, I must reverse the engine because coax cable can be damaged. What I see, with every rotate came always the same count of pulses. One idea what I have on this moment, is build in the second sensor, and this connected to Input 5, for counter of DEC. Voltage for Sensor CW take from output CW (if is active) then INC go high, and voltage for sensor CCW from CCW output, then DEC go high(physically lower) I know calculation can be not stable, but this is no important for this system(antena). Also if faulty is +/- 10 degrees, this really not problem. 

Of course I look to project step in range. Thank you very much, you help me very well! When the project is fully complete, I put that here.

Link to comment
Share on other sites

  • MVP 2023

Edit....the morning after writing this.  Despite noting that your motor has the 11 tooth chopper, I immediately jumped to my type of system where the chopper is on the final driven shaft/tower.  On waking this morning my brain immediately told me of this error.  So I've left this here, and if you can mount such a thing on the tower it would be useful.  Dan below is also writing along the same lines.

If your ON or OFF time of the sensor is long enough, you can get away with using a virtual position by stopping your motor at the middle of the longest transition.  Whichever one is the longest time period....ON or OFF.  This way you will keep your count.   But.....as Kratmel has already said, you also need an input that gives you a home point, but in my cases it is always a mid-point.  This can even be a simple microswitch, which you position so that your normal rotations trigger the switch during use, rather than deliberately running the antenna fully one way to home it.  So for CW you rotate to your desired point and stop the motor, with the rotation sensor not changing state, ie no further rotation possible to "jiggle" the sense.  CCW you do it all again but backwards.  The main thing is aiming to stop the sense in the very MIDDLE of the arc it is on or off the longest.  To do this you might have to add in a little timer to delay the stop slightly so that the exact middle is reached.  This will need a little trial and error on the timer to find the inertia of the entire drive system.   If your pulses are very short for both on and off this likely won't work, but it sounds like they will be long enough.

I have a few installs of my "toys" that use such a system, and invariably once it is set up correctly, I log readings and find that the mid-check is pretty much not needed after 1000 or so movements over 20 hours.  But being a midpoint is a good way to do things.  This of course also means that the thing that the contactless switch is reading has to be completely uniform.  Depending on the job, I would generate a chopper disc on my CAD that was then laser cut.  pic below..and the square was an enclosure on the end of a hollow shaft that then held the disc very accurately.  The sensor actually rotates around the shaft in my cases, the shafts are supports that hang from moving trolleys.  But the movement is the same as yours... slow rotation speed.

The KISS principle is the same the world over, complex control is sometimes not needed.  Other times, very annoyingly, it IS!

cheers, Aus


Link to comment
Share on other sites



Are you actually using a Quadrature  Encoder?   If so, then the Input  is on IN0  and 1  and set for a High speed Counter.

IF the sensor is the only thing sensing the target, then    you have to know that you are going  CW or CCW - you need these signals 

    To  Count up  --              CW Signal + Target Signal   = Increment Pulses

    To  Count Down  --  CCW Signal + Target Signal   =  Decrement Pulses 

  The   Home prosition sensor can be center   and reset the counter to keep it in synch  as the antenna rotates thru this position.

I  have an Amatuer Radio License, but not a tower, but this is kinda the approach I would take :

        Sensors -   Sense the gear or position of the Rotor shaft.

                           -   Center position

                            - Possible   sensor at each end of the rotor travel  as limit sensing with Auto  Stop of motion  when reached - regardless of the Count.

                           - Linearization to convert  Pulse count to Degrees,   

                          -- Have  0  degrees at the center home position and go   + 180 and  -180  from Home 

           I would shy away from using an encoder - expense, coupling the encoder and weatherproofing since it will be outdoors.

Post your program.

I did a CAT program using a Unitronics PLC  to control a transceiver.




Link to comment
Share on other sites

  • MVP 2023

In this setup (Samba+rotation gearmotor) present another one solution for positioning with absolute readout

WDD35D-1 -4 precision conductive plastic potentiometer angle sensor 10K

Product name: precision conductive plastic potentiometer
Resistance: 1K2K5K10K
Shaft length: short shaft 19mm long shaft 33mm
Linearity: ±0.1%~0.5%
Mechanical rotation angle: 360° continuous)
Theoretical electrical angle: 345 plus or minus 2 degrees


This potentiometer angle sensor can be installed on the main shaft and connected to Samba analog input (some 24 to 10V DC/DC converter neded).

No homing needed. Position is present directly after power ON. 0-10V signal can be converted to 0-360deg.


Another simple solution...

Use 10k multiturn potentiometer - no DC/DC needed - only one time calibrate 0 position and use Linearization function.    Note - output voltage must be in range 0-10V.


This  solution can be programmed via ladder and some fixed position can be implemented without problems.

Link to comment
Share on other sites

  • MVP 2023

Amateur radio people are notoriously creative with the most hacked-up parts.  My call sign is KEØZCM.

If you rolled your own rotator assembly you may be able to roll your own quadrature encoder by adding a second sensor.  I have actually done that on a machine using photo sensors, but if you have a tooth sensor that will work, too.

The trick it to place the sensors so the pulse trains are 90 degrees out of phase as the gear rotates:


The sensors don't have to be right next to each other as long as you can get the offset waveform shown above.  Then you can use the Samba's encoder function.


There's lots of ways to skin this cat.

Joe T.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...