In SX Microcontrollers, SX/B Compiler and SX-Key Tool, g_daubach wrote: Hi jfischer, I have interfaced a quadrature encoder directly to an SX28 without external decoder/counter chip. If I read your specs correctly, the encoder will turn at a maximum of 300 RPM which is 5 revolutions/s. With a resolution of 1000 pulses/revolution, the pulse width is 200µs (I hope I did not mess up "revolution" and "resolution" :-) ). Considering an SX clocked at 50 MHz with an average execution speed of 50 MIPS, it should be possible to handle decoding, counting and comparing with the SX alone (no external components). It is important to note that port B of all SXes has an additional, so-called WKPNDB (wakeup pending) register. This register is not only useful for wakeup control but also for detecting pulses. Port B can be configured that either rising or falling edges occuring at port B pins set the associated bit in the WKPNDB register. In oder to detect the encoder pulses you would run within a fast loop. Instead of polling the pulse inputs directly, you would poll the status of the WKPNDB register instead. This makes sure that no pulses are lost which might be the case when polling the inputs at the "wrong time". Note that there is no instruction for reading the WKPNDB register. Instead, the following seqzence should be executed: mov M, #$09 ; Selects the WKPNDB register for subsequent mov !RB, w instructions mov w, #0 mov !RB, w The mov !RB, w instruction actually exchanges the contents of w and WKPNDB. After execution, w contains the status of the WKPNDB bits, and WKPNDB is cleared. As Bean noted, there must be a way to transfer some "preset count value" into the SX. One option would be using a serial protocol, either RS-232, SPI, or I²C. In my SX projects I normally use RS-232 or I²C. All three protocols can be handled by the SX just by software. One more question: Is it necessary to detect the direction of rotation? If not, the program could be a bit simpler but I don't see any problems handling both encoder outputs with the SX. BTW, your name sounds "pretty German". As I don't want to bother the forum by using German language here, please feel free sending me a private message in German - if you like. On the other hand, this is an intersting thread, so we should keep it alive here on the forum. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=85878#m85893 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)