<?xml version="1.0"?><rss version="2.0">
<channel>
  <title>Alan&#039;s Ramblings - avr tag</title>
  <link>http://bleaklow.com:80/tags/avr/</link>
  <description>My opinions may be incorrect, but they are my own</description>
  <language>en</language>
  <copyright>Alan Burlison</copyright>
  <lastBuildDate>Wed, 23 Nov 2011 16:42:03 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  <image>
    <url>http://bleaklow.com/images/misc/logo.gif</url>
    <title>Alan&#039;s Ramblings</title>
    <link>http://bleaklow.com:80/</link>
  </image>
  <item>
    <title>A mention on the Pragmatic Programmer</title>
    <link>http://bleaklow.com:80/2011/05/08/a_mention_on_the_pragmatic_programmer.html</link>
    <description>
          &lt;p&gt;
I was looking at my &lt;a href=&#034;http://www.google.com/analytics/&#034;&gt;Google Analytics&lt;/a&gt; and noticed I was getting referrals from the &lt;a href=&#034;http://www.pragprog.com&#034;&gt;Pragmatic Programmer&lt;/a&gt; site, specifically from an article in the April magazine issue entitled &lt;a href=&#034;http://www.pragprog.com/magazines/2011-04/advanced-arduino-hacking&#034;&gt;Advanced Arduino Hacking&lt;/a&gt;.  Turns out they were using my &lt;a href=&#034;/files/2010/Makefile.master&#034;&gt;Makefile.master&lt;/a&gt; as the basis of their article, which describes how to use the Arduino platform without having to use the not-very-good Arduino IDE.  OK, I suppose that&#039;s a little unfair - the IDE is clearly meant for beginners but if you are an experienced developer or are working on more complex projects it becomes very limiting very quickly, as noted in the article.
&lt;/p&gt;
&lt;p&gt;
There are a &lt;a href=&#034;http://users.jyu.fi/~mweber/software/arduino/Makefile.master&#034;&gt;number&lt;/a&gt; &lt;a href=&#034;http://code.google.com/p/arduino/issues/attachmentText?id=344&amp;aid=7568997944726479287&amp;name=Makefile.master&amp;token=aabb0d45600455086e9b95b1f977f91a&#034;&gt;of&lt;/a&gt; copies of my Makefile.master floating around, but I&#039;m updating it fairly regularly, so I recommend you grab the &lt;a href=&#034;/files/2010/Makefile.master&#034;&gt;original version&lt;/a&gt;.  Compared to the version on the PragProg site, the current version (at time of writing) has the following improvements: 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The only really platform-specific parts of the Makefile are those that deal with running the serial monitor used to connect to the Arduino.  On Solaris I use &lt;a href=&#034;http://download.oracle.com/docs/cd/E19253-01/816-5165/6mbb0m9tt/index.html&#034;&gt;tip&lt;/a&gt; whereas on Linux you&#039;d probably want to use something such as &lt;a href=&#034;http://www.gnu.org/software/screen/&#034;&gt;screen&lt;/a&gt;.  I&#039;ve therefore added platform-specific sections to configure the serial monitor commands to the Makefile.master.  I don&#039;t currently have settings for MacOS, if someone wants to provide some suggestions, I&#039;ll add them in.&lt;/li&gt;
&lt;br/&gt;
&lt;li&gt;I hit a linker bug when using the &lt;a href=&#034;http://www.nongnu.org/avr-libc/user-manual/index.html&#034;&gt;avr-libc&lt;/a&gt; floating-point library, the workaround being to specify &lt;code&gt;-lm&lt;/code&gt; both first and last in the linker command-line arguments.&lt;/li&gt;
&lt;br/&gt;
&lt;li&gt;An optional &lt;code&gt;EXTRA_FLAGS&lt;/code&gt; macro that can be used to specify any additional flags that you want passed to gcc/g++.  I use this for enabling/disabling debugging, e.g. &lt;code&gt;EXTRA_FLAGS=-DDEBUG&lt;/code&gt; in my project Makefile.&lt;/li&gt;
&lt;br/&gt;
&lt;li&gt;The automatic tracking of &lt;code&gt;#include&lt;/code&gt; dependencies was being done via a separate invocation of the compiler, this has been collapsed into the main compilation step, thus halving the number of times the compiler is invoked.  If you don&#039;t know what automatic dependency checking is, there&#039;s a good explanation &lt;a href=&#034;http://mad-scientist.net/make/autodep.html&#034;&gt;here&lt;/a&gt; and also in the &lt;a href=&#034;http://www.gnu.org/software/make/manual/make.html#Automatic-Prerequisites&#034;&gt;GNU make&lt;/a&gt; documentation.&lt;/li&gt;
&lt;br/&gt;
&lt;li&gt;The generated dependency files are stored in the &lt;code&gt;build&lt;/code&gt; subdirectory of the project, but they do tend to clutter things up.  I&#039;ve therefore  moved them all into hidden (dot) files.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
One final note, the PragProg Makefile.master uses &lt;code&gt;stty -f $(PORT) hupcl&lt;/code&gt; to trigger a reset on the arduino before uploading the hex image to it.  Not only is that platform-specific, it&#039;s also unnecessary if you are using a recent-ish version of &lt;a href=&#034;http://www.nongnu.org/avrdude/&#034;&gt;avrdude&lt;/a&gt; which will do the reset for you if you specify a programmer type of &lt;code&gt;arduino&lt;/code&gt; rather than &lt;code&gt;stk500&lt;/code&gt;.
&lt;/p&gt;</description>
      <category>Arduino</category>
    <category>Tech</category>
    <comments>http://bleaklow.com:80/2011/05/08/a_mention_on_the_pragmatic_programmer.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2011/05/08/a_mention_on_the_pragmatic_programmer.html</guid>
    <pubDate>Sun, 08 May 2011 14:01:41 GMT</pubDate>
  </item>
  <item>
    <title>ATMega registers and memory ranges</title>
    <link>http://bleaklow.com:80/2011/04/10/atmega_registers_and_memory_ranges.html</link>
    <description>
          &lt;p&gt;
The AVR family has a reasonably complex register and memory architecture, with:
&lt;ul&gt;
&lt;li&gt;Multiple address spaces&lt;/li&gt;
&lt;li&gt;Registers that can be accessed directly and via the memory address space&lt;/li&gt;
&lt;li&gt;Register pairs that are used as memory indexes&lt;/li&gt;
&lt;li&gt;Restrictions on which registers can be loaded directly with constant values&lt;/li&gt;
&lt;li&gt;Some IO ports that appear in both the memory and IO address spaces, but with different addresses in each&lt;/li&gt;
&lt;li&gt;Some IO ports that are only accessible via the memory address space&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;p&gt;
In addition, the gcc compiler has conventions governing which registers it uses for what purpose, for example:
&lt;/p&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;Which registers it uses for purposes such as storing temporary values and zero&lt;/li&gt;
&lt;li&gt;Which registers it uses for passing and returning arguments&lt;/li&gt; 
&lt;li&gt;Which registers it uses as a stack frame pointer&lt;/li&gt;
&lt;li&gt;Which registers are saved by the caller on entry to a subroutine and which ones have to be saved by the callee&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;p&gt;
When I&#039;m reading the assembler output of gcc I find it helpful to have a table to remind me which registers are being used for what, and why.  The information is not exactly well-explained in the AVR documentation and I&#039;ve not been able to find all the information in once place on the Internet, so I&#039;ve drawn up the following quick-reference table to remind me of what goes where:
&lt;p&gt;
&lt;a href=&#034;/files/2011/ATmegaRegMem.pdf&#034;&gt;&lt;img src=&#034;/images/2011/ATmegaRegMem.png&#034; alt=&#034;ATMega registers and address ranges&#034;/&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Click on the image for a PDF copy of the table.  I hope you find this useful, corrections and suggestions welcome - please leave a comment below!
&lt;/p&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#034;http://www.atmel.com/dyn/resources/prod_documents/doc8271.pdf&#034;&gt;ATmega328P datasheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#034;http://www.atmel.com/dyn/resources/prod_documents/doc2549.pdf&#034;&gt;ATmega1289 datasheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#034;http://www.atmel.com/dyn/resources/prod_documents/doc0856.pdf&#034;&gt;8-bit AVR instruction set&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#034;http://www.nongnu.org/avr-libc/user-manual/index.html&#034;&gt;avr-libc documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;</description>
      <category>Arduino</category>
    <category>Tech</category>
    <comments>http://bleaklow.com:80/2011/04/10/atmega_registers_and_memory_ranges.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2011/04/10/atmega_registers_and_memory_ranges.html</guid>
    <pubDate>Sun, 10 Apr 2011 16:28:50 GMT</pubDate>
  </item>
  <item>
    <title>EletroAxé with Carlinhos Brown</title>
    <link>http://bleaklow.com:80/2011/04/01/eletroax_with_carlinhos_brown.html</link>
    <description>
          &lt;p&gt;
&lt;a href=&#034;http://www.carlinhosbrown.com.br/en/music/&#034;&gt;Carlinhos Brown&lt;/a&gt; is a colossus in Brazilian music, known not only for his solo musical career but also for the founding of &lt;a href=&#034;http://www.timbalada.com/&#034;&gt;Timbalada&lt;/a&gt; and for reviving the use of the Timbau, one of the instruments I (try to!) play.  As part of this year&#039;s carnival in Salvador, &lt;a href=&#034;http://kylemcdonald.net&#034;&gt;Kyle McDonald&lt;/a&gt; and &lt;a href=&#034;http://www.lucaswerthein.com&#034;&gt;Lucas Werthein&lt;/a&gt; built him a drum suit, with a series of drum triggers linked up to an Arduino and then via wireless to a PC to allow Carlinhos to trigger drum samples by tapping on the pads on the suits.  It&#039;s a cool project, see the video below and the &lt;a href=&#034;http://www.lucaswerthein.com/?p=187&#034;&gt;project page&lt;/a&gt; on Lucas&#039;s site for the full details.
&lt;/p&gt;
&lt;p&gt;
&lt;iframe src=&#034;http://player.vimeo.com/video/21531156&#034; width=&#034;480&#034; height=&#034;270&#034; frameborder=&#034;0&#034;&gt;&lt;/iframe&gt;
&lt;/p&gt;
&lt;p&gt;
The very first version of my &lt;a href=&#034;/2011/03/11/as_it_says_beautiful_light_performance.html&#034;&gt;wireless-controlled LED system&lt;/a&gt; was intended to be used on drums, so the EletroAxé project is based on a similar concept.  In my case I built a prototype using a &lt;a href=&#034;http://www.sparkfun.com/products/9199&#034;&gt;vibration sensor&lt;/a&gt; mounted on one of the &lt;a href=&#034;http://www.kalango.com/lshop,showrub,2004g,e,,percussion_instruments.alfaia,,,,.htm&#034;&gt;Alfaias&lt;/a&gt; that we play in &lt;a href=&#034;http://www.jubadoleao.com/&#034;&gt;Juba do Leão&lt;/a&gt;, the &lt;a href=&#034;http://www.jubadoleao.com/geek.php&#034;&gt;Maracatu&lt;/a&gt; group I&#039;m a member of.  It worked fine, but then the folks from the &lt;a href=&#034;http://travellinglightcircus.com&#034;&gt;Travelling Light Circus&lt;/a&gt; came along with their proposal, and the idea of mounting the strips on drums got shelved.  However it would be pretty cool to link up something like that suit to the LED system. and as both are arduino-based, it wouldn&#039;t be particularly hard either.  I have mad visions of this bunch playing at night, all lit up with radio-synchronised LED strips :-)
&lt;/p&gt;
&lt;p&gt;
&lt;iframe title=&#034;YouTube video player&#034; width=&#034;480&#034; height=&#034;390&#034; src=&#034;http://www.youtube.com/embed/IVtYG3tYg0M?rel=0&#034; frameborder=&#034;0&#034; allowfullscreen&gt;&lt;/iframe&gt;
&lt;/p&gt;</description>
      <category>Drumming</category>
    <category>Arduino</category>
    <category>Tech</category>
    <comments>http://bleaklow.com:80/2011/04/01/eletroax_with_carlinhos_brown.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2011/04/01/eletroax_with_carlinhos_brown.html</guid>
    <pubDate>Fri, 01 Apr 2011 17:17:00 GMT</pubDate>
  </item>
  <item>
    <title>As it says, &#034;Beautiful light performance&#034;</title>
    <link>http://bleaklow.com:80/2011/03/11/as_it_says_beautiful_light_performance.html</link>
    <description>
          &lt;p&gt;
Well, we did our first performance with the LED strips on Wednesday at &lt;a href=&#034;http://www.islingtonmill.com/&#034;&gt;Islington Mill&lt;/a&gt; in Manchester,and I&#039;m relieved to say they worked flawlessly, even after one of the wheels was dropped just before the performance started!  The lighting in the venue was a bit too bright to make a good video, so Andy made a video of the strips in action at Thursday&#039;s &lt;a href=&#034;http://travellinglightcircus.com/&#034;&gt;Travelling Light Circus&lt;/a&gt; rehearsal which he&#039;s put up on YouTube.  Even though I say it myself, I think it&#039;s rather good :-)
&lt;/p&gt;
&lt;p&gt;
Seeing the strips in use by the talented TLC performers just gives them an entirely different dimension, and I think the video is really well done as well. For me, one of the best bits of the project has been the opportunity to work with people who have an artistic clue :-)
&lt;/p&gt;
&lt;p&gt;
&lt;iframe title=&#034;YouTube video player&#034; width=&#034;640&#034; height=&#034;390&#034; src=&#034;http://www.youtube.com/embed/p2Q76JXH06U&#034; frameborder=&#034;0&#034; allowfullscreen&gt;&lt;/iframe&gt;
&lt;/p&gt;</description>
      <category>Arduino</category>
    <category>Tech</category>
    <comments>http://bleaklow.com:80/2011/03/11/as_it_says_beautiful_light_performance.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2011/03/11/as_it_says_beautiful_light_performance.html</guid>
    <pubDate>Fri, 11 Mar 2011 23:01:00 GMT</pubDate>
  </item>
  <item>
    <title>Connecting a HL1606 strip to an ATmega</title>
    <link>http://bleaklow.com:80/2011/03/09/connecting_a_hl1606_strip_to_an_atmega.html</link>
    <description>
          I&#039;ve been left &lt;a href=&#034;/2010/05/28/bidirectional_patterns_with_the_hl1606.html#comment1299357384118&#034;&gt;a comment&lt;/a&gt; asking how the HL1606 strips are connected up to an Arduino.  The wiring is really pretty simple, but depends on exactly which ATmega version you have, as the hardware SPI pins vary from MCU to MCU. The following assumes it&#039;s a ATmega328P as used on the more modern Duemilanoves, you&#039;ll need to refer to the MCU documentation and the board schematic to find the correct ports and pins for different Arduino versions.&lt;/p&gt;
&lt;p&gt;The 328P uses the following pins for hardware SPI:&lt;/p&gt;
&lt;pre&gt;
/CS    Port B Pin 2    (Arduino pin 10)
MOSI   Port B Pin 3    (Arduino pin 11)
MISO   Port B Pin 4    (Arduino pin 12)
SCK    Port B Pin 5    (Arduino pin 13)
&lt;/pre&gt;
&lt;p&gt;
I used Timer 2 to drive the fade clock on the strips.  The output of Timer 2 uses the following pin:
&lt;pre&gt;
TIMER2 Port B Pin 1    (Arduino pin 9)
&lt;/pre&gt;
&lt;/p&gt;
&lt;p&gt;The strips themselves have the following labelling on the inputs:&lt;/p&gt;
&lt;pre&gt;
S-I    Fade clock input
D-I    Data input
CK-I   Data clock input
L-I    Data latch input
&lt;/pre&gt;
&lt;p&gt;
So you need to wire up the strip as follows:
&lt;pre&gt;
ATmega      Strip
/CS     to  L-I
MOSI    to  D-I
SCK     to  CK-I
TIMER2  to  SI
&lt;/pre&gt;
&lt;p&gt;
Note that if you want to wire up more than one strip you&#039;ll need to work around the fact that the HL1601 strips don&#039;t implement the SPI protocol properly.  The easiest way is to gate the SCK signal with the /CS line so that when a strip is not being accessed it doesn&#039;t see the data clock.  I&#039;ve detailed the problem and the solution more fully in this &lt;a href=&#034;2010/05/27/how_the_hl1606_really_works.html&#034;&gt;earlier post&lt;/a&gt;,
&lt;/p&gt;</description>
      <category>Arduino</category>
    <category>Tech</category>
    <comments>http://bleaklow.com:80/2011/03/09/connecting_a_hl1606_strip_to_an_atmega.html#comments</comments>
    <guid isPermaLink="true">http://bleaklow.com:80/2011/03/09/connecting_a_hl1606_strip_to_an_atmega.html</guid>
    <pubDate>Wed, 09 Mar 2011 23:29:00 GMT</pubDate>
  </item>
  </channel>
</rss>

