<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/"/>

<title>Jeff Epler's blog</title>
<modified>2014-04-30T21:14:10Z</modified>
<tagline>Photos, electronics, cnc, and more</tagline>
<author><name>Jeff Epler</name><email>jepler@unpythonic.net</email></author>
<entry>
<title>Towards fast I/O in Arduino for AVRs</title>
<issued>2014-04-30T21:14:10Z</issued>
<modified>2014-04-30T21:14:10Z</modified>
<id>https://gamma.unpythonic.net/01398892450</id>
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/01398892450"/>
<content type="text/html" mode="escaped">

So I've been working on something.  I've only looked at assembler output so far,
but it looks right and promising.

&lt;p&gt;Basically, I'd like to let you name I/O pins via typedef, then efficiently
read and write the pins.  And I'd like to make Arduino's digitalWrite just as
efficient when the pin argument is a constant.

&lt;p&gt;All instruction counts are in Debian Wheezy's avr-gcc version 4.7.2 with 
&lt;tt&gt;-mmcu=atmega328p -Os&lt;/tt&gt; specified on the commandline.
&lt;pre&gt;
// You can declare ports (they use zero RAM)
typedef IOPIN&amp;lt;PORT_B, 0&amp;gt; iob0;
typedef IOPIN&amp;lt;PORT_B, 1&amp;gt; iob1;
typedef OCPIN&amp;lt;PORT_B, 1, true&amp;gt; ocb1; // emulate an open collector port

// .. and use them efficiently (instruction counts never include ret)
int en() { iob0::output(); }                // 1 instruction
int fn() { iob0::toggle(); }                // 1 instruction
int gn() { ocb1::set(); }                   // 2 instructions
int hn() { ocb1::clear(); }                 // 2 instructions
int jn(bool b) { iob0::write(b); }          // 5 instructions
int kn() { iob0::write(1); }                // 1 instruction

// you can use fastDigitalWrite just like digitalWrite (but faster and inline)
int c(int i) { fastDigitalWrite(1, i); }    // 5 instructions
int d() { fastDigitalWrite(1, 1); }         // 1 instruction

// these have a variable port so they still turn into calls to digitalWrite
int a(int i, int j) { fastDigitalWrite(i, j); }
int b(int i) { fastDigitalWrite(i, 1); }
&lt;/pre&gt;

&lt;p&gt;&lt;p&gt;&lt;b&gt;Files currently attached to this page:&lt;/b&gt;
&lt;table cellpadding=5 style=&quot;width:auto!important; clear:none!important&quot;&gt;&lt;col&gt;&lt;col style=&quot;text-align: right&quot;&gt;&lt;tr bgcolor=#eeeeee&gt;&lt;td&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01398892450/fast_io_prototype.cpp&quot;&gt;fast_io_prototype.cpp&lt;/a&gt;&lt;/td&gt;&lt;td&gt;6.2kB&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;p&gt;
</content>
</entry>
<entry>
<title>WWVB clock progress</title>
<issued>2011-09-12T20:29:28Z</issued>
<modified>2011-09-12T20:29:28Z</modified>
<id>https://gamma.unpythonic.net/01315859368</id>
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/01315859368"/>
<content type="text/html" mode="escaped">
&lt;a href=&quot;http://timeguy.com&quot;&gt;Chris&lt;/a&gt; was kind enough to pass along to me a
&lt;a href=&quot;http://www.sparkfun.com/products/10060&quot;&gt;commercial WWVB receiver&lt;/a&gt;.
This module was a bit of a pain to develop for, because most of the time the
interference from a nearby laptop computer is enough to seriously compromise
reception, and almost all of the time having a USB cable running from the
microcontroller to the laptop will kill reception outright.</content>
</entry>
<entry>
<title>Towards my GPS LED Light Clock</title>
<issued>2011-06-22T20:19:10Z</issued>
<modified>2011-06-22T20:19:10Z</modified>
<id>https://gamma.unpythonic.net/01308773950</id>
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/01308773950"/>
<content type="text/html" mode="escaped">
A few years ago, I made a CCFL light clock using an Arduino with a custom
shield containing a transformer (to get a reliable 60Hz timebase) and a
triac (for solid-state switching of the lamp).  By having a simple 7-day alarm calendar (set at compile time), the clock seldom requires interaction except for the reading lamp function.

&lt;p&gt;However, the design has two main problems:</content>
</entry>
<entry>
<title>Arduino Random Number Generator</title>
<issued>2009-11-10T16:00:26Z</issued>
<modified>2009-11-10T16:00:26Z</modified>
<id>https://gamma.unpythonic.net/01257868826</id>
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/01257868826"/>
<content type="text/html" mode="escaped">&lt;div style=&quot;float:right;clear:right&quot;&gt;&lt;!-- schematic.png--&gt;&lt;div class=albumouter style=width:306px id=&gt;&lt;div class=albumimage style=&quot;width:253px;margin-left:26.5px;&quot;&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01257868826/schematic.png&quot; class=&quot;thickbox&quot; rel=&quot;album&quot; title=&quot;Random Number Generator Schematic&quot;&gt;&lt;img src=&quot;https://media.unpythonic.net/emergent-files/01257868826/schematic-small.jpg&quot; width=247 height=300&gt;&lt;/a&gt;&lt;div &gt;&lt;div style=&quot;float: right&quot; &gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01257868826/schematic.png&quot;&gt;&lt;img class=zoom src=&quot;https://media.unpythonic.net/emergent-files/default/zoom.png&quot;&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01257868826/schematic.png&quot;&gt;Random Number Generator Schematic&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;
Inspired by other designs I've seen online, most directly &lt;a href=&quot;http://robseward.com/misc/RNG2/&quot;&gt;Rob Seward's design&lt;/a&gt;, I decided
to build my own random number generator based Will Ware's &amp;quot;avalanche noise in a
reverse-biased PN junction&amp;quot; (try &lt;a href=&quot;http://web.archive.org/web/20061117145903/http://willware.net:8080/hw-rng.html&quot;&gt;this mirror&lt;/a&gt; of &lt;a href=&quot;http://willware.net:8080/hw-rng.html&quot;&gt;Will Ware's page&lt;/a&gt;).  Also important is &lt;a href=&quot;http://www.av8n.com/turbid/paper/turbid.htm&quot;&gt;turbid&lt;/a&gt; which introduced me to the
concept of hash saturation and the math behind it.

&lt;p&gt;</content>
</entry>
<entry>
<title>at90usb162 single-sided board</title>
<issued>2009-06-29T12:19:33Z</issued>
<modified>2009-06-29T12:19:33Z</modified>
<id>https://gamma.unpythonic.net/01246277973</id>
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/01246277973"/>
<content type="text/html" mode="escaped">I got an e-mail request for this board.  You may use this eagle (4.x) library,
schematic, and board under the &lt;a href=&quot;http://www.gnu.org/licenses/gpl-2.0.html&quot;&gt;GNU GPL version 2 or later&lt;/a&gt;, or &lt;a href=&quot;http://creativecommons.org/licenses/by-sa/3.0/us/&quot;&gt;CC-BY-SA&lt;/a&gt;.</content>
</entry>
<entry>
<title>Autoreprogram for DFU devices</title>
<issued>2008-10-04T12:54:38Z</issued>
<modified>2008-10-04T12:54:38Z</modified>
<id>https://gamma.unpythonic.net/01223124878</id>
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/01223124878"/>
<content type="text/html" mode="escaped">
It's a bit of an annoyance to first have to press a combination of two
buttons on my at90usb162 board, then run a sequence of 4 dfu-programmer
commands.

&lt;p&gt;Thanks to the magic of the freedesktop 'hal', though, I've written a program
that waits for the dfu device to appear.  It then erases and flashes the
device, finally restarting into the newly uploaded firmware.

&lt;p&gt;Modify the program to name your .hex file (and avr partnumber if it's
different), then leave it running in the background.
It's still necessary to tickle the RESET and HWB buttons in the proper way
after rebuilding your firmware, but it does shorten the process.

&lt;p&gt;&lt;p&gt;&lt;b&gt;Files currently attached to this page:&lt;/b&gt;
&lt;table cellpadding=5 style=&quot;width:auto!important; clear:none!important&quot;&gt;&lt;col&gt;&lt;col style=&quot;text-align: right&quot;&gt;&lt;tr bgcolor=#eeeeee&gt;&lt;td&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01223124878/autoprogram.py&quot;&gt;autoprogram.py&lt;/a&gt;&lt;/td&gt;&lt;td&gt;1.5kB&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;p&gt;
</content>
</entry>
<entry>
<title>at90usb162 gotcha: PC0 vs XTAL2</title>
<issued>2008-10-04T03:05:39Z</issued>
<modified>2008-10-04T03:05:39Z</modified>
<id>https://gamma.unpythonic.net/01223089539</id>
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/01223089539"/>
<content type="text/html" mode="escaped">
&lt;div style=&quot;float:right;clear:right&quot;&gt;&lt;!-- tqfpboard.jpg--&gt;&lt;div class=albumouter style=width:306px id=&gt;&lt;div class=albumimage style=&quot;width:306px;margin-left:0.0px;&quot;&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01223089539/tqfpboard-medium.jpg&quot; class=&quot;thickbox&quot; rel=&quot;album&quot; title=&quot;Unpopulated board&quot;&gt;&lt;img src=&quot;https://media.unpythonic.net/emergent-files/01223089539/tqfpboard-small.jpg&quot; width=300 height=179&gt;&lt;/a&gt;&lt;div &gt;&lt;div style=&quot;float: right&quot; &gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01223089539/tqfpboard-medium.jpg&quot;&gt;(M)&lt;/a&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01223089539/tqfpboard.jpg&quot;&gt;(L)&lt;/a&gt;&lt;/div&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01223089539/tqfpboard.jpg&quot;&gt;Unpopulated board&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;
I spent a very long time trying to diagnose a board-level problem in my
current project, an (almost all) surface-mount board based on the at90usb162.
The board would reliably program over USB (which is very cool) but the programs
I was running to blink the onboard LEDs would lock up.  When I discovered
that touching the body of the crystal would give me a slow-running program,
I was convinced that I had bad placement of the crystal, or incorrect
capacitors, or the like.

&lt;p&gt;Finally after much head-scratching, I decided to restrict the DDRC to just
some of the pins on the port -- before I'd set DDRC = 0xff.  Well, it turns
out that PC0 is a shared function with XTAL2.  Apparently turning on bit 0
of DDRC turns this pin into an output, and makes the crystal stop running.
Touching the crystal's can coupled 60Hz ambient noise into it, which was
amplified enough to be treated like the external clock (I had suspected that
the LEDs were blinking much slower than they should have been, but wasn't
entirely sure)

&lt;p&gt;Now I'm tempted to declare this board &amp;quot;working&amp;quot;.  whee!

&lt;p&gt;&lt;b&gt;Update&lt;/b&gt;, 2009-03-19: This board has been incorporated in a project.  Yay!
 </content>
</entry>
<entry>
<title>Improved Analog & Digital Interface with Arduino</title>
<issued>2007-12-25T14:51:34Z</issued>
<modified>2007-12-25T14:51:34Z</modified>
<id>https://gamma.unpythonic.net/01198594294</id>
<link rel="alternate" type="text/html" href="https://gamma.unpythonic.net/01198594294"/>
<content type="text/html" mode="escaped">
&lt;div style=&quot;float:right;clear:right&quot;&gt;&lt;!-- arduino-vcp.png--&gt;&lt;div class=albumouter style=width:306px id=&gt;&lt;div class=albumimage style=&quot;width:306px;margin-left:0.0px;&quot;&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01198594294/arduino-vcp-medium.png&quot; class=&quot;thickbox&quot; rel=&quot;album&quot; title=&quot;Arduino Virtual Control Panel&quot;&gt;&lt;img src=&quot;https://media.unpythonic.net/emergent-files/01198594294/arduino-vcp-small.png&quot; width=300 height=52&gt;&lt;/a&gt;&lt;div &gt;&lt;div style=&quot;float: right&quot; &gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01198594294/arduino-vcp-medium.png&quot;&gt;(M)&lt;/a&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01198594294/arduino-vcp.png&quot;&gt;(L)&lt;/a&gt;&lt;/div&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01198594294/arduino-vcp.png&quot;&gt;Arduino Virtual Control Panel&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;float:right;clear:right&quot;&gt;&lt;!-- ArduinoDiecimila400.jpg--&gt;&lt;div class=albumouter style=width:306px id=&gt;&lt;div class=albumimage style=&quot;width:306px;margin-left:0.0px;&quot;&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01198594294/ArduinoDiecimila400-medium.jpg&quot; class=&quot;thickbox&quot; rel=&quot;album&quot; title=&quot;Arduino Diecimila board&quot;&gt;&lt;img src=&quot;https://media.unpythonic.net/emergent-files/01198594294/ArduinoDiecimila400-small.jpg&quot; width=300 height=230&gt;&lt;/a&gt;&lt;div &gt;&lt;div style=&quot;float: right&quot; &gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01198594294/ArduinoDiecimila400-medium.jpg&quot;&gt;(M)&lt;/a&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01198594294/ArduinoDiecimila400.jpg&quot;&gt;(L)&lt;/a&gt;&lt;/div&gt;&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01198594294/ArduinoDiecimila400.jpg&quot;&gt;Arduino Diecimila board&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;
Building on my &lt;a href=&quot;https://gamma.unpythonic.net/01198525592&quot;&gt;earlier work&lt;/a&gt;, I've now improved
the interface between HAL and &lt;a href=&quot;http://arduino.cc&quot;&gt;the Arduino board&lt;/a&gt;
to have:
&lt;ul&gt;&lt;li&gt;6 10-bit analog inputs&lt;/li&gt;&lt;/ul&gt;
&lt;ul&gt;&lt;li&gt;6 8-bit PWM &amp;quot;analog&amp;quot; outputs&lt;/li&gt;&lt;/ul&gt;
&lt;ul&gt;&lt;li&gt;6 digital inputs/outputs (partition chosen when component is loaded)&lt;/li&gt;&lt;/ul&gt;
&lt;ul&gt;&lt;li&gt;GPL license statement in source files&lt;/li&gt;&lt;/ul&gt;
As before, the driver consists of an Arduino Sketch (&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01198594294/halintf.pde&quot;&gt;halintf.pde&lt;/a&gt;)
and a HAL Userspace Component written in Python (&lt;a href=&quot;https://media.unpythonic.net/emergent-files/01198594294/arduino.py&quot;&gt;arduino.py&lt;/a&gt;).</content>
</entry>
</feed>
