---- START NEW MESSAGE --- Received: from cherry.ease.lsoft.com [209.119.0.109] by dpmail10.doteasy.com with ESMTP (SMTPD32-8.05) id A432F9601CC; Wed, 28 Jan 2004 11:57:38 -0800 Received: from PEAR.EASE.LSOFT.COM (209.119.0.19) by cherry.ease.lsoft.com (LSMTP for Digital Unix v1.1b) with SMTP id <2.00CC15AA@cherry.ease.lsoft.com>; Wed, 28 Jan 2004 14:57:25 -0500 Received: from MITVMA.MIT.EDU by MITVMA.MIT.EDU (LISTSERV-TCP/IP release 1.8e) with spool id 5992 for PICLIST@MITVMA.MIT.EDU; Wed, 28 Jan 2004 14:57:16 -0500 Received: from MITVMA (NJE origin SMTP@MITVMA) by MITVMA.MIT.EDU (LMail V1.2d/1.8d) with BSMTP id 2267; Wed, 28 Jan 2004 14:55:40 -0500 Received: from lorre.umail.ucsb.edu [128.111.151.218] by mitvma.mit.edu (IBM VM SMTP Level 430) via TCP with ESMTP ; Wed, 28 Jan 2004 14:55:39 EST X-Comment: mitvma.mit.edu: Mail was sent by lorre.umail.ucsb.edu Received: from ip68-6-102-229.sb.sd.cox.net ([68.6.102.229] helo=Daniel) by lorre.umail.ucsb.edu with asmtp (Exim 4.24) id 1Alvml-00026o-T3 for PICLIST@MITVMA.MIT.EDU; Wed, 28 Jan 2004 11:55:39 -0800 References: <23075D38FE1C8144847DFAECA3565F270173E37C@pai-smx-01.europe.bkhm.net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanner: umail.ucsb.edu found no viruses in this message Message-ID: <00f801c3e5d8$c05a0ed0$1308a8c0@Daniel> Date: Wed, 28 Jan 2004 11:55:59 -0800 Reply-To: pic microcontroller discussion list Sender: pic microcontroller discussion list From: Daniel Imfeld Subject: Re: [PIC:]Another 16 bit maths question To: PICLIST@MITVMA.MIT.EDU Precedence: list X-RCPT-TO: Status: U X-UIDL: 371856153 ----- Original Message ----- From: "Michael Rigby-Jones" > >-----Original Message----- > >From: Daniel Imfeld > > >Subject: Re: [PIC:]Another 16 bit maths question > >The best way to do this (in code space, complexity, and > >running time) is to use fixed point math (integers) for the > >entire calculation. Simply use values ten times what they > >need to be, and make the correction in your head. > > > >This gives: angle = 892 - 2*count > > > >Just multiply count by 10 before putting it into the > >calculation. > > Fixed point math is definitely the way to go, but why would you multiply by > 10? A binary power allows all conversions to and from a fixed point format > to be performed using only shifts rather than multiplies. Getting the > fractional and integer parts is also trivialy easy. > > We need to know what kind of precision is required by the OP, and within > what range the count variable is to suggest how many fractional bits are > required. > > Assuming 4 bits is enough: > > Angle = (892 << 4) - (count << 5) > > This can calculated very quickly by the PIC. > > Regards > > Mike > I keep forgetting that the 16 series doesn't have a hardware multiply. But anyway, my reasons for the multiply by 10 are that given the equation, only one decimal place of precision is needed, as only one is possible in the answer. A multiply by 10 (or 20 in this case to incorporate the multiply by 2) eliminates the decimal place, making everything pure integers. The OP said count is a 10-bit integer, and angle is an integer, so any value of count*10 in the modified equation would produce a value with no decimal places. That said, I didn't know that it was that easy to convert to 2-power fixed-point format and back, so it probably is a better method, especially if not using a PIC18 series. Daniel Imfeld -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics .