<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stack Overflow</title>
	<atom:link href="http://embeddedgurus.com/stack-overflow/feed/" rel="self" type="application/rss+xml" />
	<link>http://embeddedgurus.com/stack-overflow</link>
	<description>A Blog by Nigel Jones</description>
	<lastBuildDate>Fri, 05 Mar 2010 00:48:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Welcome to the new stack-overflow!</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/03/welcome-to-the-new-stack-overflow/</link>
		<comments>http://embeddedgurus.com/stack-overflow/2010/03/welcome-to-the-new-stack-overflow/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 13:19:13 +0000</pubDate>
		<dc:creator>Nigel Jones</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/stack-overflow/?p=178</guid>
		<description><![CDATA[Regular visitors will no doubt have noticed a rather dramatic change to the visual appearance of this blog. EmbeddedGurus has grown dramatically in the last year and so we&#8217;ve moved to a better platform (Wordpress) to manage the growth. Although the switch over from Blogger has been relatively painless, it&#8217;s still necessary for me to [...]]]></description>
			<content:encoded><![CDATA[<p>Regular visitors will no doubt have noticed a rather dramatic change to the visual appearance of this blog. EmbeddedGurus has grown dramatically in the last year and so we&#8217;ve moved to a better platform (Wordpress) to manage the growth. Although the switch over from Blogger has been relatively painless, it&#8217;s still necessary for me to manually check all my previous posts making sure they are right. I should have this done in the next few days at which point I will resume regular blogging.</p>
<p>If you&#8217;ve posted a comment to my blog in the last week or so it may not have made the transition &#8211; for which I apologize.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/stack-overflow/2010/03/welcome-to-the-new-stack-overflow/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>So you want to be an independent contractor?</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/so-you-want-to-be-an-independent-contractor/</link>
		<comments>http://embeddedgurus.com/stack-overflow/2010/02/so-you-want-to-be-an-independent-contractor/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 14:19:00 +0000</pubDate>
		<dc:creator>Nigel Jones</dc:creator>
				<category><![CDATA[Consulting]]></category>
		<category><![CDATA[Independent contractor]]></category>
		<category><![CDATA[tax code]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/19/so-you-want-to-be-an-independent-contractor/</guid>
		<description><![CDATA[Today&#8217;s post is motivated by the events that happened yesterday in Austin, Texas. For my overseas visitors, a software engineer, Joe Stack, decided to fly his light aircraft into an office building that housed the regional offices of the IRS (the American tax office). He created tremendous damage and likely murdered at least one person, [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s post is motivated by the <a href="http://www.cnn.com/2010/US/02/18/texas.plane.crash/index.html?hpt=T1">events </a>that happened yesterday in Austin, Texas. For my overseas visitors, a software engineer, Joe Stack, decided to fly his light aircraft into an office building that housed the regional offices of the IRS (the American tax office). He created tremendous damage and likely murdered at least one person, while killing himself. Notwithstanding that I <a href="http://www.embeddedgurus.net/stack-overflow/2009/12/terrorist-engineers.html">wrote </a>just a few weeks ago about the propensity for engineers to be involved in terrorist acts, what is relevant about this news item is that it appears that Joe Stack&#8217;s principal complaint concerned a portion of the<a href="http://taxfoundation.org/blog/show/25870.html"> US tax code</a> (via <a href="http://www.salon.com/news/joe_stack/index.html?story=/tech/htww/2010/02/18/joe_stack_s_tax_problem">Andrew Leonard</a>) that applies almost uniquely to consultants / independent contractors in the software / firmware field.</p>
<p>So while this isn&#8217;t a tax advice blog, I thought I&#8217;d weigh in on the issue, since it&#8217;s something that applies to me, and indeed anyone thinking of becoming a consultant / independent contractor in the USA.</p>
<p>The main issue revolves around who is an employee and who is an independent contractor. From a tax perspective this is an important distinction, because companies can avoid a lot of overhead by classifying employees as independent contractors. For example, employers avoid paying the employer contribution to social security, which for a typical engineer in the USA was around US$7000 per person in 2009. Instead the independent contractor is responsible for this payment. Conversely, independent contractors get some benefits that employees do not. For example an independent contractor can normally deduct from his taxable income the cost of travel to and from a client&#8217;s office.</p>
<p>Now whether one prefers employee or independent status is of course a matter of income levels and personal preference. However, what is crucial is that one not fall some where in the middle &#8211; because if you do you stand the risk of being re-classified by the IRS &#8211; at which point the tax bills can start getting very large for everyone involved. This falling in the middle tends to occur when someone is classified as an independent by the company &#8211; but acts like an employee. That is they work the same hours, and do the same work at the same time in the same location as someone who is an employee. If this describes you, or it describes a job that you are considering, then I suggest you read on.</p>
<p>Note that in the following, I have assumed that you want to be an independent contractor. If you are classified this way and instead want to be an employee, then do the opposite of what is advised!</p>
<p><strong>Time</strong><br />
An independent contractor must be free to set their own work hours. Although it is OK for an organization to say you can&#8217;t work, e.g. after 9 pm or before 6 am, it is not OK for them to specify your exact work hours. Furthermore, it is important that you exercise this right. For example if you are required to be on site 40 hours a week, then to preserve your independent contractor status it would be smart to work e.g. four 10 hour days, rather than the normal five 8 hour days. I also recommend that you strive to get the right to work from your home office for a certain percentage of the time. This helps establish your home office as a bona fide work place while simultaneously bolstering your independent status.</p>
<p><strong>Tools</strong><br />
An independent contractor is normally expected to provide their own tools. Now clearly you are unlikely to own a $25,000 spectrum analyzer. However as an independent contractor it is certainly reasonable that you provide your own computer and other tools such as compilers, email clients etc. The problem with this is that it often clashes with a companies IT policy. When this happens I strongly suggest that you sit down with the various parties (HR, IT, your recruiting manager etc) to address the issue. There are various options available, but the bottom line is you need to protect your status &#8211; and the company (if it&#8217;s on the ball) will want to do the same.</p>
<p><strong>Multiple Clients</strong><br />
The final way in which I handle this issue is by having multiple concurrent clients. This not only helps you meet the time requirement, but it also strongly reinforces the fact that you are free to work for whom you want, when you want &#8211; almost the definition of an independent contractor.</p>
<p>Well that&#8217;s my practical guide to not falling afoul of the IRS rules. Hopefully for those of you contemplating going into the consulting business you&#8217;ll have found it useful.</p>
<p>I&#8217;ll be returning to my more normal fare with my next post. As a heads up, embedded-gurus is undergoing a major face-lift over the next few weeks, which may impact not only my posting schedule, but also all the other bloggers here.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/stack-overflow/2010/02/so-you-want-to-be-an-independent-contractor/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Efficient C Tip #11 &#8211; Avoid passing parameters by using more small functions</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/efficient-c-tip-11-avoid-passing-parameters-by-using-more-small-functions/</link>
		<comments>http://embeddedgurus.com/stack-overflow/2010/02/efficient-c-tip-11-avoid-passing-parameters-by-using-more-small-functions/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 21:10:00 +0000</pubDate>
		<dc:creator>Nigel Jones</dc:creator>
				<category><![CDATA[Efficient C/C++]]></category>
		<category><![CDATA[parameter passing]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/06/efficient-c-tip-11-avoid-passing-parameters-by-using-more-small-functions/</guid>
		<description><![CDATA[This is the eleventh in a series of tips on writing efficient C for embedded systems. Today&#8217;s topic will, I suspect, be slightly controversial. This post is based upon two basic observations:

Passing parameters to functions is costly.
Conditional branch instructions can be very costly on CPUs that have instruction caches (even with branch prediction).

I don&#8217;t think [...]]]></description>
			<content:encoded><![CDATA[<p>This is the eleventh in a <a href="http://www.embeddedgurus.net/stack-overflow/2008/06/efficient-c-tips-1-choosing-correct.html">series</a> of tips on writing efficient C for embedded systems. Today&#8217;s topic will, I suspect, be slightly controversial. This post is based upon two basic observations:</p>
<ol>
<li>Passing parameters to functions is costly.</li>
<li>Conditional branch instructions can be very costly on CPUs that have instruction caches (even with branch prediction).</li>
</ol>
<p>I don&#8217;t think that too many people will disagree with me on the above. Despite this I too often see a style of coding that incurs these costs unnecessarily. I think it&#8217;s best illustrated by a (real world) example. The issue is one that will be familiar to most of you.  An embedded system contains a number of discrete LEDs (say 3), and the requirement is to write some code to allow higher level code to either turn on, turn off, or toggle a particular LED. The way I often see this coded is as follows:</p>
<p><code>typedef enum<br />
{<br />
LED1, LED2, LED3<br />
} LED_NO;</code></p>
<p><code>typedef enum<br />
{<br />
LED_OFF, LED_ON, LED_TOGGLE<br />
} LED_ACTION;</code></p>
<p><code>void led(LED_NO led_no, LED_ACTION led_action)<br />
{<br />
switch (led_no)<br />
{<br />
case LED1:<br />
switch (led_action)<br />
{<br />
case LED_OFF:<br />
PORTB_PORTB0 = 0;<br />
break;</code></p>
<p><code>case LED_ON:<br />
PORTB_PORTB0 = 1;<br />
break;</code></p>
<p><code>case LED_TOGGLE:<br />
PORTB_PORTB0 ^= 1;<br />
break;</code></p>
<p><code>default:<br />
break;<br />
}<br />
break;</code></p>
<p><code>case LED2:<br />
...<br />
}</code></p>
<p>So what&#8217;s wrong with this you ask? Well in a nutshell the parameters passed to the function are used strictly to control the order of execution. There is no code common to any pair or group of parameters. When faced with a situation such as this, I instead implement the code as a large number of very small functions. For example:<br />
<code><br />
void led1_Off(void)<br />
{<br />
PORTB_PORTB1 = 0;<br />
}</code></p>
<p><code>void led1_On(void)<br />
{<br />
PORTB_PORTB1 = 1;<br />
}</code></p>
<p><code>void led1_Toggle(void)<br />
{<br />
PORTB_PORTB1 ^= 1;<br />
}</code><br />
&#8230;</p>
<p>Let&#8217;s compare the two approaches.</p>
<h4>Efficiency</h4>
<p>This blog posting is supposedly about efficiency, so let&#8217;s start with the results. I coded these two approaches up together with a main() function that exercised all 9 possible combination&#8217;s. I then turned full speed optimization on and looked at the results for an AVR processor.</p>
<p>Single function approach: 78 bytes for main(), 94 bytes for the LED code. Execution time 208 cycles.</p>
<p>Multiple function approach: 42 bytes for main(), 54 bytes for the LED code. Execution time 96 cycles.</p>
<p>Clearly my approach is significantly more efficient.</p>
<h4>Usability</h4>
<p>By usability I&#8217;m referring to the case where someone else needs to use your code. They know they need to say toggle LED2 so they hunt around and find the file led.h. The question is, once they have opened up led.h, how quickly can they determine what they have to do in order to toggle LED2? In the single function case they are presented with just one function (which is a plus), but then they have to locate the enumerations and work out the parameters that need to be passed to the function (which is a minus). In the multiple function case, they have to search through a list of functions looking for the correct one. However once they have found it, it&#8217;s very clear what the function does.</p>
<p>For me, I think it is a toss up between the two approaches as to which is more usable.</p>
<h4>Maintainability</h4>
<p>In this case the multiple function approach is the big winner. To see how this is, consider what happens to the single function case when one adds an LED or adds an action. The single function case just explodes in size, whereas with the multi-function approach one simply adds more very simple functions.</p>
<h4>Conclusions</h4>
<p>If you buy my analysis then clearly the multi-function approach is superior in both efficiency and maintainability &#8211; two areas that are dear to my heart. Now granted this is a fairly extreme example. However in my experience if you look through a reasonable amount of code you will soon discover a function that essentially does one thing or another based upon a function parameter. When you locate such a function you might want to try breaking it into two functions in the manner described here &#8211; I think you&#8217;ll be pleased with the results.  <a href="http://www.embeddedgurus.net/stack-overflow/2009/07/efficient-c-tips-10-use-unsigned.html">Previous   Tip</a></p>
<p><a name="more"></a>****<br />
As the readership of this blog has grown I must say I have been really impressed with the many insightful comments that have been posted. I know I learn a lot from them, and so I suspect, do a lot of the other readers. Thus for those of you that have commented in the past &#8211; thank you. For those of you yet to post a comment, I encourage you to take the plunge!</p>
<p><a href="http://www.embeddedgurus.net/stack-overflow/">Home</a></p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/stack-overflow/2010/02/efficient-c-tip-11-avoid-passing-parameters-by-using-more-small-functions/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Is GCC a &#039;good&#039; compiler?</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/is-gcc-a-good-compiler/</link>
		<comments>http://embeddedgurus.com/stack-overflow/2010/02/is-gcc-a-good-compiler/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 02:20:00 +0000</pubDate>
		<dc:creator>Nigel Jones</dc:creator>
				<category><![CDATA[Compilers / Tools]]></category>
		<category><![CDATA[Compilers]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[IAR]]></category>
		<category><![CDATA[Keil]]></category>
		<category><![CDATA[Rowley]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/02/is-gcc-a-good-compiler/</guid>
		<description><![CDATA[It seems that barely a month goes by when I&#8217;m not asked my opinion on compilers. Sometimes I&#8217;m simply asked what compilers I use, while other times I&#8217;m asked my opinion on specific compilers &#8211; with GCC being by far the most asked about compiler. I&#8217;ve resisted writing about this topic because quite frankly it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>It seems that barely a month goes by when I&#8217;m not asked my opinion on compilers. Sometimes I&#8217;m simply asked what compilers I use, while other times I&#8217;m asked my opinion on specific compilers &#8211; with GCC being by far the most asked about compiler. I&#8217;ve resisted writing about this topic because quite frankly it&#8217;s the sort of topic that people get very passionate about &#8211; and by passionate I mean frothing at the mouth passionate. It seems that some folks simply can&#8217;t accept the fact that someone doesn&#8217;t agree with them that XYZ is simply the best compiler ever. Notwithstanding this, the volume of inquiries has reached the point where I really feel the need to break my silence.</p>
<p>First of all lets make some general observations.</p>
<ol>
<li>Despite the fact that I&#8217;ve been doing this for nearly 30 years and also despite the fact that as a consultant I probably use a wider variety of compilers than someone that works for an employer, the simple fact is that I&#8217;ve only had cause to use in anger a limited number of compilers. Thus are Rowley compilers any good? Well their website is decent, the documentation is OK and the IDE very nice. However I&#8217;ve never built a real project with their tools and so I really don&#8217;t know whether Rowley compilers are any good.</li>
<li>Many vendors provide compilers for many targets. As such it&#8217;s a good bet that if their 8051 compiler is very good, then their ARM compiler is also likely to be excellent. However it isn&#8217;t a given. Thus while I whole heartedly endorse the Keil 8051 compiler, I have no opinion on their ARM compiler.</li>
<li>Compilers vary in price from &#8216;free&#8217; to &#8216;cheap&#8217; to &#8216;expensive&#8217; to &#8216;they have got to be joking&#8217;. I&#8217;ve put all of these costs in quotes, because as you&#8217;ll see below, one&#8217;s perspective on what constitutes &#8216;free&#8217; or &#8216;expensive&#8217; is not easily defined.</li>
</ol>
<p>So, enough with the preamble. Lets start with the &#8216;free&#8217; and &#8216;cheap&#8217; compilers, including GCC. Well for me the bottom line (literally) is that I can&#8217;t afford to use these compilers. The reason is quite simple. I&#8217;m a high priced consultant. I can charge high hourly rates in part because I have exceptionally high productivity. Part of the way I achieve my high productivity is by not wasting my time (and hence my client&#8217;s money) on stupid issues unrelated to the problem at hand. Given that a compiler / linker is such a frequently used tool, and given that I&#8217;m also the sort of engineer who pushes his tools hard, it&#8217;s absolutely essential to me that when I run into a compiler issue I can pick up the phone and get an intelligent response ASAP. One simply can&#8217;t do that with &#8216;free&#8217; or &#8216;cheap&#8217; compilers, and thus too often one is reduced to browsing the Internet to find the solution to a problem. When this happens, then my &#8216;free&#8217; compiler rapidly starts to cost an arm and a leg.</p>
<p>What always amazes me about this topic is that so few employers / engineers seem to understand this. It seems that too many folks will eschew paying $2000 for a compiler &#8211; and then happily let their engineers bang their heads against a problem for a week &#8211; at a rate of at least $1000 a day.</p>
<p>Thus for me, the answer to the question &#8216;Is GCC a good compiler?&#8217; is &#8216;no, it isn&#8217;t&#8217;. Of course if you are a student, or indeed anyone who is cash poor and time rich, then by all means use GCC. I&#8217;m sure you&#8217;ll be very pleased with the results and that you&#8217;ll find it to be a good compiler for you.</p>
<p>What then of the &#8216;expensive&#8217; and they &#8216;have got to be joking&#8217; categories? Rather interestingly, although based on limited experience, I&#8217;ve found that the very expensive compiler vendors ($10K+) also have lousy support. Instead it&#8217;s the &#8216;expensive&#8217; vendors that actually seem to offer the best combination of functionality, code quality, support and price &#8211; and it&#8217;s this category that I tend to use the most.</p>
<p>Finally, regarding which compiler vendor I use. I happen to be a fan of IAR compilers. I&#8217;ve always found their code quality to be at least &#8216;good&#8217;. Their linker is probably the easiest and most powerful  linker I&#8217;ve ever used. Their support is very good (thanks Steve <img src='http://embeddedgurus.com/stack-overflow/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ). Finally their IDE is easy to use and has a very consistent look and feel across a wide range of processors, which is important to me as I tend to switch between architectures a lot.</p>
<p><a href="http://www.embeddedgurus.net/stack-overflow/">Home</a></p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/stack-overflow/2010/02/is-gcc-a-good-compiler/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Goto heresy</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/</link>
		<comments>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 11:17:00 +0000</pubDate>
		<dc:creator>Nigel Jones</dc:creator>
				<category><![CDATA[General C issues]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/02/01/goto-heresy/</guid>
		<description><![CDATA[Today&#8217;s post is prompted by an email I received from Michael Burns. With his permission I have reproduced his email below.
Hi Nigel,
What is your opinion on the usage of goto in C?
Sometimes when a routine has many conditions [usually for error handling] I have used a do {..} while(0); loop with breaks thus avoiding both [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s post is prompted by an email I received from Michael Burns. With his permission I have reproduced his email below.</p>
<blockquote><p>Hi Nigel,</p>
<p>What is your opinion on the usage of goto in C?</p>
<p>Sometimes when a routine has many conditions [usually for error handling] I have used a do {..} while(0); loop with breaks thus avoiding both deep nesting and repeated checks with a status variable.</p>
<p>For example:<br />
<code><br />
unsigned int XXX_ExampleRoutine (unsigned int XXX_instance, unsigned int *XXX_handle)<br />
{<br />
unsigned int status;</code></p>
<p><code>do<br />
{<br />
if (!XXX_IsValidXXXInstance (XXX_instance))<br />
{<br />
status = XXX_INVALID_INSTANCE;<br />
break;<br />
}</code></p>
<p><code>if (XXX_handle == NULL)<br />
{<br />
status = XXX_INVALID_ARGUMENT;<br />
break;<br />
}</code></p>
<p><code>status = XXX_AddRequest (XXX_instance, XXX_handle);<br />
if (status != XXX_STATUS_OK)<br />
{<br />
break;<br />
}</code></p>
<p><code>etc</code></p>
<p><code>} while (0);</code></p>
<p><code>return status;<br />
}</code></p>
<p>But perhaps the do {..} while(0); loop is just an excuse not to use goto?</p></blockquote>
<p>My (slightly edited) response to him was as follows:</p>
<blockquote><p>I rarely use a goto statement. While I dislike them for their potential abuse (for example a number of years ago I looked at a Flash driver from AMD that was absolutely littered with them), I also think they have their place.  Furthermore I think folks that scream ‘the goto statement is banned’ and then happily allow the use of ‘break’ and ‘continue’ are deluding themselves.</p>
<p>Turning to your example code. As you have pointed out, coding this without using ‘break’ or ‘goto’ can rapidly lead to code that is a nightmare to follow. Indeed once one gets beyond about four or five tests of the type you are performing, I’d say that the code becomes impossible to follow unless you use either the style you have espoused or a goto statement. I’d also make the case that in this situation a goto is actually better. To illustrate my point, I have modified your code slightly, in much the way someone might who wasn’t paying attention:<br />
<code><br />
unsigned int XXX_ExampleRoutine (unsigned int XXX_instance, unsigned int *XXX_handle)<br />
{<br />
unsigned int status;</code></p>
<p><code>do<br />
{<br />
if (!XXX_IsValidXXXInstance (XXX_instance))<br />
{<br />
status = XXX_INVALID_INSTANCE;<br />
break;<br />
}</code></p>
<p><code>if (XXX_handle == NULL)<br />
{<br />
status = XXX_INVALID_ARGUMENT;<br />
break;<br />
}</code></p>
<p><code>do<br />
{<br />
status = XXX_AddRequest (XXX_instance, XXX_handle);<br />
if (status == XXX_STATUS_BAD)<br />
{<br />
break;<br />
}<br />
} while (status == XXX_SOME_STATUS);</code></p>
<p><code>etc<br />
} while (0);</code></p>
<p><code>return status;<br />
}</code></p>
<p>In this case, the break wouldn’t work as desired, whereas if you had coded it with a goto, the code would still work as intended.</p>
<p>I guess the bottom line for me is that K&amp;R put a goto statement into the language for a reason (while leaving out lots of other features). Like just about everything else in C, the goto statement can be abused – but when applied intelligently it has its place.</p></blockquote>
<p>In his reply Michael commented that MISRA doesn&#8217;t allow goto or continue, and limits break statements to loop termination. I&#8217;ve already <a href="http://www.embeddedgurus.net/stack-overflow/2009/10/is-misra-compliance-worthwhile.html">posted </a>my comments on MISRA compliance &#8211; and I think my position here is consistent with what I wrote then &#8211; which in a nutshell is this. MISRA compliance is all well and good, but when it prevents you from implementing something in the most robust manner, then I think it&#8217;s incumbent upon one as a professional to do what is best rather than what has been mandated by a committee. If that includes using a goto, then so be it.</p>
<p><a href="http://www.embeddedgurus.net/stack-overflow/">Home </a></p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/stack-overflow/2010/02/goto-heresy/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Voltage gradients in embedded systems</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/01/voltage-gradients-in-embedded-systems/</link>
		<comments>http://embeddedgurus.com/stack-overflow/2010/01/voltage-gradients-in-embedded-systems/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 15:05:00 +0000</pubDate>
		<dc:creator>Nigel Jones</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[corrosion]]></category>
		<category><![CDATA[voltage gradient]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/01/24/voltage-gradients-in-embedded-systems/</guid>
		<description><![CDATA[Today&#8217;s&#8217; post was prompted by an excellent comment from Phil Ouellette in a recent newsletter from Jack Ganssle. In a nutshell Phil was advocating strobing switches with an alternating voltage waveform, rather than a direct voltage in order to minimize corrosion and premature switch failure. This happens to be an area in which I have [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s&#8217; post was prompted by an excellent comment from Phil Ouellette in a recent <a href="http://www.ganssle.com/tem/tem187.htm">newsletter </a>from Jack Ganssle. In a nutshell Phil was advocating strobing switches with an alternating voltage waveform, rather than a direct voltage in order to minimize corrosion and premature switch failure. This happens to be an area in which I have some experience and so I thought I&#8217;d extend the concept a little bit and also give you some food for thought.</p>
<p>The basic idea behind Phil Ouellette&#8217;s comments is that if one has a bias voltage between two pins (such as between switch contacts), and if this bias is always in one direction (i.e. DC), then the bias can act so as to drive an electrochemical reaction. The exact results of this electrochemical reaction vary (corrosion, dendrite growth etc.), but the net result is normally the same &#8211; namely an unwanted short circuit between two pins.</p>
<p>These problems arise particularly on products that have to operate in humid environments and / or products that have to spend a very long time under power over their expected operational life.</p>
<p>So what can be done about this? Well the most important thing to understand is that it is voltage gradient (volts per meter) that is the driving force in this problem and that furthermore, voltage gradient is a vector quantity and thus its direction is important. With this understanding, it should be clear that to minimize these types of problems, one has to minimize the integral of the voltage gradient over time. To do this one has three basic choices:</p>
<ol>
<li>Minimize the voltage</li>
<li>Maximize the separation</li>
<li>Modulate the voltage</li>
</ol>
<p>Let&#8217;s take a look at each of these in turn:</p>
<p><strong>Minimize the voltage</strong><br />
Clearly technology is progressing in the right direction for us here, as 5V systems are rapidly becoming extinct and 1.8V systems becoming more common place. Thus all other things being equal, the voltage gradient between any two pins on a 5V system will be 2.8 times greater than on a 1.8V system. Thus if you are designing a system where corrosion is a concern you will do yourself a big favor for opting for as low a voltage system as you can. However, see the caveat below.</p>
<p>Note also that given that what counts is minimizing the voltage over time, it follows that you can normally improve the system performance by powering down systems that are not needed at any given time. This also of course saves you power and thus is a highly recommended step.</p>
<p><strong>Maximize the separation</strong><br />
This is by far and away the toughest problem. Twenty years ago, ICs ran on 5V and had 0.1 inch lead spacing, giving a maximum voltage gradient between pins of 5 / 0.00254 = 1969 V/m. Today, a typical 1.8V IC has a lead spacing of 0.5 mm giving a maximum voltage gradient of 1.8 / 0.0005 = 3600 V/m. Thus the voltage gradient between pins on a typical IC has gone up &#8211; despite the decrease in the operating voltage. Thus if selecting a low voltage part means that you must use a fine lead pitch part, then you are almost certainly shooting yourself in the foot!</p>
<p>Other areas where you can increase separation without too much pain is in the selection of passive components. For example a 1206 resistor has a much lower voltage gradient than an 0402 resistor, and an axial leaded capacitor is usually preferable to a radially leaded device. As a result, when I&#8217;m designing systems that have potential corrosion issues I really prefer to use larger components. Of course this can put you into conflict with marketing and production.</p>
<p><strong>Modulate the voltage</strong><br />
The method suggested by Phil Ouellette is reasonably straightforward for something like a switch. However, if one generalizes the problem to all the components on the board, then it becomes a much more complex problem. For example, consider an address bus to an external memory. The most significant address lines will presumably change state at a much lower frequency than the low order address lines. Indeed it is not uncommon for a system that has booted up and is running normally to be in a situation where the top two or three address lines never change state. Now if they are all at the same state (for example high), then no voltage gradient exists between them and so there is no problem. However if the lines are say High &#8211; Low &#8211; High, then the voltage gradient is as bad as it gets &#8211; and you have a potential problem. There are of course various solutions to this particular problem. The easiest solution is to ensure that the most significant address lines are routed to non contiguous pins on the memory chip (sometimes known as address scrambling) so that high frequency address lines are adjacent to low frequency lines. A much more difficult problem is to link the application so that all address lines are guaranteed to toggle at a reasonable frequency&#8230;</p>
<p>Another interesting example comes when one performs microcontroller port pin assignment. Normally one has little choice about certain pin assignments &#8211; but for the remainder one has free rein. The next time you find yourself in this position you may want to try performing the assignment so as to minimize the voltage gradients. I think you will find it to be a very challenging task.</p>
<p>Anyway, I hope this has given you some food for thought. Please let us know via the comments section if you have faced any of these types of problems and how you solved them.</p>
<p><a href="http://www.embeddedgurus.net/stack-overflow/">Home</a></p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/stack-overflow/2010/01/voltage-gradients-in-embedded-systems/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A tutorial on lookup tables in C</title>
		<link>http://embeddedgurus.com/stack-overflow/2010/01/a-tutorial-on-lookup-tables-in-c/</link>
		<comments>http://embeddedgurus.com/stack-overflow/2010/01/a-tutorial-on-lookup-tables-in-c/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 13:00:00 +0000</pubDate>
		<dc:creator>Nigel Jones</dc:creator>
				<category><![CDATA[General C issues]]></category>
		<category><![CDATA[Lookup table]]></category>
		<category><![CDATA[LUT]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2010/01/11/a-tutorial-on-lookup-tables-in-c/</guid>
		<description><![CDATA[A while back I wrote a blog posting on using lookup tables as a means of writing efficient C. Since then, every day someone looking for basic information on lookup tables ends up on this blog &#8211; and I suspect goes away empty handed. To help make their visits a bit more fruitful I thought [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I wrote a blog posting on using <a href="http://www.embeddedgurus.net/stack-overflow/2009/05/efficient-c-tips-9-use-lookup-tables.html">lookup tables</a> as a means of writing efficient C. Since then, every day someone looking for basic information on lookup tables ends up on this blog &#8211; and I suspect goes away empty handed. To help make their visits a bit more fruitful I thought I&#8217;d offer some basic information on how best to implement look up tables in C. Given that this blog is about embedded systems, my answers are of course embedded systems centric.</p>
<p>So what is a lookup table? Well a lookup table is simply an initialized array that contains precalculated information. They are typically used to avoid performing complex (and hence time consuming) calculations. For example, it is well known that the speed of CRC calculations may be significantly increased by use of a lookup table. A suitable lookup table for computing the CRC used in SMBUS calculations is shown below. (Note that the SMBUS consortium refers to their CRC as a PEC)</p>
<p><code>uint8_t pec_Update(uint8_t pec)<br />
{<br />
static const __flash uint8_t lookup[256] =<br />
{<br />
0x00U, 0x07U, 0x0EU, 0x09U, 0x1CU, 0x1BU, 0x12U, 0x15U,<br />
0x38U, 0x3FU, 0x36U, 0x31U, 0x24U, 0x23U, 0x2AU, 0x2DU,<br />
0x70U, 0x77U, 0x7EU, 0x79U, 0x6CU, 0x6BU, 0x62U, 0x65U,<br />
0x48U, 0x4FU, 0x46U, 0x41U, 0x54U, 0x53U, 0x5AU, 0x5DU,<br />
0xE0U, 0xE7U, 0xEEU, 0xE9U, 0xFCU, 0xFBU, 0xF2U, 0xF5U,<br />
0xD8U, 0xDFU, 0xD6U, 0xD1U, 0xC4U, 0xC3U, 0xCAU, 0xCDU,<br />
0x90U, 0x97U, 0x9EU, 0x99U, 0x8CU, 0x8BU, 0x82U, 0x85U,<br />
0xA8U, 0xAFU, 0xA6U, 0xA1U, 0xB4U, 0xB3U, 0xBAU, 0xBDU,<br />
0xC7U, 0xC0U, 0xC9U, 0xCEU, 0xDBU, 0xDCU, 0xD5U, 0xD2U,<br />
0xFFU, 0xF8U, 0xF1U, 0xF6U, 0xE3U, 0xE4U, 0xEDU, 0xEAU,<br />
0xB7U, 0xB0U, 0xB9U, 0xBEU, 0xABU, 0xACU, 0xA5U, 0xA2U,<br />
0x8FU, 0x88U, 0x81U, 0x86U, 0x93U, 0x94U, 0x9DU, 0x9AU,<br />
0x27U, 0x20U, 0x29U, 0x2EU, 0x3BU, 0x3CU, 0x35U, 0x32U,<br />
0x1FU, 0x18U, 0x11U, 0x16U, 0x03U, 0x04U, 0x0DU, 0x0AU,<br />
0x57U, 0x50U, 0x59U, 0x5EU, 0x4BU, 0x4CU, 0x45U, 0x42U,<br />
0x6FU, 0x68U, 0x61U, 0x66U, 0x73U, 0x74U, 0x7DU, 0x7AU,<br />
0x89U, 0x8EU, 0x87U, 0x80U, 0x95U, 0x92U, 0x9BU, 0x9CU,<br />
0xB1U, 0xB6U, 0xBFU, 0xB8U, 0xADU, 0xAAU, 0xA3U, 0xA4U,<br />
0xF9U, 0xFEU, 0xF7U, 0xF0U, 0xE5U, 0xE2U, 0xEBU, 0xECU,<br />
0xC1U, 0xC6U, 0xCFU, 0xC8U, 0xDDU, 0xDAU, 0xD3U, 0xD4U,<br />
0x69U, 0x6EU, 0x67U, 0x60U, 0x75U, 0x72U, 0x7BU, 0x7CU,<br />
0x51U, 0x56U, 0x5FU, 0x58U, 0x4DU, 0x4AU, 0x43U, 0x44U,<br />
0x19U, 0x1EU, 0x17U, 0x10U, 0x05U, 0x02U, 0x0BU, 0x0CU,<br />
0x21U, 0x26U, 0x2FU, 0x28U, 0x3DU, 0x3AU, 0x33U, 0x34U,<br />
0x4EU, 0x49U, 0x40U, 0x47U, 0x52U, 0x55U, 0x5CU, 0x5BU,<br />
0x76U, 0x71U, 0x78U, 0x7FU, 0x6AU, 0x6DU, 0x64U, 0x63U,<br />
0x3EU, 0x39U, 0x30U, 0x37U, 0x22U, 0x25U, 0x2CU, 0x2BU,<br />
0x06U, 0x01U, 0x08U, 0x0FU, 0x1AU, 0x1DU, 0x14U, 0x13U,<br />
0xAEU, 0xA9U, 0xA0U, 0xA7U, 0xB2U, 0xB5U, 0xBCU, 0xBBU,<br />
0x96U, 0x91U, 0x98U, 0x9FU, 0x8AU, 0x8DU, 0x84U, 0x83U,<br />
0xDEU, 0xD9U, 0xD0U, 0xD7U, 0xC2U, 0xC5U, 0xCCU, 0xCBU,<br />
0xE6U, 0xE1U, 0xE8U, 0xEFU, 0xFAU, 0xFDU, 0xF4U, 0xF3U<br />
};<br />
pec = lookup[pec];<br />
return pec;<br />
}</code></p>
<p>There are several things to note about this declaration.</p>
<p><strong>The use of static</strong><br />
If static was omitted, then this table would be allocated and initialized on the stack every time the function is called. This is very slow (and hence self defeating) and will most likely lead to a stack overflow on smaller systems. As a result, a lookup table that is not declared static is almost certainly a mistake. The only exception that I am aware of to this rule is when the lookup table must be used by multiple modules- and hence must be declared so as to have global scope.</p>
<p><strong>The use of const</strong><br />
By definition a lookup table is used to read data. As a result, writing to a lookup table is almost always a mistake. (There are exceptions, but you really need to know what you are doing if you are dynamically altering lookup tables). Thus to help catch unintended writes to a lookup table, one should always declare the array as const.</p>
<p>Note that sometimes this superfluous if the array is forced into Flash, as described below.</p>
<p><strong>The use of __flash</strong><br />
If one provides no memory modifier (such as __flash) then many embedded systems compilers will copy the array into RAM (even though it is declared as const). Given that RAM is normally a much more precious resource than Flash, then this is a very bad thing. As a result, one should give a memory specifier such as __flash to force the array to be kept in Flash. Note that the syntax for doing so varies by compiler vendor. __flash is an IAR extension. I&#8217;ve also seen CODE (Keil) and ROM (Microchip) among others.</p>
<p><strong>The use of a size specific data type such as uint8_t</strong><br />
Almost by definition lookup tables can consume a lot of space. As a result it is very important that you be aware of exactly how much space is being consumed. The best way to do this is to use the <a href="http://www.embeddedgurus.net/stack-overflow/2008/06/efficient-c-tips-1-choosing-correct.html">C99 data types</a> so that you know for sure what the underlying storage unit is. As a result, if your data type is &#8216;int&#8217; then I&#8217;d suggest that you are doing yourself a disservice.</p>
<p><strong>Avoidance of incomplete array declarations </strong><br />
You should also note I have explicitly declared the array size as 256. I could of course have omitted this and had the declaration read as static const __flash uint8_t lookup[] = { &#8230;};<br />
However, I strongly recommend that you do not do this with lookup tables, as this is your first line of defense against inadvertently declaring the table with the wrong number of initializers.</p>
<p><strong>Range Checking</strong><br />
In this case, range checking of the array indexer is unnecessary as it is an 8-bit entity and the table is 256 bytes. Thus by definition it is not possible to index beyond the end of the array. However, in general one should always range check the indexer before performing the lookup. If you make your index variable <a href="http://www.embeddedgurus.net/stack-overflow/2009/07/efficient-c-tips-10-use-unsigned.html">unsigned </a>then you can make the check one-sided which aids in keeping the computation speed high. For example:</p>
<p><code>#define TABLE_SIZE (27u)</code></p>
<p><code>uint8_t lookup(uint8_t index)<br />
{<br />
uint16_t value;<br />
static const __flash uint16_t lookup[TABLE_SIZE] =<br />
{<br />
946u, 2786u, ... 89u<br />
};<br />
if (index &lt; TABLE_SIZE)<br />
{<br />
value = lookup[index];<br />
}<br />
else<br />
{<br />
//Handle error<br />
}<br />
...<br />
}</code></p>
<p><strong>Examples</strong><br />
So where do I use lookup tables? I&#8217;ve already mentioned CRC calculations as a common application. Probably my most common usage is for implementing jump tables. I wrote an extremely detailed <a href="http://www.rmbconsulting.us/jump-tables-via-function-pointer-arrays-in-cc">article</a> about this which I recommend you read if this is your interest. The third area where I often implement lookup tables is when I need to know the value of some complex function, where the independent variable has a limited set of values. To put this into plain English. If I have a typical 8 or 10 bit analog &#8211; digital &#8211; converter (ADC) and I need to compute say 6.5 * ln(X) where X is the ADC reading, then I&#8217;ll often just declare a lookup table that contains the values of 6.5 * ln(X) for all possible X (0 &#8211; 255 in the case of an 8 bit ADC). In this case all I need do is index the lookup table with the value of the ADC and I have my result. (The really observant reader will have noticed that 0 is an invalid input to the ln() function and so my previous statement is not entirely correct. Although this can be handled in several ways including range checking or the use of NaN (Not a Number),  I mention it so as to point out that lookup tables do not absolve you of taking care of corner conditions).</p>
<p>Once you get the hang of using lookup tables, particularly if you embrace the idea of <a href="http://www.embeddedgurus.net/stack-overflow/2009/05/efficient-c-tips-9-use-lookup-tables.html">very large lookup tables</a>, then you&#8217;ll quickly begin to wonder how you ever got along without them.</p>
<p>I&#8217;m sure that visitors to this blog would also appreciate hearing about other real world examples of the use of lookup tables &#8211; so feel free to tell the world about your experiences in the comments section.</p>
<p><a href="http://www.embeddedgurus.net/stack-overflow">Home</a></p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/stack-overflow/2010/01/a-tutorial-on-lookup-tables-in-c/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The best search terms of 2009</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/12/the-best-search-terms-of-2009/</link>
		<comments>http://embeddedgurus.com/stack-overflow/2009/12/the-best-search-terms-of-2009/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 18:00:00 +0000</pubDate>
		<dc:creator>Nigel Jones</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/12/31/the-best-search-terms-of-2009/</guid>
		<description><![CDATA[One of the interesting things about writing a blog is looking at the search terms that result in people visiting the blog. The vast majority of the search terms are quite reasonable. However, every once in a while a term pops up that brings a wry smile to my face. With that being said, I [...]]]></description>
			<content:encoded><![CDATA[<p>One of the interesting things about writing a blog is looking at the search terms that result in people visiting the blog. The vast majority of the search terms are quite reasonable. However, every once in a while a term pops up that brings a wry smile to my face. With that being said, I thought I&#8217;d share with you the &#8216;best&#8217; search terms of the year. The terms appear below, together with my take on them&#8230;</p>
<p><b>Stay away from embedded systems</b><br />What can I say? This just conjured up images of someone&#8217;s mother telling them that going into embedded systems would be the ruin of them. It certainly was for me.</p>
<p><b>Crazy enough to use unsigned</b><br />I guess I must be a raving lunatic then.</p>
<p><b>Clueless consultant</b><br />I winced when I saw this. I&#8217;ll just note for the record that at least it wasn&#8217;t paired with my name!</p>
<p><b>Personality as it relates to programming eprom</b><br />Huh?</p>
<p><b>Why is c so complicated?</b><br />A profound question indeed. So many responses came to mind, but at the end of the day none seemed adequate&#8230;</p>
<p><b>Should I correct grammer and spelling on my blog comments?</b><br />Not withstanding the irony that &#8216;grammar&#8217; is misspelled I found this to be an unintentionally revealing insight into the minds of those that blog!</p>
<p>With that I will say goodbye to 2009 and welcome to 2010. I hope 2010 is a better year for the industry as a whole and for my readers in particular. I&#8217;ll be back to my &#8216;regular&#8217; topics with my next posting. As always, thanks for reading.</p>
<p><a href="http://www.embeddedgurus.net/stack-overflow/">Home</a></p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/stack-overflow/2009/12/the-best-search-terms-of-2009/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Terrorist engineers</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/12/terrorist-engineers/</link>
		<comments>http://embeddedgurus.com/stack-overflow/2009/12/terrorist-engineers/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 13:11:00 +0000</pubDate>
		<dc:creator>Nigel Jones</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/12/30/terrorist-engineers/</guid>
		<description><![CDATA[From time to time I comment on things related to engineers (as opposed to engineering). This is one of those times!
Anyway as you may know, someone tried to blow an airliner out of the sky the other day. What you may not know is that once again the perpetrator was an engineer. I say &#8216;once [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time I comment on things related to engineers (as opposed to engineering). This is one of those times!</p>
<p>Anyway as you may know, someone tried to blow an airliner out of the sky the other day. What you may not know is that once again the perpetrator was an engineer. I say &#8216;once again&#8217; because as this <a href="http://www.newscientist.com/article/mg20227127.200-can-university-subjects-reveal-terrorists-in-the-making.html">opinion piece</a> in the New Scientist discusses, engineers are distressingly common in terrorist groups. Anyway, I suggest you read the article as it addresses some of the &#8216;obvious&#8217; reasons, while suggesting something insightful about engineers as a group. I also suggest you read the comments as many of them are very thought provoking.</p>
<p>My next posting will be a little more cheerful.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/stack-overflow/2009/12/terrorist-engineers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hardware costs versus development costs</title>
		<link>http://embeddedgurus.com/stack-overflow/2009/12/hardware-costs-versus-development-costs/</link>
		<comments>http://embeddedgurus.com/stack-overflow/2009/12/hardware-costs-versus-development-costs/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 23:16:00 +0000</pubDate>
		<dc:creator>Nigel Jones</dc:creator>
				<category><![CDATA[Consulting]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[AVR]]></category>
		<category><![CDATA[development costs]]></category>
		<category><![CDATA[PIC]]></category>

		<guid isPermaLink="false">http://www.gfcdev.org/test-stack/2009/12/24/hardware-costs-versus-development-costs/</guid>
		<description><![CDATA[Earlier this year I posted about how to solve the problem of PIC stack overflow. As part of that article I asked the question as to why does anybody use a PIC anyway when there are superior architectures such as the AVR available? Well, various people have linked to the posting and so I get [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier this year I posted about how to solve the problem of PIC <a href="http://www.embeddedgurus.net/stack-overflow/2009/04/pic-stack-overflow.html">stack overflow</a>. As part of that article I asked the question as to why does anybody use a PIC anyway when there are superior architectures such as the AVR available? Well, various people have linked to the posting and so I get a regular stream of visitors to it, some of whom weigh in on the topic. The other day, one visitor offered as a reason for using the PIC the fact that they are cheap. Is this the case I asked myself? So I did some rough comparisons of the AVR &amp; 8 bit PIC processors &#8211; and sure enough PIC processors are cheaper to buy. For example comparing the ATmega168P vs the PIC16F1936 (two roughly equivalent processors &#8211; the AVR has more memory and a lot more throughput, the PIC has more peripherals) I found that Digikey was selling the AVR for 2.60 per 980 and the PIC for $1.66 per 1600. A considerable difference &#8211; or is it?</p>
<p>Most of the products I work on have sales volumes of 1000 pieces a year, with a product life of 5 years. Thus if I chose the AVR for such a product, then my client would be paying approximately $1000 a year more for say 5 years. Applying a very modest 5% discount rate, this translates to a Net Present Value of $4,329.</p>
<p>This is when it gets interesting. Does the AVR&#8217;s architecture allow a programmer to be more productive? Well, clearly this is a somewhat subjective manner. However my sense is that the AVR does indeed allow greater programmer productivity. The reasons are as follows:</p>
<ol>
<li>The AVR&#8217;s architecture lends itself by design to being coded in a HLL. The PIC does not. As a result, programming the PIC in a HLL is always a challenge and one is far more likely to have to resort to assembly language &#8211; with the attendant drop in productivity.</li>
<li>The AVR&#8217;s inherent higher processing speed means that one has to be less concerned with fine tuning code in order to get the job done. Fine tuning code can be very time consuming.</li>
<li>The AVR&#8217;s greater code density means that one is less likely to be concerned with making the application fit in the available memory (something that can be extremely time consuming when things gets tight).</li>
<li>The AVR&#8217;s superior interrupt structure means that interrupt handling is far easier. Again interrupts are something that can consume inordinate amounts of time when things aren&#8217;t working.</li>
</ol>
<p>Now if one is a skilled PIC programmer and a novice on the AVR, then your experience will probably offset what I have postulated are inherent inefficiencies in the PIC architecture. However what about someone such as myself who is equally comfortable in both arenas? In this case the question becomes &#8211; how many more days will it take to code up the PIC versus the AVR and what do those days cost?</p>
<p>Of course if you are a salaried employee, then your salary is &#8216;hidden&#8217;. However when you are a consultant the cost of extra days is clearly visible to the client. In this case, if using an AVR reduces the number of development days by even a few, the cost difference between the two processors rapidly dwindles to nothing. Thus the bottom line is &#8211; I&#8217;m not sure that PICs are cheaper. However I suspect that in many organizations what counts is the BOM cost of a product &#8211; and perhaps this finally explains why PIC&#8217;s are more popular than AVR&#8217;s.</p>
<p>As always, I&#8217;m interested in your thoughts.<br />
<a href="http://www.embeddedgurus.net/stack-overflow/">Home</a></p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/stack-overflow/2009/12/hardware-costs-versus-development-costs/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
