<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://hades.mech.northwestern.edu//index.php?action=history&amp;feed=atom&amp;title=Quadrature_decoding_in_software</id>
	<title>Quadrature decoding in software - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://hades.mech.northwestern.edu//index.php?action=history&amp;feed=atom&amp;title=Quadrature_decoding_in_software"/>
	<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Quadrature_decoding_in_software&amp;action=history"/>
	<updated>2026-05-16T09:53:48Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Quadrature_decoding_in_software&amp;diff=5675&amp;oldid=prev</id>
		<title>LIMS at 03:25, 26 December 2007</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Quadrature_decoding_in_software&amp;diff=5675&amp;oldid=prev"/>
		<updated>2007-12-26T03:25:42Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Optical and magnetic rotation encoders usually generate quadrature signals called A and B.   Read about quadrature, which allows clockwise and counterclockwise motion to be distinguished.   There are special chips that can count up and down according to quadrature A and B inputs.  There are even some PICs with quadrature inputs, but the 4520 isn&amp;#039;t one of them.&lt;br /&gt;
&lt;br /&gt;
QuadratureSoft.c uses software to decode and count A and B signals.   It can handle any number of encoders, but it is limited in the number of counts per second it can handle.  As written it runs at a 1KHz interrupt rate, and it is required that the A and B signals for one encoder change no more than once in 1mS.   If both A and B change in 1mS, the algorithm cannot determine if an up-count or a down-count has occurred.&lt;br /&gt;
&lt;br /&gt;
In understanding the algorithm, consider that for instance a high-to-low transition of A implies an up-count if B is high, but a down-count if B is low.   The algorithm works by assembling a 4-bit number consisting of the previous state of  A and B (1mS ago), and the present state.  The four bits form a number in the range 0 to 15.  For instance if A was previously high and B was low, and they are both unchanged now, the code is 1010 (binary), which is 10 (decimal).   The codes are translated to up-counts or down-counts (or neither) by being used as an index of the array DecoderLookup.&lt;br /&gt;
&lt;br /&gt;
If both A and B changed since 1mS ago (code 1001 for instance), then the encoder is moving too fast for the interrupt interval.  This is an error condition (&amp;quot;overrun&amp;quot;).  It is detected by the second part of the ISR, and a light is turned on to indicate the error.  Once it is determined that this does not happen in normal operating conditions, the error-checking part of the ISR can be removed.&lt;/div&gt;</summary>
		<author><name>LIMS</name></author>
	</entry>
</feed>