<?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>^2&#039; &#187; microcontroller</title>
	<atom:link href="http://andrew-stephanie.ca/tag/microcontroller/feed" rel="self" type="application/rss+xml" />
	<link>http://andrew-stephanie.ca</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2012 20:12:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>DSC &#8211; Differential Solar Controller</title>
		<link>http://andrew-stephanie.ca/dsc-differential-solar-controller</link>
		<comments>http://andrew-stephanie.ca/dsc-differential-solar-controller#comments</comments>
		<pubDate>Sun, 10 Jan 2010 19:28:11 +0000</pubDate>
		<dc:creator>abythell</dc:creator>
				<category><![CDATA[At Home]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[microcontroller]]></category>
		<category><![CDATA[solar]]></category>

		<guid isPermaLink="false">http://andrew-stephanie.ca/?p=792</guid>
		<description><![CDATA[To control a domestic solar hot water system, a custom controller was built using the Arduino Duemilanove. It reads temperature inputs from the tank and roof sensors to drive a relay that turns the circulator pump on and off. Temperature readings are sent via serial port to a laptop which records and graphs the temperature data. The graphs and data are sent wirelessly to a web server, that displays the current temperatures and status using a Google Gadget. [...]]]></description>
			<content:encoded><![CDATA[<p>To control my domestic <a href="http://andrew-stephanie.ca/?s=solar+water">solar hot water system</a>, I built a custom controller was built using the <a href="http://arduino.cc/en/Main/ArduinoBoardDuemilanove">Arduino Duemilanove</a>.Â Â  It reads temperature inputs from the tank and roof sensors to drive a relay that turns the circulator pump on and off.Â  Temperature readings are sent via serial port to a laptop which records and graphs the temperature data.Â  The graphs and data are sent wirelessly to a web server, that displays the <a href="http://andrew-stephanie.ca/solar">current temperatures and status</a> using a <a href="http://www.google.com/ig/adde?synd=open&amp;source=ggyp&amp;moduleurl=andrew-stephanie.ca/dsc/gsolar.xml">Google Gadget</a>.</p>
<p>I designed, built, and installed the controller for around $100.Â  Here is a brief description of how to build your own DSC.Â  This is by no means an exhaustive, step-by-step guide, and you will require knowledge of electrical wiring, soldering, programming, Linux, web servers, and more.</p>
<h3>Temperature Sensors</h3>
<p>A single strand of Cat5 cable forms a bus for a network of Dallas <a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&amp;name=DS18S20%2BCT-ND">DS1820+</a> 1-wire temperature sensors (<a href="http://datasheets.maxim-ic.com/en/ds/DS18S20.pdf">datasheet</a>).Â  The Cat5 cable is run from the controller (using RJ-45 connector), past the heat exchanger (for input, output, and tank sensors) and cold water inputs, then up onto the roof and into the temperature sensor well inside the solar collector.Â  Temperature sensors can be added anywhere along the bus using telephone <a href="http://www.homedepot.ca/webapp/wcs/stores/servlet/CatalogSearchResultView?D=902030&amp;Ntt=902030&amp;catalogId=10051&amp;langId=-15&amp;storeId=10051&amp;Dx=mode+matchallpartial&amp;Ntx=mode+matchall&amp;recN=0&amp;N=0&amp;Ntk=P_PartNumber">3-Wire Butt Splice</a> (blue) connectors.Â  Be sure to crimp them tightly so that all the wires make solid contact.Â  Using TIA/EIA-568-B wiring:</p>
<ul>
<li>Blue = DQ (pin 2)</li>
<li>Blue/White = GND (pin 1)</li>
<li>Orange = +5V (pin 3)</li>
</ul>
<p>Solder a 6&#8243; lead to each leg of the DS1820.Â  Use higher-temperature wire for the roof sensor (125 C +).Â  Wrap leg #2 in 1/8&#8243; heat-shrink, then wrap the entire device (all three legs and part of the semiconductor) in 1/4&#8243; heat-shrink.</p>
<p>The temperature sensor can be mounted to a conductive surface (pipe, side of a tank, etc.) using 3M <a href="http://www.canadiantire.ca/AST/browse/3/HouseHome/StorageOrganization/HouseholdOrganization/PRD%7E0610403P/3M%2BPicture%2BHanging%2BStrips.jsp">Picture Hanging Strips</a>, <a href="http://www.canadiantire.ca/AST/browse/6/Tools/SpecialtyTools/TapeGlueSealants/PRD%7E0676065P/3M%2BExterior%2BMounting%2BTape.jsp">Exterior Mounting Tape</a>, or plain old duct tape.Â  They can also be inserted into metal knitting needles and sealed with epoxy to make probes.</p>
<h3>Controller Hardware</h3>
<p>Using the links below, you can order all the parts you need to build your own DSC, assuming you can read a schematic and solder (some surface mount parts).Â  Don&#8217;t forget to add at least 2 (4 is better) Dallas 1-wire temperature sensors (<a href="http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&amp;name=DS18S20%2BCT-ND">DS-1820</a>) to your parts order.</p>
<ul>
<li><a href="http://andrew-stephanie.ca/wp-content/uploads/2010/01/dsc-schematic.pdf">schematic for the DSC controller</a> (PDF)</li>
<li><a href="http://andrew-stephanie.ca/wp-content/uploads/2010/01/digikey-partslist.csv">digikey-partslist</a> (CSV) &#8211; includes <a href="http://www.digikey.ca">Digikey</a> Part Numbers required to populate the PCB.Â  Other Digikey parts may be required &#8211; read on for a complete list.</li>
<li><a href="http://www.batchpcb.com/product_info.php?products_id=29172&amp;check=ccf26c8dc7149029c17c4a51858fee64">printed circuit board</a> &#8211; order from <a href="http://www.batchpcb.com">Batch PCB</a></li>
<li>Arduino <a href="http://arduino.cc/en/Main/ArduinoBoardDuemilanove">Duemilanove</a> &#8211; purchase online from SparkFun or Adafruit</li>
</ul>
<p>The PCB is an Arduino shield that mates with the Duemilanove.Â  You could also build the controller on a prototype board or using a prototype shield from SparkFun or Adafruit.Â  As you can see from the schematic, the circuit is not that complicated, and most parts can be swapped or omitted, except for R1 (4K7) which is a required value for the 1-Wire bus.</p>
<p>The PCB is my design and can be used for non-commercial purposes, with no warranty.Â  It&#8217;s been tested though and is the same board design I am currently using to run my solar hot water system.Â  BatchPCB provides low-cost, small run, well made printed circuit boards.Â  The link above should allow you to place your own order directly without any middlemen (ie. Me).Â  I&#8217;ve used BatchPCB for many projects and have always been happy with the results.</p>
<p>The parts list has Digkey part numbers to all the components I used to populate the PCB.Â  If you notice Digikey no longer stocks a part, or you&#8217;re wondering about compatibility with other part numbers, please let me know.Â  Digikey has a reasonable shipping and handling fee, considering that you can place an order at noon today and have the parts on your desk by noon tomorrow.</p>
<p>A relay runs a 120V AC <a href="http://www.google.com/url?sa=t&amp;source=web&amp;cd=5&amp;ved=0CDAQFjAE&amp;url=http%3A%2F%2Fkingpumps.com%2FPDFs%2FGrundfosPumps%2FL-UP-TL-107.pdf&amp;ei=Id1-TOz7Aov4sAOp2rieCw&amp;usg=AFQjCNFvxTBtwP1SbX2bAUBR7dcF_i4uhQ&amp;sig2=EnBDsykUs5J4KwyQKyM2_w">Grundfos UP26-99</a> circulator pump, which will draw at most 2.1A. Â  Make sure the relay can handle the current needed to run your pump (see <a href="http://www.components.omron.com/components/web/PDFLIB.nsf/0/8F66C9A835A195FE85257201007DD572/$file/G2RL_0609.pdf">datasheet</a>), and if necessary choose another relay with the same footprint.Â  The relay listed is rated for 12A@250VAC.</p>
<h3>Wiring and Enclosure</h3>
<p>Because this circuit uses 12VDC and 120V AC, ensure you mount the controller in an appropriate enclosure and take all the usual precautions when dealing with electricity.Â Â  Required parts:</p>
<ul>
<li>metal or plastic (easier to drill) enclosure &#8211; 4x4x6 leaves lots of room for wiring</li>
<li>LED lenses (need part number)</li>
<li>AC Hour Meter (optional)</li>
<li>AC Toggle Switch</li>
</ul>
<p>The controller can be wired directly, or fitted with an AC plug.Â  The connection between the pump and the controller can also be made using AC plugs and sockets.</p>
<h3>Firmware</h3>
<p>Built with the <a href="http://www.arduino.cc/">Arduino</a> environment and the <a href="http://milesburton.com/wiki/index.php?title=Dallas_Temperature_Control_Library">Dallas Temperature Control Library</a>.Â  <a href="http://andrew-stephanie.ca/wp-content/uploads/2010/01/dsc.tar.gz">Download the sketch</a>.</p>
<h3>Logging</h3>
<p>The system can be monitored using the USB/serial port of the Arduino.Â  I use a bash script running on a linux laptop that is called from a cron job to read the state and temperatures via tty and insert them into a round robin database to create useful graphs.Â  The bash script also outputs an <a href="http://andrew-stephanie.ca/dsc/solar.xml">XML file</a>, which is used as the data source for the <a href="http://andrew-stephanie.ca/dsc/gsolar.xml">Solar Hot Water Google Gadget</a>.Â  Get the gadget and view the system status <a href="http://andrew-stephanie.ca/solar">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrew-stephanie.ca/dsc-differential-solar-controller/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>AVR and ISP</title>
		<link>http://andrew-stephanie.ca/avr-and-isp</link>
		<comments>http://andrew-stephanie.ca/avr-and-isp#comments</comments>
		<pubDate>Wed, 24 Sep 2008 18:22:06 +0000</pubDate>
		<dc:creator>abythell</dc:creator>
				<category><![CDATA[At Work]]></category>
		<category><![CDATA[microcontroller]]></category>
		<category><![CDATA[stk500]]></category>

		<guid isPermaLink="false">http://andrew-stephanie.ca/?p=29</guid>
		<description><![CDATA[Schematic <p>The ATMEL ISP programming standard is a 6 pin header, from the AVR Hardware Design Considerations appnote.&#160; This pinout is used on the STK500.&#160; Unlike some protocols (eg. RX and TX) there is no need to swap the MISO and MOSI lines when wiring up the header.&#160; The stk500 is able to have LEDS [...]]]></description>
			<content:encoded><![CDATA[<h3>Schematic</h3>
<p>The ATMEL ISP programming standard is a 6 pin header, from the <a href="http://www.google.ca/url?sa=t&#038;source=web&amp;ct=res&#038;cd=1&amp;url=http%3A%2F%2Fwww.atmel.com%2Fdyn%2Fresources%2Fprod_documents%2Fdoc2521.pdf&#038;ei=Ye7bSJi6EI2woQSzsMjsAw&amp;usg=AFQjCNGhHVT83gW5ojlD-ZD1n5rWRH4ElA&amp;sig2=KWECGkSmW4einJpvFLxIEQ">AVR Hardware Design Considerations</a> appnote.&nbsp; This pinout is used on the STK500.&nbsp; Unlike some protocols (eg. RX and TX) there is no need to swap the MISO and MOSI lines when wiring up the header.&nbsp; The stk500 is able to have LEDS and switches connected to the mcu during programming.&nbsp; Experiments show that LEDS on the MOSI and MISO lines without R1 and R2 break ISP.&nbsp; Any devices on the SPI ports need to be isolated by a resistor (see Section 4 of the <a href="http://www.google.ca/url?sa=t&#038;source=web&amp;ct=res&#038;cd=1&amp;url=http%3A%2F%2Fwww.atmel.com%2Fdyn%2Fresources%2Fprod_documents%2Fdoc2521.pdf&#038;ei=Ye7bSJi6EI2woQSzsMjsAw&amp;usg=AFQjCNGhHVT83gW5ojlD-ZD1n5rWRH4ElA&amp;sig2=KWECGkSmW4einJpvFLxIEQ">appnote</a>).</p>
<div id="attachment_99" class="wp-caption alignnone" style="width: 310px"><a href="http://andrew-stephanie.ca/wp-content/uploads/2008/09/attiny-schematic.png"><img class="size-medium wp-image-99" title="attiny-schematic" src="http://andrew-stephanie.ca/wp-content/uploads/2008/09/attiny-schematic-300x213.png" alt="AVR attiny13 setup for ISP" height="213" width="300" /></a><p class="wp-caption-text">AVR attiny13 setup for ISP</p></div>
<div id="attachment_101" class="wp-caption alignnone" style="width: 160px"><a href="http://andrew-stephanie.ca/wp-content/uploads/2008/09/isp-spi.png"><img class="size-thumbnail wp-image-101" title="isp-spi" src="http://andrew-stephanie.ca/wp-content/uploads/2008/09/isp-spi-150x150.png" alt="Proper connection for SPI and ISP to co-operate" height="150" width="150" /></a><p class="wp-caption-text">Proper connection for SPI and ISP to co-operate</p></div>
<p><div id="attachment_36" class="wp-caption alignnone" style="width: 160px"><a href="http://andrew-stephanie.ca/wp-content/uploads/2008/09/isp.png"><img class="size-thumbnail wp-image-36" title="isp" src="http://andrew-stephanie.ca/wp-content/uploads/2008/09/isp-150x150.png" alt="6-Pin In Circuit Programming Header for AVR" height="150" width="150" /></a><p class="wp-caption-text">6-Pin In Circuit Programming Header for AVR</p></div><br />
<h3><strong>STK500 and ATTiny13 @ 128kHz<br /></strong></h3>
<p>The ISP programming frequency must be at least 1/4 the target clock frequency (datasheeet).&nbsp; For an ATTiny13 running at 128kHz (for power saving) the SCK period should be at least 32 us.&nbsp; Another<a href="http://www.google.ca/url?sa=t&#038;source=web&amp;ct=res&#038;cd=15&amp;url=http%3A%2F%2Fwww.ai.uga.edu%2Fmc%2Fmicrocontrollers%2Favr%2FAVRnotebook.pdf&#038;ei=tdTbSPXDIKWkpwTlpojnAw&amp;usg=AFQjCNHvfi1_UVcc9DEK0h9WLjvei7zQPQ&amp;sig2=8YZjVoGr5cPfSEEoD8j97A"> online source</a> offers the following hookup for programming attiny13s with an stk500:
<ul>	
<li> Connect ISP6 to SPROG1 with a 6-pin cable;</li>
<p>	
<li>Connect PORTE.RST to PORTB.PB5 with a 1-pin cable;</li>
<p>	
<li>Connect PORTE.XT1 to PORTB.PB3 with a 1-pin cable;</li>
<p>	
<li>Set ISP frequency (in AVR Studio STK500 menu) to 1/5 the target clock&nbsp; frequency, or lower. (By default, target clock frequency is 9.6 / 8 = 1.2&nbsp; MHz.)</li>
<p></ul>
<p>1/5 target clock frequency for 128kHz clock would yield SCK = 39.&nbsp; This is an interesting discussion on programming the attiny13 at low clock speeds:<br />
<blockquote><a href="http://http://www.nabble.com/Slow-communication-with-ATTiny13-td12775912.html">http://www.nabble.com/Slow-communication-with-ATTiny13-td12775912.html</a></p></blockquote>
<p>While this seems straight forward, in practice once the lfuse is changed from 0x6A to 0x6B (CLKSEL=11 or 128kHz internal), the stk500 with an sck=40 is unable to communicate with the chip.&nbsp; Initially, communication was restored using:
<ul>	
<li>fosc = 128000 (stk500 rewrites as 131kHz)</li>
<p>	
<li>sck = 40</li>
<p>	
<li>avrdude option i=40</li>
<p></ul>
<p>Then suddenly this no longer worked.&nbsp; From the <a href="http://www.google.ca/url?sa=t&#038;source=web&amp;ct=res&#038;cd=1&amp;url=http%3A%2F%2Fwww.atmel.com%2Fdyn%2Fresources%2Fprod_documents%2Fdoc2535.pdf&#038;ei=rCPcSI-KA6LOpgS20PjoAw&amp;usg=AFQjCNHuCqIJRgLDMEQyX74Ad2b5W20VDA&amp;sig2=ChJAr2WYwTcxVJO-cp-sHA">attiny13 datasheet</a>:<br />
<blockquote>The 128 kHz internal Oscillator is a low power Oscillator providing a clock of 128 kHz. The frequency depends on supply voltage, temperature and batch variations. This clock may be select as the system clock by programming the CKSEL fuses to â€œ11â€.</p></blockquote>
<p>So it would seem that the clock frequency may or may not be 128khz.&nbsp; After through testing, it was determined that the i=40 option has no effect.&nbsp; Given that the clock frequency is essentially unknown, the only way to restore communications is to max out SCK:
<ul>	
<li>fosc = 131.657</li>
<p>	
<li>sck = 276</li>
<p>	
<li>avrdude option &#8216;i&#8217; not used</li>
<p></ul>
<p>It should also be noted that things were restored after trying to read out all the flash memory, then adjusting the stk500 parameters as above.&nbsp;&nbsp; The flash dump does not complete before the stk500_2_ReceiveMessage(): timeout.&nbsp; The timeout also happens when programming larger files into flash.&nbsp; Not sure if the read cycle is related, but thought it should be noted.&nbsp; Timouts also occur with these settings programming an ATMeg8151.&nbsp; Use these settings instead:
<ul>
<li>fosc = 1.229 Mhz</li>
<li>sck = 9.8 us</li>
<li>vtarget/vareg = 5.0V</li>
</ul>
<h3>Power Consumption</h3>
<p>Ideally this would run from a <a href="http://www.batteryprice.com/productspec/cr2032.pdf">CR2032</a> lithium button cell battery.&nbsp; The circuit above, with LED1 not connected, draws 12mA.&nbsp; The CR2032 specs indicate 12mA is the maximum recommended pulse discharge, and 4mA is the max. continuous discharge rate.&nbsp; That means currently this 220mAh battery will only last 18 hours.&nbsp; If the design can be tweaked to run at 4mA, the run time would be 55 hours. Rechargeable AA batteries have capacity 2100 &#8211; 2600 mAh, which could run for about a month.</p>
<p>Options for minimizing power consumption are listed in the <a href="http://www.google.ca/url?sa=t&#038;source=web&amp;ct=res&#038;cd=1&amp;url=http%3A%2F%2Fwww.atmel.com%2Fdyn%2Fresources%2Fprod_documents%2Fdoc2535.pdf&#038;ei=rCPcSI-KA6LOpgS20PjoAw&amp;usg=AFQjCNHuCqIJRgLDMEQyX74Ad2b5W20VDA&amp;sig2=ChJAr2WYwTcxVJO-cp-sHA">datasheet</a> in section 7.2.&nbsp; The A/D convert, BOD, and watchdog are all turned off by default.&nbsp; Only the analog comparator must be disabled.&nbsp; Setting unused pins to inputs and enabling internal pull ups is also recommended.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrew-stephanie.ca/avr-and-isp/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

