In SX Microcontrollers, SX/B Compiler and SX-Key Tool, CraigJ wrote: I've been reading some threads here, and trying to figure out using the ISR for serial communications. I think I have it figured out, but I wanted to run my numbers to make sure I'm on the right track, as I've never had to code anything based on cycles or critical timing before, so hopefully my examples make sense. I'm using the external 4MHz resonator, as power consumption is a primary consideration. My understanding is that when sampling bits for serial communications an odd number should be used, though I've seen examples here using even that seem to work fine. So, if I want 19200 baud with 5x oversampling, The calculation is: 5 * 19_200 = ISR Rate of 96_000 per second. To figure out the amount of time I divide 1 / 96_000 = .00001041667 seconds meaning the ISR runs every 10.417 uS, but the amount of time the ISR takes to execute is determined by the code IN the ISR, right? Using a 4MHz clock, if the ISR executes 96_000 times per second this means that the total number of cycles that are available is 41.67 for code in the ISR plus any other code that needs to run outside the ISR, per ISR execution. So, if my calculations are accurate, for solid serial communications at 19_200 I'm assuming that 5x is more than sufficient. Generally speaking as the baud rate decreases can the sampling rate stay the same? If I find that I need more cycles would reducing the baud to 9600 and setting the ISR rate to 38_400 be adequate? Is there any recommend reading to help me get my head around this? I've been searching the forums and found some stuff, but I probably don't know what search terms to use. Thanks -Craig ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=296284 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)