In SX Microcontrollers, SX/B Compiler and SX-Key Tool, rwatts wrote: The ISR should control the servo without a problem. However, the COUNT function will not be precise for two reasons: 1) Time spent in the ISR does not count against your 1000 msecs timing interval. In your case the ISR time will vary with the width of the servo pulse. Worst case, on average around 4% of your time will be in the ISR, so this probably isn't a concern here. 2) If a magneto pulse happens during a servo pulse, it won't get counted. The COUNT function can't register a pulse unless it (and not the ISR) is running when the pulse happens. Since the magneto pulses can be shorter than the servo pulses, this is a definite possibility. Again, you may be able to convince yourself that missing a few pulses won't be a problem for this project. If you decide you need to, you can solve both of these problems by coding the pulse counter yourself. You could add code to the ISR to set a bit flag once per second (every 200 executions of the ISR). WKPND_B.4 will be set every time there is a magneto pulse, independent of what code is running. You just have to clear it before the next pulse comes along. Create a loop that checks and clears WPKND_B.4, increments the count when it's set, and loops until the 1 second flag is set. When that happens, clear the 1 second flag and save the count. There's a trick to using the WKPND_B register. WKPND_B = ByteVar will actually swap the value of ByteVar and the value of WKPND_B. So the the pulse counting code would be: CountRPMS: MagnetoPulses = 0 DO Temp = 0 WKPND_B = Temp 'Temp gets the value of WKPND_B and WKPND_B is cleared and ready for the next pulse IF Temp.4 = 1 THEN INC MagnetoPulses ENDIF LOOP UNTIL OneSecondFlag = 1 OneSecondFlag = 0 'Update ServoVal here GOTO CountRPMS By the way, you'll probably want to force ServoVal to stay between LowThrottle and HighThrottle. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=147881#m147926 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)