In SX Microcontrollers, SX/B Compiler and SX-Key Tool, JonnyMac wrote: I think you're working too hard. You should start with a newer template and use 1.51.03 features; things like declared subroutines. And if your goal is to read a sensor several times and get the average reading, you can do it like this: [code]SUB ADC_IN FOR idx = 1 TO 4 ANALOGIN InCPin, OutCPin, ctrRaw, 2 ' get raw sensor value ctrRaw = ctrRaw >> 2 ' divide by 4 ctrAvg = ctrAg + ctrRaw NEXT ENDSUB[/code] The code above basically works like this routine, but without the extra accumulator variable: [code]SUB ADC_IN ctrAcc = 0 ' clear accumulator FOR idx = 1 TO 4 ANALOGIN InCPin, OutCPin, ctrRaw, 2 ' get raw sensor value ctrAcc = ctrAcc + ctrRaw NEXT ctrAvg = ctrAcc / 4 ENDSUB[/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=207973#m208105 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)