In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Zoot wrote: RTCC interrupt rates are independent of system clock frequency; that presumes that the given clock is fast enough to let the interrupts run completely before the next one is called. No way 100_000 will run at 4mhz with this kind of code. I would run at 20MHZ or better yet 50MHZ (which is what it looks like you're doing). If debugging, make sure the Key is clocking at 50mhz. Second, and this prob. the cause of the problem -- you don't just want to wait for the ping response, you want to actually check that the ping line goes high THEN goes low, not just check for low. I am sure the ping will not respond in 10us after the trigger line goes low. The ping is programmed to *always* return some kind of high pulse, so you need to check for the edge before closing out the reading. Probably something like this: [code] ' ----- End Pulse USD ----- IF General_Var(1) = 3 THEN ' waiting for high pulse on ping to finish triggering the USD IF Tix >= 1 THEN ' 10us trigger LOW USD_Pin ' end pulse IF Tix >= 2 THEN ' wait for at least 10us low Tix = 0 ' clear the timer rawdata = 0 ' clear the last measured value INPUT USD_Pin ' make pin input General_Var(1) = 4 ' next state ENDIF ENDIF ENDIF ' ----- wait for pin to go high before waiting for sample ----- IF General_Var(1) = 4 THEN IF USD_Pin = 0 THEN 'still low Tix = 0 ' keep the counts cleared rawdata = 0 ELSE General_Var(1) = 5 'went high, wait and measure... ENDIF ENDIF ' ----- Measuring USD ----- IF General_Var(1) = 5 THEN ' measuring IF USD_Pin = 0 THEN ' Signal is high as long as no feedback. Once USD receives something, then signal goes low. ' wait for pulse to end. only if pulse has ended, procedures goes ahead, otherwise abortion here led2 = ison LOW USD_Pin ' pulse ended: turn pin off to keep trigger low Distance = rawdata ' move count to stable variable Tix = 0 ' clear the timer ' from now on I have 5ms until the next reading of the USD (set at 1*) IF Tix >= 4000 THEN General_Var(1) = 2 ' end this step, skip the index finding step and system check ENDIF ENDIF ENDIF [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=394074#m401105 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)