In SX Microcontrollers, SX/B Compiler and SX-Key Tool, jmokie wrote: I have been fiddling with this problem for some time now without any success. Please let me tap into your knowledge to help me out. Problem: I have three optical sensors that I am trying to use for line following. I have successfully connected them as a/d inputs to the SX28. The outputs seem to have a reasonable relationship to the manufacture's curves. I need to calculate max, min, and avg of each of the sensors in order to use their signals for PID control of the motors. 3 x 3 sensors = 9 variables. Now when I use my method of noise reduction by taking the avg of 5 readings, I need 3 word variables( X 5 bytes and then divide by 5.) so that takes another 6 bytes of variable space. I have reached the limit of variable memory space ( in order to do this, what with needing a few other variables for PVerror, Pulse widths, timers, etc. My variable list and the subroutine that I am using are listed below. I am a basic programmer and fairly new to SX28. Any suggestions? Jerry ----------------------------------------- LMax var byte LMin var byte LAvg var byte Left Sensor values Lf var word [for calculating avg] Lval var byte [raw value from sensor] ------------------------------------------ RMax var byte RMin var byte RAvg var byte Right sensor values Rt var word [for calculating avg] Rval var byte [raw value from sensor] ---------------------------------- Ctr var word [for calculating avg] CVal var byte [raw value from sensor] CMax var byte Center sensor CMin var byte CAvg var byte --------------------------------- timer var byte Snsrread: timer = 0 For timer = 0 to 5 ANALOGIN InCPin, OutCPin, Cval, 2 ANALOGIN InRPin, OutRPin, Rval, 2 ANALOGIN InLPin, OutLPin, Lval, 2 Ctr = Ctr + Cval Rt = Rt + Rval Lf = Lf + Lval next Ctr = Ctr/5 [calculate avg] '---------------------------Calculate Min, Max, Avg of Ctr \mov Cval, Ctr lsb [take the lsb to conserve on memory] If Cval < Cmin then Cmin=Cval endif If Cval>CMax then CMax=Cval endif CAvg=CMax+CMin CAvg=Cavg/2 ------------------------------------ Rt = Rt/5 \mov Rval, Rt lsb [same routine on each input] If Rval < Rmin then Rmin=Rval endif If Rval>RMax then RMax=Rval endif RAvg=RMax+RMin Ravg=Ravg/2 ------------------------------------------ Lf = Lf/5 \mov Lval, Lf lsb If Lval < Lmin then Lmin= Lval endif If Lval>LMax then LMax= Lval endif LAvg=LMax+LMin lAvg=Lavg/2 return ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=207973 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)