In SX Microcontrollers, SX/B Compiler and SX-Key Tool, g_daubach wrote: Eric, I noticed that you are clocking the SX with 4 MHz, so the ISR will be invoked every 64 µs, as you have mentioned in the title comment. Generally speaking, you can have serveral virtual peripherals handled by one ISR, like reading the encoders, and handling serial communication. The important point is that timing-critical routines, like the handlers for serial communications need to be called at a constant rate. Otherwise, you would have jitter on the transmit serial signal, and maybe, the receiver might read false input data. To make sure that timing is correct, any ISR code that is executed before the timing-critical routines must take the same amount of clock cycles to execute whenever the ISR is invoked. In your sample code, this is not the case, as the IF tmp81.3 THEN, and the IF tmp81.1 THEN blocks are obviously not executed on each ISR invocation. To achieve a constant execution time, you might consider using IF...ELSE...ENDIF blocks, and place some dummy code in the ELSE part with the same executi on Besides this, for serial communications routines, an ISR timing must be selected that matches one of the standard baud rates. For example, at 9600 Baud, one bit takes 104.17 µs. As the receiver must detect the start bit, and then delay 1.5 bits to "center" on the first data bit, the ISR must be invoked every 52.083 µs, or approximately every 208th system clock cycles. This does result in 9615 Baud which is close enough to 9600. So, instead of using RETURNINT, you would have to use RETURNINT 208. This also causes that your code to read the encoders is executed after a slightly shorter time period but I don't think that this is critical. Note that the SX/B SERIN and SEROUT commands don't use interrupts, and that their timing can be wrong when an ISR is active. So, when using SERIN ro SEROUT, you should disable RTCC interrupts before, and enable them again after the SERIN or SEROUT. On the other hand, this means that the encoders will not be scanned during this time. If this matters, the only chance is to use a piece of assembly code for the serial in and out routines, and place it inside the ISR as described above. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=150679#m152701 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)