News:

;) This forum is the property of Proton software developers

Main Menu

Quadratic encoder problem

Started by Parmin, Apr 12, 2021, 03:20 AM

Previous topic - Next topic

Parmin

#20
I thank those that sent example codes, but most examples are for steady movement, be it from a pulse generator or a motor that moves in predictable way, or in the last microchip example for an (I think) unmetered moves rather than fine control.

My codes have no problem in getting the pulses both clockwise or anticlockwise, even when it is moving fast (up to 50rpm or so).
Therefore so far the answers received do not actually point to a solution to my problem.

My problem is that somehow some of the pulse click is lost when the encoder is rotated with fast direction changes. 
I am quite sure there should be a solution because after all a dc servo motor uses quadrature encoder to hold the motor in position.
The difference is that between pulses quadrature encoder on motors would hold it's last state, whereas the handwheel encoder lost its state after a short period.
For example on a string of 00 01 11 10, and the pulse is stopped at say 01, or, 11, rather than continues the rest of the string (11 or 10) , it simply goes to 00 if the motion is stopped.
This might be the issue.

John Drew

Parmin, yes the last value can be saved, just need a bit more hardware. Big cap, another A/D input, maybe a resistor or two. Some experiments I did with a screwjack which has a simple set of points it started to lose calibration due to missed counts or contact bounce, can't remember which. For my application an absolute encoder was ideal.just more expensive. Horses for courses :)
John

RayEllam

My experience with shaft encoders is very limited but my observations are as follows.

1. Digital pot, a mechanical switch used for controlling volume levels, lcd menus etc. These all are low, varying RPM systems that use mechanical switches and thus suffer from switch bounce. Therefore you need an aggressive LPF on the switches to achieve any form of accuracy.

2. Feed back from servos. In industrial use these are normally optical/analog/hall effect  methods where switch bounce is non existent.

3. Feedback from stepper motors, well in most cases this is simply a micro switch at an index position, motor pulses are simply counted to obtain positional info with an infrequent return to index for recalibration.

The upshot is it depends on the use.

See_Mos

QuoteIn my code, I use INT interrupt pin to detect every rise of Signal A and read the state of Signal B when this occurs to determine the direction of the wheel spin.  I also use SWord for the location log to be able to record both positive and negative movements.

Parmin, you need to connect the encoder to PORTB 4 and 5 or 6 and 7 then use interrupt on change to detect both A and B rising or falling edges so that you catch all four possible states.

flosigud

My code above uses IOC. It increments or decrements a counter whenever a change occur.

Parmin

#25
Quote from: See_Mos on Apr 15, 2021, 04:15 PMParmin, you need to connect the encoder to PORTB 4 and 5 or 6 and 7 then use interrupt on change to detect both A and B rising or falling edges so that you catch all four possible states.
Yes mate
I have rewritten my code to use IOC and thus catching every different states.

Quote from: flosigud on Apr 15, 2021, 09:30 PMMy code above uses IOC. It increments or decrements a counter whenever a change occur.
My new design uses IOC too.

@RayEllam
If you follow the link on my original post you would see another type of encoder.
This one is optical based as well.


@John Drew
Yes it seems that I have to use Absolute encoder after all.

RayEllam

#26
Maybe this will help.

https://www.best-microcontroller-projects.com/rotary-encoder.html

One thing I did was to toggle a pin set as a D/O everytime the ISR was called and hooked a scope to it, this showed how horrendous the switch bounce was 🤣

Stephen Moss

#27
Quote from: Parmin on Apr 15, 2021, 08:27 AMFor example on a string of 00 01 11 10, and the pulse is stopped at say 01, or, 11, rather than continues the rest of the string (11 or 10) , it simply goes to 00 if the motion is stopped.
The output should not return to 00 if it stops rotating, it should still output the current 00, 01, 11, or 10 state until turned to a new position or the power is removed.
If it goes to 00 that suggests you have the version with open collector outputs and that you have not used any pull-up resistors to connect the A & B outputs to 5V (4K7 or 5K1 would do), if that is the case I am surprised you managed to register any counts at all.
Pull up resistors are needed whenever the output is Open collector, an alternative to using external pull up resistors is to use the week internal pull-up resistors of the PIC, but not all PICs have those and for those PICs that do have them they are usually only available on a limited number of pins. If they are available on the input pins you are using then you just need to set the appropriate register bits to enable them.

Parmin

@Stephen Moss
Yes the encoder is an Open Collector Output type.
And Yes I do put in pull-up resistors on the outputs.

This is the link to the "datasheet"
https://www.machinetoolproducts.com/content/Yumo/Yumo%20ISM8060%20Series%20Spec%20Sheet.jpg