Hello All, I have an interesting question. The project is a robot arm in a closed loop app using a potentiometer connected to the arm. The motor is activated by an analog voltage input, which compares to the pot settings (and has specific hysteresis points in the code). The pot has a specific range defined in increments preset by the user within the AtoD range. I am trying to find a way in C (CCS) to fit variable, user-defined limits (LowLimit and HighLimit) within the preset analog to digital limits and reset the AtoD range to within the new user limits. The range on the AtoD is 0 to 5 volts, set up with Vref to 5 volts. The user defined limits are defined as : 0v < LowLimit < High Limit < 5v. The new range is found by : HighLimit - LowLimit = Range. The problem is: How do I divide in CCS C to find the new ratio? Normal float and long division will not provide a divisor that is usable for the steps within the ratio. I have read all the information about floats, atod calculations, etc. but I have not found any app such as this..... Pseudo Code long Range; // Pot values low to high long LowLimit; // Lower Pot value limit => 0 v long HighLimit; // Higher Pot value limit =< 5 v long increment; // New range of pot positions long PotPosition; // Measured input of pot position long MeasVal; // User input voltage 0 to 5 volts long PotVal ; // Pot Position measurement int input=0; // Analog measurement channel int pot=1; // Analog measurement channel MeasVal = measure_routine(input); // Get new input value to fit within range PotVal = measure_routine(pot); // Get pot value Range = HighLimit - LowLimit; // determines range of new limits increment = Range / 1023; // 0x3ff full range of atod gives new increment ***** Here is the issue, cannot find a way to do this and get a number that makes this work: PotPosition = MeasVal * increment; // Gives new position for the pot Code would then compare the analog voltage input to the PotPosition reading, then move the motor accordingly. The new limits correspond to the old zero and five volt limits, and have limits on how small the range can be before range becomes unusable. The issue remains: How do you calculate the new position within the new range? Any thoughts? Jack Wilker -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body