> -----Original Message----- > From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf > Of cllow2020 > Sent: 04 December 2009 15:32 > To: Microcontroller discussion list - Public. > Subject: Re: [PIC] increase pic program flash memory size ? possible ? > > thanks jinx, > an0_value=(an0_value/10)*2441 / 1000 //: get back reading in mv range > an1_value=(an1_value/10)*2441 / 1000 > an2_value=(an2_value/10)*2441 / 1000 > an3_value=(an3_value/10)*2441 / 1000 > > an4_value=(an4_value/10)*2441 / 1000 *16 //: get back reading in mv > range > and 16x > an5_value=(an5_value/10)*2441 / 1000 *16 > an6_value=(an6_value/10)*2441 / 1000 *16 > an7_value=(an7_value/10)*2441 / 1000 *16 > -- You would probably save a useful amount of program memory if you can put the ADC values into an array and iterate through them in a loop rather than calculating each one explicitly. Also assuming you are using integers in the calculations you could save a little more memory and improve speed by scaling the constants to avoid the two divide/multiply operations e.g. an0_value=(an0_value/10)*2441 / 1000 can be reduced to an0_value=(an0_value * 125) / 512 and an4_value=(an4_value/10)*2441 / 1000 *16 can be reduced to an4_value=(an4_value * 125) / 8192 If your compiler is smart enough the divisions will be reduced to shift operations, or you could do them explicitly. These are not exactly equivalent; the scaling factor is 0.2441 in the original and 0.244140 in the optimised version, giving an error of 0.016% which is probably insignificant compared to component tolerances (scaling resistors and voltage reference for ADC. This gives a maximum error in the reported value of 1mv. Regards Mike ======================================================================= This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. ======================================================================= -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist