<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: 5V sensors with Maple analog input</title>
		<link>http://forums.leaflabs.com/topic.php?id=259</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:15:28 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=259" rel="self" type="application/rss+xml" />

		<item>
			<title>larryang on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-2135</link>
			<pubDate>Sun, 31 Oct 2010 22:20:45 +0000</pubDate>
			<dc:creator>larryang</dc:creator>
			<guid isPermaLink="false">2135@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Eh, where to start...  I'm a DSP programmer, so I'll give my perspective.  Instead of decimal, you have to think in binary.  You have to know a bit about the hardware, especially how the processor does arithmetic.&#60;/p&#62;
&#60;p&#62;Check out this useful Q notation:  &#60;a href=&#34;http://en.wikipedia.org/wiki/Q_(number_format)&#34; rel=&#34;nofollow&#34;&#62;http://en.wikipedia.org/wiki/Q_(number_format)&#60;/a&#62;.  In C code, I would keep everything straight via type names, such as uint32_q8.&#60;/p&#62;
&#60;p&#62;As for implementing delta_t = (1.121*(timeNew-timeOld))/2, regardless of Q format, this how I would do it, a fairly quick fashion.  Since 1.121 * 256 ~ 287, so (((timeNew-timeOld)* 287)/256)/2 which simplifies to ((timeNew-timeOld)* 1148)/512.  Compiler should take care of converting the divide to arithmetic right shift, but they don't always do that.&#60;/p&#62;
&#60;p&#62;This stuff isn't that portable, and you'll have to check for saturation/overflow.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-2039</link>
			<pubDate>Tue, 26 Oct 2010 14:48:25 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">2039@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;poslathian - should we break FixedPoint out into a new thread?&#60;/p&#62;
&#60;p&#62;In the meantime ...&#60;/p&#62;
&#60;p&#62;I think one FixedPoint32 class would be fine to start with, and we can flesh it out as we go.&#60;/p&#62;
&#60;p&#62;I am happy to start with a fixed 16.16 format, or a single common format for all instances of the Fixed32 class, to make it easy to get going.&#60;/p&#62;
&#60;p&#62;I do think that template classes are the 'right' final solution, but we might find one on the net we can use, and hence avoid ever having to do that ourselves :-)&#60;/p&#62;
&#60;p&#62;I would like operator overloading. I did a little bit of programming on PowerPC Macs using the AltiVec function wrappers, and it was pretty ugly.&#60;/p&#62;
&#60;p&#62;To start with, we probably only need a constructor, +, -, * and /, ==, &#38;lt;, &#38;gt;, (etc) and a way to get a text string representation of the number. &#60;/p&#62;
&#60;p&#62;I assume we are representing the number as an int32, and there are no virtual functions.&#60;/p&#62;
&#60;p&#62;Is this interesting as a project to other folks?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-2018</link>
			<pubDate>Mon, 25 Oct 2010 20:41:09 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">2018@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I agree with the no templates solution. The macro solution is good, In fact thats what ive been using, but it doesnt support operator overloading, since at the end of the day the type is still just a int32 or whatever. &#60;/p&#62;
&#60;p&#62;I was thinking we could use a single FixedPoint class, with the width and fractional/interger components as member variables. Give people three flavors, 16, 32, and 64 bit fixed point types, with any breakdown of fractional/integer parts they wish. Then overload the operators for that class. &#60;/p&#62;
&#60;p&#62;Templates do seem the natural and more efficient way to do it, since technically we are just building a polym. type but..ehh..no.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-2011</link>
			<pubDate>Mon, 25 Oct 2010 20:09:31 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">2011@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;poslathian - I was thinking of several levels of complexity.&#60;/p&#62;
&#60;p&#62;At the simplest, it is typedefs and some macros.&#60;/p&#62;
&#60;p&#62;Next up is operator overloading and some easy constructors, so one approach might be:&#60;br /&#62;
FixedPoint32 pi(8,24) = FixedPoint32Value(3,1415926);&#60;br /&#62;
FixedPoint32 radius(8,24) = FixedPoint32Value(1,4142);&#60;br /&#62;
FixedPoint32 area(8,24) = pi * radius * radius;&#60;br /&#62;
SerialUSB.print(area);&#60;/p&#62;
&#60;p&#62;but a way that seems to make more sense (though I do &#60;em&#62;NOT&#60;/em&#62; like C++ templates) might be:&#60;br /&#62;
FixedPoint32&#38;lt;8,24&#38;gt; pi(3,1415926);&#60;br /&#62;
FixedPoint32&#38;lt;8,24&#38;gt; radius(1,4142);&#60;br /&#62;
FixedPoint32&#38;lt;8,24&#38;gt; area = pi * radius * radius;&#60;br /&#62;
SerialUSB.print(area); &#60;/p&#62;
&#60;p&#62;The 'Rolls Royce' solution might be&#60;br /&#62;
Fixed&#38;lt;2,24&#38;gt; pi(3,1415926);&#60;br /&#62;
Fixed&#38;lt;1,37&#38;gt; radius(1,4142);&#60;br /&#62;
FixedPoint32&#38;lt;15,17&#38;gt; area = pi * radius * radius;&#60;/p&#62;
&#60;p&#62;I am happy to start off with something simple, and preferably already tested and working :-)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-2005</link>
			<pubDate>Mon, 25 Oct 2010 19:56:07 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">2005@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer, I've been using my own hacked together implementation, without any checking on overflow or other fancy features. I was thinking of something along the lines of &#60;/p&#62;
&#60;p&#62;FixedPoint32 x(16,16);&#60;br /&#62;
or&#60;br /&#62;
FixedPoint64 x(50,14); &#60;/p&#62;
&#60;p&#62;and the rest with operator overflow (so you can just do x*y) and no checking for value overflow. This is really just one class (wirish only, since its c++), and minimal adjustments to multiply and divide operations. &#60;/p&#62;
&#60;p&#62;What did you have in mind that was more complicated?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-1996</link>
			<pubDate>Mon, 25 Oct 2010 19:29:13 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">1996@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;poslathian - have you found a nice fixed point C++ class library that would run okay on Maple? It seems like such a well understood problem, but I haven't found a nice solution.&#60;/p&#62;
&#60;p&#62;If anyone has a nice library, I'd be interested.&#60;br /&#62;
My requirements:&#60;br /&#62;
1. Reasonably small, i.e. well under 10K for the core, and no huge bloat if its used in several source files&#60;br /&#62;
2. Reasonably quick. Within 50% of hand-coded fixed point would be good, but within 4x would be fine&#60;br /&#62;
3. Somewhat flexible in number range. I'd like to specify the number of digits (bits) in whole and fractional parts. I'd accept that the whole thing must fit in, e.g. a 32 bit int&#60;br /&#62;
4. robust - it doesn't silently blow up if there are errors&#60;br /&#62;
5. Easy to use - at worst it should have a well designed API, at best it might look well integrated into the language, using operator overloading and nice constructors&#60;br /&#62;
6. Debuggable - it must be possible to understand what is going on 'under the covers' so I can debug my code; this may be no more than some helper functions for print support.&#60;br /&#62;
7. Open Source&#60;/p&#62;
&#60;p&#62;Silntknight - specifying the N would be a nice option, but IMHO it'd be pretty good to be able to say the number of digits in the whole and fractional part, and let it get on with it :-)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-1995</link>
			<pubDate>Mon, 25 Oct 2010 19:28:46 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">1995@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Go with the 32 bits unless youre really tight on memory. All the operations happen 32 bits at a time anyway. &#60;/p&#62;
&#60;p&#62;You need to be careful that if youre using fixed point, your max number goes way down. For example if I have 256.0 * 256.0 in 16,16 fixed point then I end up with 65536.0, which is greater than 2^16-1, and so you have an overflow. &#60;/p&#62;
&#60;p&#62;Point being, even if all your numbers are under 1000, you still just overflowed a 32 bit number. &#60;/p&#62;
&#60;p&#62;The solution in the above case is either to avoid multiplying two &#34;big&#34; numbers (so that the result would be greater than 2^16 or whatever) or to use sacrifice some of your fractional bits (do 20 and 12 instead of 16 and 16...). Or, use floating point numbers, and all that that entails.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-1987</link>
			<pubDate>Mon, 25 Oct 2010 18:48:18 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">1987@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Poslathian, I think that is a good idea. I know the precision I need. What would be nice is if you could also specify the N bits, because I doubt I'd need all 32 (maybe only 16 or 24).
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-1985</link>
			<pubDate>Mon, 25 Oct 2010 18:25:33 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">1985@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer's recommended reading about floating point is seconded here. I avoid floating point whenever possible (read - when I roughly know the range of number I'll be dealing with)&#60;/p&#62;
&#60;p&#62;I usually use fixed point when I need fractional numbers. Ive been toying with the idea of using operator overflow in c++ to add fixed point support to libmaple. What do you think?&#60;/p&#62;
&#60;p&#62;for those of you curious, fixed point is a scheme is where you take an N bit number (say 32 bits) and you say the high j (say 16) bits and make them integer bits, and the low k bits (say 16) and make them fractional bits. &#60;/p&#62;
&#60;p&#62;Then for a 32 bits number you have:&#60;br /&#62;
x = num[31:16] + (1/2^16)*num[15:0]&#60;/p&#62;
&#60;p&#62;of course you dont have to do 16 and 16, you can get any precision you want. And note that the precision here is fixed at 1/2^16  ... hence fixed point. &#60;/p&#62;
&#60;p&#62;In this scheme adding and subtracting both occur in the normal way, and multiplying and dividing take one extra operation. For example&#60;/p&#62;
&#60;p&#62;x*y is actually (x*2^16)*(y*2^16)  so you have to then divide by 2^16 on your result
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-1984</link>
			<pubDate>Mon, 25 Oct 2010 18:23:30 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">1984@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;Is that what you mean?&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Yes. I wasn't sure if it used HTML formatting.&#60;/p&#62;
&#60;p&#62;First, let me start by saying that I actually find all this fun. I haven't had any formal education in programming (except HTML...) so, while it may be confusing, none of it is stuff I wouldn't be willing to try.&#60;/p&#62;
&#60;p&#62;On to the heart of the matter, I believe anything coming from millis() should be stored as a long. What I might do is break it down into multiple calculations. I would initialize timeNew and timeOld as long's, but their subtraction could easily be parsed as an int.&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;int delta_t = timeNew - timeOld;
delta_t = delta_t / 2;
float delta_time = 1.121 * delta_t;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Hopefully that code would give me a good balance between accuracy and speed. Only the last calculation would involve non-integers (obviously odd numbers divided by 2 give non-integers, but a half-millisecond error is acceptable). For the last calculation, should I have it something like:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;float c = 1.121;
float delta_time = delta_t * c;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;The previous also removes float division in exchange for integer division. Either way, even 50 clock cycles for all the math is fine.&#60;/p&#62;
&#60;p&#62;Long story short, I could use a float or recast everything in microseconds.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-1979</link>
			<pubDate>Mon, 25 Oct 2010 13:13:24 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">1979@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Another interesting paper on floating point &#60;a href=&#34;http://docs.sun.com/source/806-3568/ncg_goldberg.html&#34;&#62;What Every Computer Scientist Should Know About Floating-Point Arithmetic&#60;/a&#62; is worth a skim.&#60;/p&#62;
&#60;p&#62;It starts off with Rounding Error, so there isn't too much to read before some of the problems with the usual floating point representation becomes apparent.&#60;/p&#62;
&#60;p&#62;Please don't be scared away from using floating point. But please be aware that it is not as fool proof as it might appear.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-1975</link>
			<pubDate>Mon, 25 Oct 2010 11:01:33 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">1975@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;Also, I am not concerned with speed to the extent that I would sacrifice (much) accuracy.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Okay, I think I understand a bit better.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;What I am really asking for is the most accurate possible answer for the equation. ...&#60;br /&#62;
&#60;code&#62;delta_t = (1.121*(timeNew-timeOld))/2;&#60;/code&#62;&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Okay, &#60;code&#62;1.121&#60;/code&#62; can be stored as a float, or a double.&#60;/p&#62;
&#60;p&#62;The calculation as shown has only 3 decimal places, and 4 significant digits, which would fit into a float. How many digits are needed to store &#60;code&#62;timeNew&#60;/code&#62; and &#60;code&#62;timeOld&#60;/code&#62;?&#60;/p&#62;
&#60;p&#62;A &#60;code&#62;float&#60;/code&#62; uses 24 bits (23 bits and an implied extra bit, which is always 1) to store the number part (mantissa), so more than 7 significant decimal digits*. The rest is the exponent which says where the binary point is, and the sign.&#60;/p&#62;
&#60;p&#62;A &#60;code&#62;double&#60;/code&#62; uses 53 bits (52 and an implied 1) for the number. So oodles :-)&#60;/p&#62;
&#60;p&#62;BUT, remember that some rational numbers don't have precise representations in floating point format, for example 0.1, precision can be exceeded, so it isn't as ideal as it might seem.&#60;br /&#62;
See &#60;a href=&#34;http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems&#34;&#62;http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;If you wanted the arithmetic to faithfully carry all possible values within a known number of significant digits, and hence not lose any information, then it would need to be done using fixed point, and implemented as integers, or use a much better analysis of the calculation than I can give.&#60;/p&#62;
&#60;p&#62;So, if the calculation were done in units 10,000x bigger, it could all be integers. &#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;Also, should I do the divisions before, or leave the Maple to do it. I think I should leave the Maple to do it because 1 instruction will add 1/72 of a microsecond (double check my math) to the code and will leave it, hopefully, more accurate.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;I would try to write the code for the calculation in the way I understand, and if that has a divide, so be it.&#60;/p&#62;
&#60;p&#62;Having said that I should add that divide is one of the slowest arithmetic operations, and can take anything from 2 to 12 cycles, depending on the values involved, for an integer divide on a Cortex-M3. A floating point divide will be significantly slower.&#60;/p&#62;
&#60;p&#62;A divide by two shouldn't matter to the accuracy.&#60;/p&#62;
&#60;p&#62;But, try to do what you understand as you'll likely need to debug this.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;As far as recasting goes, all I am concerned about is accuracy, so if recasting it into integer operations would be more accurate, which I am hesitant to believe, I will do so.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Have a look at&#60;br /&#62;
&#60;a href=&#34;http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems&#34;&#62;http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems&#60;/a&#62;&#60;br /&#62;
and see how you feel about floating point vs fixed point integer.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;Quick aside, &#34;remembering&#34; that the value is 10000 times too large won't be useful because the computer needs it to process the value later. I might as well divide now.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;If all the math is recast to be in microseconds, or even 1/72,000,000 of a second (i.e. internal processor clock frequency), then the math will be as accurate as the machine can do, and the units will be those required to control the hardware at the greatest precision it can achieve.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;Thanks Gbulmer, you are *extraordinarily* helpful!&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Thank you very much for saying so. That is kind, generous and much appreciated.&#60;/p&#62;
&#60;p&#62;* I think I remember all the correct terminology :-)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-1972</link>
			<pubDate>Mon, 25 Oct 2010 09:40:06 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">1972@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Do you mean how do I get your text to look different?&#60;br /&#62;
I use blockquote, in an XML/HTML style, but I can't show exactly because it turns into a blockquote, so I will misspell and write &#34;blockpuote&#34;&#60;br /&#62;
&#38;lt;blockpuote&#38;gt;some text &#38;lt;/blockpuote&#38;gt;&#60;br /&#62;
turns into&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;some text &#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Is that what you mean?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Silntknight on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-1968</link>
			<pubDate>Sun, 24 Oct 2010 23:09:23 +0000</pubDate>
			<dc:creator>Silntknight</dc:creator>
			<guid isPermaLink="false">1968@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ok, so first, how do I use quotes (like you do, not these: &#34;)?&#60;/p&#62;
&#60;p&#62;Also, I am not concerned with speed to the extent that I would sacrifice (much) accuracy. I was just commenting on how I can rewrite the code accurately and make it faster.&#60;/p&#62;
&#60;p&#62;When I say &#34;store as a decimal,&#34; I mean store a number like 1.275. int would give me problems, but I know that double's can store data like that, at least in Java. Your explanation shows why. I guess I should say non-integers, because &#34;decimal&#34; has a specific denotation within computer terminology. What I am really asking for is the most accurate possible answer for the equation. Also, I realized the equation I gave earlier is incorrect. It should be&#60;br /&#62;
&#60;code&#62;delta_t = (1.121*(timeNew-timeOld))/2;&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;Also, should I do the divisions before, or leave the Maple to do it. I think I should leave the Maple to do it because 1 instruction will add 1/72 of a microsecond (double check my math) to the code and will leave it, hopefully, more accurate.&#60;/p&#62;
&#60;p&#62;As far as recasting goes, all I am concerned about is accuracy, so if recasting it into integer operations would be more accurate, which I am hesitant to believe, I will do so. I think that is there more for the purpose of speed. Quick aside, &#34;remembering&#34; that the value is 10000 times too large won't be useful because the computer needs it to process the value later. I might as well divide now.&#60;/p&#62;
&#60;p&#62;Thanks Gbulmer, you are *extraordinarily* helpful!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "5V sensors with Maple analog input"</title>
			<link>http://forums.leaflabs.com/topic.php?id=259&amp;page=2#post-1963</link>
			<pubDate>Sun, 24 Oct 2010 19:18:28 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">1963@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;... pressure sensor isn't linear over it's domain. It is only linear over .2V to 4.9V.
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Okay, I get it now.&#60;/p&#62;
&#60;p&#62;On Maple (ARM) an int is 32-bits, but people traditionally use specific types to force the size to be what they need, so int32 would be unambiguous.&#60;/p&#62;
&#60;p&#62;I don't use floating point arithmetic much, but it works. I just did a quick check, and the sizeof(float) is 4 bytes, and the sizeof(double) is 8. It's just slower than int's.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;... If I store it as a double, can I get decimals?&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Not sure what you mean. A double is &#60;em&#62;only&#60;/em&#62; a decimal part, it is represented in (the binary form of) scientific notation, e.g. 1.275 is stored as 0.1275 * 10^1 (but in binary)*.&#60;/p&#62;
&#60;p&#62;So yes, with some example numbers, and assuming timeNew and timeOld are unsigned long ...&#60;br /&#62;
double delta_t = 1.275*((timeNew-timeOld)/2);&#60;br /&#62;
               = 1.275 * ((300-199)/2);&#60;br /&#62;
               = 1.275 * (101/2);&#60;br /&#62;
               = 1.275 * (50);   // it is integer arithmetic&#60;br /&#62;
               = 63.75;&#60;/p&#62;
&#60;p&#62;I wouldn't worry about how fast the code goes until you get it giving the correct answers.&#60;br /&#62;
(I'd also suggest looking at Amdahl's Law.)&#60;/p&#62;
&#60;p&#62;That calculation can be recast as:&#60;br /&#62;
double delta_t = 1.275*((timeNew-timeOld)/2);&#60;br /&#62;
double delta_t = 0.6375*((timeNew-timeOld));&#60;br /&#62;
double delta_t = 6375*((timeNew-timeOld))/10000;&#60;br /&#62;
int delta_t = 6375*((timeNew-timeOld)); // and remember it is 10000 times too big&#60;/p&#62;
&#60;p&#62;Please try to avoid focusing on how fast it will go until it gives the correct answers because:&#60;br /&#62;
1. It is likely that it will be fast enough anyway,&#60;br /&#62;
2. It is always difficult to really know which part will be the slow part before it works&#60;br /&#62;
3. It might be impossible to make it fast enough, and that is hard to tell until it works&#60;/p&#62;
&#60;p&#62;As far as I can see, there isn't anything you have described which the Maple can't do easily, if approached in the right way. So get it working with the least amount of effort, and leave plenty of time to improve it if there are any problems.&#60;/p&#62;
&#60;p&#62;* actually it is sneakier than this, but this is a pretty good way to understand it.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
