<?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>gonium.net &#187; ATMega</title>
	<atom:link href="http://gonium.net/md/tag/atmega/feed/" rel="self" type="application/rss+xml" />
	<link>http://gonium.net/md</link>
	<description>so much time, so little to do.</description>
	<lastBuildDate>Fri, 30 Jul 2010 13:47:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>FreeRTOS for ATMega644</title>
		<link>http://gonium.net/md/2008/08/10/freertos_for_atmega644/</link>
		<comments>http://gonium.net/md/2008/08/10/freertos_for_atmega644/#comments</comments>
		<pubDate>Sun, 10 Aug 2008 16:19:26 +0000</pubDate>
		<dc:creator>md</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[nerdism]]></category>
		<category><![CDATA[ATMega]]></category>
		<category><![CDATA[microcontroller]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[rtos]]></category>

		<guid isPermaLink="false">http://gonium.net/md/?p=89</guid>
		<description><![CDATA[
FreeRTOS is an open-source realtime operating system for microcontrollers. The ATMega644 of ATMEL provides 64KB of flash program memory in a DIY-friendly 40-pin PDIP package. Read on for how to combine both to my new software development platform.

FreeRTOS provides a nice RTOS for embedded systems and is readily available for various platforms. One timer of [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://gonium.net/md/wp-content/uploads/2008/08/1365045226_4e46522658.jpg" alt="six-legged chip bug" title="chip_bug" width="300" height="225" class="alignnone size-medium wp-image-90" /></p>
<p><a href="http://www.freertos.org/">FreeRTOS</a> is an open-source realtime operating system for microcontrollers. The <a href="http://www.atmel.com/dyn/products/product_card.asp?part_id=3694">ATMega644</a> of ATMEL provides 64KB of flash program memory in a DIY-friendly 40-pin PDIP package. Read on for how to combine both to my new software development platform.<br />
<span id="more-89"></span><br />
FreeRTOS provides a nice RTOS for embedded systems and is readily available for various platforms. One timer of the hardware is used to implement multitasking features. A library provides routines for creating tasks and synchronization. Unfortunately, FreeRTOS is currently only ported to the ATMega323 &#8211; so I created a basic port to the ATMega644 and stripped all unnecessary features.</p>
<p>Typically, the FreeRTOS demo shows how to implement various threads and let them access the hardware. While it is educating to read the code, it is too bloated to serve as a template for new developments. In addition, I prefer <a href="http://jump.to/fleury">Peter Fleury&#8217;s UART library</a> for serial outputs. So, I removed all threads and included the library. To make sure that two threads cannot write to the same UART at the same time, I introduced a mutex per UART to synchronize the output on a per-string basis. Please note that there is no Mutex to synchronize read access. The main program starts two tasks which print &#8220;foo&#8221; and &#8220;bar&#8221; to the serial line, respectively. I kept the task surveilance mechanism as implemented in the original FreeRTOS demo (this might become handy ;-))</p>
<p>Here is a peek at the main.c file:</p>
<p class="vci_info">[viewcode]src=freertos-atmega644-main.c [/viewcode]</p>
<pre class="vci_code"></pre>
<p class="vci_info">HTML code generated by <a href="http://www.zacharyfox.com/blog/free-tools/vim-color-improved">vim-color-improved v.0.4.0.</a><strong>Download this code:</strong> <a href="http://gonium.net/media//freertos-atmega644-main.c">freertos-atmega644-main.c</a></p>
<p>You can get the whole package (GPL licensed) from the download page. Have fun! Kudos for the CC&#8217;ed chip bug picture go to <a href="http://flickr.com/photos/oskay/1365045226/">oskay</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gonium.net/md/2008/08/10/freertos_for_atmega644/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tweaking the code</title>
		<link>http://gonium.net/md/2007/04/18/tweaking-the-code/</link>
		<comments>http://gonium.net/md/2007/04/18/tweaking-the-code/#comments</comments>
		<pubDate>Wed, 18 Apr 2007 14:54:47 +0000</pubDate>
		<dc:creator>md</dc:creator>
				<category><![CDATA[arduino]]></category>
		<category><![CDATA[digital]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[ATMega]]></category>
		<category><![CDATA[clock]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dcf77]]></category>

		<guid isPermaLink="false">http://gonium.net/md/2007/04/18/tweaking-the-code/</guid>
		<description><![CDATA[


Thanks to Lasse Lambrecht, I can release a new version of the DCF77 code &#8211; now you can run it on the ATMega168-based Arduinos.



The ATMega8 differs slightly from the ATMega48/88/168-series: The latter chips have an extended Timer2-hardware and therefore need different initializations. Lasse send me a nice adjustment of the code, basically he uses preprocessor [...]]]></description>
			<content:encoded><![CDATA[<img src='http://gonium.net/md/wp-content/uploads/2007/04/tweaking.png' alt='tweaking.png' />
<br />

<p>Thanks to <a href="http://www.lobl.de">Lasse Lambrecht</a>, I can release a new version of the DCF77 code &#8211; now you can run it on the ATMega168-based Arduinos.</p>

<span id="more-55"></span>

The ATMega8 differs slightly from the ATMega48/88/168-series: The latter chips have an extended Timer2-hardware and therefore need different initializations. Lasse send me a nice adjustment of the code, basically he uses preprocessor flags to figure out which initialization commands to use:


#ifdef ATMEGA168
  TCCR2B |= (1< <CS22);    // turn on CS22 bit
  TCCR2B &#038;= ~((1<<CS21) | (1<<CS20));    // turn off CS21 and CS20 bits   
#else
  TCCR2 |= (1<<CS22);    // turn on CS22 bit
  TCCR2 &#038;= ~((1<<CS21) | (1<<CS20));    // turn off CS21 and CS20 bits   
#endif
  // Use normal mode
#ifdef ATMEGA168
  TCCR2A &#038;= ~((1<<WGM21) | (1<<WGM20));   // turn off WGM21 and WGM20 bits 
  TCCR2B &#038;= ~(1<<WGM22);                  // turn off WGM22
#else
  TCCR2 &#038;= ~((1<<WGM21) | (1<<WGM20));   // turn off WGM21 and WGM20 bits 
#endif
  // Use internal clock - external clock not used in Arduino
  ASSR |= (0<<AS2);
#ifdef ATMEGA168
  TIMSK2 |= (1<<TOIE2) | (0<<OCIE2A);        //Timer2 Overflow Interrupt Enable  
#else
  TIMSK |= (1<<TOIE2) | (0<<OCIE2);        //Timer2 Overflow Interrupt Enable  
#endif


As you can see, the avr-libc just defines other names, e.g. TCCR2A/B for the ATMega168 and TCCR2 for the ATMega8.

You can get the new code here
<ul>
	<li><a href="http://gonium.net/media/arduino-dcf77-clock-0.2.1.tar.bz">arduino-dcf77-clock-0.2.1.tar.bz</a></li>


For the hardware setup, please refer to my <a href="http://gonium.net/md/2006/11/05/arduino-dcf77-radio-clock-receiver/">initial post</a>.

]]></content:encoded>
			<wfw:commentRss>http://gonium.net/md/2007/04/18/tweaking-the-code/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Arduino on Steroids</title>
		<link>http://gonium.net/md/2007/01/23/arduino-on-steroids/</link>
		<comments>http://gonium.net/md/2007/01/23/arduino-on-steroids/#comments</comments>
		<pubDate>Tue, 23 Jan 2007 21:46:29 +0000</pubDate>
		<dc:creator>md</dc:creator>
				<category><![CDATA[arduino]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[ATMega]]></category>
		<category><![CDATA[microcontroller]]></category>
		<category><![CDATA[programmer]]></category>
		<category><![CDATA[upgrade]]></category>

		<guid isPermaLink="false">http://gonium.net/md/2007/01/23/arduino-on-steroids/</guid>
		<description><![CDATA[
I just upgraded by little Arduino to the ATMega168 &#8211; and basically doubled the memory. But, be warned: This is not a hassle-free procedure if you have not some experience with microcontrollers.

I bought a cheap serial programmer &#8211; only to figure out that the firmware is outdated and the ATMega168 is not supported. You can [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://gonium.net/md/wp-content/uploads/2007/01/steroids.jpg" alt="steroids" /></p>
<p>I just upgraded by little <a href="http://arduino.cc">Arduino</a> to the ATMega168 &#8211; and basically doubled the memory. But, be warned: This is not a hassle-free procedure if you have not some experience with microcontrollers.</p>
<p><span id="more-38"></span></p>
<p>I bought a cheap serial programmer &#8211; only to figure out that the firmware is outdated and the ATMega168 is not supported. You <strong>can</strong> update the firmware &#8211; but you need another programmer for this *grmp*. So I bought a not-so-cheap <a href="http://myavr.de/shop/artikel.php?artID=42">mySmartUSB</a> which runs over USB  (so there is a chance it will work on the mac, I already found a driver for the USB chipset &#8211; stay tuned.)</p>
<p>Today, most programmers come with a 10-pin header (aka Kanda connector), but the Arduino uses the old 6-pin ICSP header. I soldered a converter to solve this. Once I succeeded with the electrical connection, I failed in using avrdude &#8211; programming went fine, but I wasn&#8217;t able to set the fuse bits. Finally, I have found <a href="http://esnips.com/doc/097ac1df-278b-4f58-a6e4-740b2ace8397/AvrOspII_400">AvrOspII</a> which worked perfectly on my Windows box. Please read <a href="http://wolfpaulus.com/journal/embedded/arduino2.html">Wolf Paulus&#8217; description</a> to save yourself a lot of time (and broken ATMegas) &#8211; he has written a great article about the fuse settings.</p>
<p>If you&#8217;re interested in a pre-flashed Arduino, send me an email.</p>
<p>PS: picture CC&#8217;ed by opk on <a href="http://flickr.com/photos/opk/57802157/">flickr</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://gonium.net/md/2007/01/23/arduino-on-steroids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I will think before I code&#8230;</title>
		<link>http://gonium.net/md/2006/12/27/i-will-think-before-i-code/</link>
		<comments>http://gonium.net/md/2006/12/27/i-will-think-before-i-code/#comments</comments>
		<pubDate>Wed, 27 Dec 2006 09:54:04 +0000</pubDate>
		<dc:creator>md</dc:creator>
				<category><![CDATA[arduino]]></category>
		<category><![CDATA[digital]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[ATMega]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[interrupt]]></category>
		<category><![CDATA[microcontroller]]></category>

		<guid isPermaLink="false">http://gonium.net/md/2006/12/27/i-will-think-before-i-code/</guid>
		<description><![CDATA[As CosineKitty pointed out: My Arduino timer interrupt code did not work because the Prescaler bits were not set correctly. 



Applying basic boolean logic helps ;-) This is the working code:


#include < avr / interrupt.h >
#include < avr / io.h >

#define INIT_TIMER_COUNT 6
#define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT

int ledPin = 13;
int int_counter = 0;
volatile int second [...]]]></description>
			<content:encoded><![CDATA[As <a href="http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1167000525">CosineKitty</a> pointed out: My <a href="http://gonium.net/md/2006/12/23/arduino-timer-interrupt/">Arduino timer interrupt</a> code did not work because the Prescaler bits were not set correctly. 

<span id="more-33"></span>

Applying basic boolean logic helps ;-) This is the working code:


#include < avr / interrupt.h >
#include < avr / io.h >

#define INIT_TIMER_COUNT 6
#define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT

int ledPin = 13;
int int_counter = 0;
volatile int second = 0;
int oldSecond = 0;
long starttime = 0;

// Aruino runs at 16 Mhz, so we have 1000 Overflows per second...
// 1/ ((16000000 / 64) / 256) = 1 / 1000
ISR(TIMER2_OVF_vect) {
  RESET_TIMER2;
  int_counter += 1;
  if (int_counter == 1000) {
    second+=1;
    int_counter = 0;
  } 
};

void setup() {
  Serial.begin(9600);
  Serial.println("Initializing timerinterrupt");
  //Timer2 Settings: Timer Prescaler /64, 
  TCCR2 |= (1< <CS22);    
  TCCR2 &#038;= ~((1<<CS21) | (1<<CS20));     
  // Use normal mode
  TCCR2 &#038;= ~((1<<WGM21) | (1<<WGM20));  
  // Use internal clock - external clock not used in Arduino
  ASSR |= (0<<AS2);
  //Timer2 Overflow Interrupt Enable
  TIMSK |= (1<<TOIE2) | (0<<OCIE2);  
  RESET_TIMER2;               
  sei();
  starttime = millis();
}

void loop() {
  if (oldSecond != second) {
    Serial.print(second);
    Serial.print(". ->");
    Serial.print(millis() - starttime);
    Serial.println(".");
    digitalWrite(ledPin, HIGH);
    delay(100);
    digitalWrite(ledPin, LOW);
    oldSecond = second;
  }
}


I will think before I code, I will think before I code, I will think before I code, ...

The timer now works perfectly. I think the CTC mode will be more efficient, but my measurement shows that the clock has a slight skew (3 ms) when the Arduino starts up (lets say, during the first five minutes). Later, the skew is about zero. So the overflow mechanism is quite exact ;-)

Note that the TIMER2 is used for PWM in the Arduino libraries, so this sketch might interfere with PWM applications - I did not test this.]]></content:encoded>
			<wfw:commentRss>http://gonium.net/md/2006/12/27/i-will-think-before-i-code/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Arduino Timer Interrupt</title>
		<link>http://gonium.net/md/2006/12/23/arduino-timer-interrupt/</link>
		<comments>http://gonium.net/md/2006/12/23/arduino-timer-interrupt/#comments</comments>
		<pubDate>Sat, 23 Dec 2006 22:12:02 +0000</pubDate>
		<dc:creator>md</dc:creator>
				<category><![CDATA[arduino]]></category>
		<category><![CDATA[digital]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[ATMega]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[microcontroller]]></category>

		<guid isPermaLink="false">http://gonium.net/md/2006/12/23/arduino-timer-interrupt/</guid>
		<description><![CDATA[Continuing my interrupt experiments, I wrote a little sketch to print the seconds since startup to serial. But: Something is wrong&#8230;

I use the Timer2 of the ATMega8. It consists of a 8 bit counter which is automatically increased. When an overflow occurs, the interrupt routine TIMER2_OVF_vect is called.
This is the code:


#include < avr / interrupt.h [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing my interrupt experiments, I wrote a little sketch to print the seconds since startup to serial. But: Something is wrong&#8230;<br />
<span id="more-32"></span><br />
I use the Timer2 of the ATMega8. It consists of a 8 bit counter which is automatically increased. When an overflow occurs, the interrupt routine TIMER2_OVF_vect is called.</p>
<p>This is the code:</p>
<pre>
<code>
#include < avr / interrupt.h >
#include < avr / io.h >

#define INIT_TIMER_COUNT 0
#define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT

int ledPin = 13;
int int_counter = 0;
volatile int second = 0;
int oldSecond = 0;

// Aruino runs at 16 Mhz, so we have 61 Overflows per second...
// 1/ ((16000000 / 1024) / 256) = 1 / 61
ISR(TIMER2_OVF_vect) {
  int_counter += 1;
  if (int_counter == 61) {
    second+=1;
    int_counter = 0;
  }
};

void setup() {
  Serial.begin(9600);
  Serial.println("Initializing timerinterrupt");
  //Timer2 Settings:  Timer Prescaler /1024
  TCCR2 |= ((1 < < CS22) | (1 << CS21) | (1 << CS20));
  //Timer2 Overflow Interrupt Enable
  TIMSK |= (1 << TOIE2);
  RESET_TIMER2;
  sei();
}

void loop() {
  if (oldSecond != second) {
    Serial.print(second);
    Serial.println(".");
    oldSecond = second;
  }
}
</code>
</code></pre>
<p>Unfortunately, the counter is not increased every second but every three seconds. I need to investigate this. Anyway, it seems to be more reasonable to use the CTC mode (clear-timer-on-compare-match). I need to read the datasheet ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://gonium.net/md/2006/12/23/arduino-timer-interrupt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino DCF77 radio clock receiver</title>
		<link>http://gonium.net/md/2006/11/05/arduino-dcf77-radio-clock-receiver/</link>
		<comments>http://gonium.net/md/2006/11/05/arduino-dcf77-radio-clock-receiver/#comments</comments>
		<pubDate>Sun, 05 Nov 2006 20:31:08 +0000</pubDate>
		<dc:creator>md</dc:creator>
				<category><![CDATA[arduino]]></category>
		<category><![CDATA[digital]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[nerdism]]></category>
		<category><![CDATA[ATMega]]></category>
		<category><![CDATA[dcf77]]></category>
		<category><![CDATA[microcontroller]]></category>

		<guid isPermaLink="false">http://gonium.net/md/2006/11/05/arduino-dcf77-radio-clock-receiver/</guid>
		<description><![CDATA[
As a first sketch, I developed a little DCF77 library for the arduino. The DCF77 sender broadcasts the exact time in Germany. It uses a binary format which needs to be decoded &#8211; which is exactly what the library does.

There are others around who wrote a DCF77 decoder: I would like to thank Captain for [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://gonium.net/md/wp-content/uploads/2006/11//DCF77-arduino.jpg" border="0" height="244" width="400" alt="DCF77-arduino.jpg" align="" /></p>
<p>As a first sketch, I developed a little DCF77 library for the arduino. The DCF77 sender broadcasts the exact time in Germany. It uses a binary format which needs to be decoded &#8211; which is exactly what the library does.</p>
<p><span id="more-24"></span></p>
<p>There are others around who wrote a DCF77 decoder: I would like to thank Captain for his <a href="http://www.captain.at/electronic-atmega-dcf77.php">DCF77 code</a>. You need to have an Arduino and a DCF77 receiver in order to use this sketch.</p>
<p>I use the &#8220;DCF-Empf&auml;nger BN 641138&#8243; of Conrad. You need a pull-up resistor as displayed here:</p>
<p><img src="http://gonium.net/md/wp-content/uploads/2006/11//arduino-dcf77-setup.jpg" border="0" height="300" width="400" alt="arduino-dcf77-setup.jpg" align="" /></p>
<p><img src="http://gonium.net/md/wp-content/uploads/2006/11//arduino-dcf77-schematic.jpg" border="0" height="300" width="400" alt="arduino-dcf77-schematic.jpg" align="" /></p>
<p>When everything is connected, the exact time is printed on the serial line. Note that this is a very early release of the software &#8211; there is a lot of functionality missing. From the README:</p>
<pre>
The current todo list is:
 * Use interrupt routines for detecting signal changes
 * Use interrupt routines to add seconds automatically
   (currently, the 59th second is shown properly)
 * Implement parity checks to prevent faulty time
   signals to be evaluated
</pre>
<p>The sketch eats up 6400 of the 7168 bytes in the Arduino. I am currently considering to upgrade my board to the ATMega 168 processor in order to have 16kb of memory&#8230;</p>
<p>You can download the code here:</p>
<ul>
<li><a href="http://gonium.net/md/wp-content/uploads/2006/11//dcf77-arduino-0.1.tar.gz">dcf77-arduino-0.1.tar.gz</a></li>
</ul>
<p><!-- Creative Commons License --><br />
The code is released under terms of the <a href="http://creativecommons.org/licenses/GPL/2.0/">CC-GNU GPL</a>.<br />
<!-- /Creative Commons License --></p>
]]></content:encoded>
			<wfw:commentRss>http://gonium.net/md/2006/11/05/arduino-dcf77-radio-clock-receiver/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>
