<?xml version="1.0" encoding="windows-1252"?>
<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>The Blogging Protagonist &#187; Circuitry</title>
	<atom:link href="http://www.SWHarden.com/blog/category/circuitry/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.SWHarden.com/blog</link>
	<description>A collection of thoughts in technological degradation</description>
	<lastBuildDate>Wed, 12 Oct 2011 02:20:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>I before E except after Hellschreiber</title>
		<link>http://www.SWHarden.com/blog/2011-08-05-i-before-e-except-after-hellschreiber/</link>
		<comments>http://www.SWHarden.com/blog/2011-08-05-i-before-e-except-after-hellschreiber/#comments</comments>
		<pubDate>Fri, 05 Aug 2011 23:52:40 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Circuitry]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Radio]]></category>
		<category><![CDATA[high altitude balloon]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=3055</guid>
		<description><![CDATA[This post describes a project I designed which transmits strings of data from a microcontroller to a PC&#8217;s screen using audio beeping in a special mode called Hellschreiber. Although these days it&#8217;s almost exclusively used by amateur radio operators, I thought it would make a cool microcontroller project! The result can be accomplished with a [...]]]></description>
			<content:encoded><![CDATA[<p><table><tr><td style="text-indent: 25px; background-color: #E5E5E5; padding: 10px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 7px;border-top-style: solid; border-right-style: solid;border-bottom-style: solid;border-left-style: solid;border-top-color: #B5B5B5; border-right-color: #B5B5B5;border-bottom-color: #B5B5B5; border-left-color: #B5B5B5;border-right-width: 1px;background-image: url(http://www.swharden.com/graphics/layout_2006_08_12/quotes.jpg); background-position: left top; background-repeat: no-repeat;">This post describes a project I designed which transmits strings of data from a microcontroller to a PC&#8217;s screen using audio beeping in a special mode called <a href="http://en.wikipedia.org/wiki/Hellschreiber" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">Hellschreiber</a>. Although these days it&#8217;s almost exclusively used by amateur radio operators, I thought it would make a cool microcontroller project! The result can be accomplished with a microcontroller and a speaker as a transmitter and a PC with a microphone as a receiver and decoder, or with actual radio equipment (even toy walkie talkies) by transmitting the tones over modulated radio frequencies for long distance communication! <a href="http://www.amazon.com/Midland-GXT760VP4-36-Mile-42-Channel-Two-Way/dp/B0039YON6Q/ref=sr_1_1?ie=UTF8&#038;qid=1312588647&#038;sr=8-1" onclick="javascript:urchinTracker ('/outbound/article/www.amazon.com');">Ideas anyone?</a></p>
<p><i><b>SPECIAL THANKS:</b> I&#8217;d like to think <a href="http://www.mikeseese.com" onclick="javascript:urchinTracker ('/outbound/article/www.mikeseese.com');">Mike Seese</a> for his brainstorming help in making this project a reality.  <a href="http://www.mikeseese.com" onclick="javascript:urchinTracker ('/outbound/article/www.mikeseese.com');">Mike</a> and I are working on a high altitude balloon project together, and a creative inexpensive radio link is one of our goals. Thanks <a href="http://www.mikeseese.com" onclick="javascript:urchinTracker ('/outbound/article/www.mikeseese.com');">Mike</a>!</i><br />
</td></tr></table></p>
<p><b>As a professional dental student by day and amateur electrical/RF engineer by night, I&#8217;m having a very strange summer.</b> I&#8217;m developing rapidly in my experience and skills in both arenas. I finally feel like I have a working knowledge of most fundamental electrical and radio frequency concepts, and I&#8217;m starting to see patients and do procedures on humans (no more mannequins) in the student dental clinic. For legal and ethical reasons I do not write specifics about what I do with my patients, but I certainly make up for it by documenting the electronic projects I work on! My goals of doing this are to (a) inspire potential electronics tinkerers to come up with new ideas and attack new projects, and (b) receive feedback and insight from those more experienced than me to help me grow in my knowledge. My eye caught <a href="http://www.swharden.com/blog/2011-07-24-frequency-counter-gen2/comment-page-1/#comment-16485" >a comment</a> a few posts ago that made me smile: <i>You have been blessed with talent and the drive to attempt things not been tried before, keep it up, great job. &#8211;David S</i>  While I can&#8217;t claim that everything I do is truly novel or never tried before, I appreciate the encouraging words. Thank you David S!</p>
<p><b>Today&#8217;s project is a fun one involving vintage wartime radio equipment, amateur radio computer software, and a healthy dose of microcontrollers!</b> My goal is to design a single chip Hellschreiber (technically Feldhellschreiber) transmitter. &#8220;Hellschreiber&#8221; translates into English as &#8220;Light Writer&#8221; and is a pun on the name of its inventor, Rudolf Hell, who built the first device in 1920. It was intended to allow messages to be transferred over poor radio links too noisy for intelligible voice or <a href="http://en.wikipedia.org/wiki/Radioteletype" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">radioteletype (RTTY)</a> communication. Its cool factor is upped by the fact that it was sometimes used by the German military in conjunction with the <a href="http://en.wikipedia.org/wiki/Enigma_machine" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">Enigma encryption system</a> during World War 2! [As an aside, RTTY is still pretty sweet and dates back to the mid 1800s! Check out hardware receivers in <a href="http://www.youtube.com/watch?v=mN8pkJoDDfI" onclick="javascript:urchinTracker ('/outbound/article/www.youtube.com');">video 1</a> and <a href="http://www.youtube.com/watch?v=Ml00ngVwrcU" onclick="javascript:urchinTracker ('/outbound/article/www.youtube.com');">video 2</a>]<br />
<iframe width="525" height="393" src="http://www.youtube.com/embed/nXLPUbGYDp4" frameborder="0" allowfullscreen></iframe></p>
<p><b>Seeing a battlefield-ready Hellschreiber receiver gives you a good idea of how it works.</b> (The video isn&#8217;t mine, I found it on youtube.) The concept is relatively simple (shown above), and the receiver has only 2 moving parts. A spinning corkscrew presses a ticker tape into ink when it receives a radio signal. As the radio signal beeps on and off, the corkscrew contacts at different positions at different times, and letters are written on the ticker tape! <a href="http://www.SWHarden.com/blog/images/anaglyph-hell-GL-11.jpg" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/anaglyph-hell-GL-11.jpg" alt="anaglyph-hell-GL-11" title="anaglyph-hell-GL-11" width="300" height="250" class="alignright size-thumbnail wp-image-3074" /></a>The <a href="http://www.nonstopsystems.com/radio/hellschreiber-fonts.htm" onclick="javascript:urchinTracker ('/outbound/article/www.nonstopsystems.com');">designers of these things were extraordinarily creative</a>! The picture on the right shows a Hellschreiber transmitter &#8211; basically a typewriter with mechanical wizardry that turns key presses into a series of radio tones corresponding to the pixelated shape of a character.</p>
<p><b>Almost a century later, people are still sending messages around the world using Hellschreiber!</b> With an <a href="http://en.wikipedia.org/wiki/Amateur_radio" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">amateur radio license</a> and an amateur radio transceiver you can tune around special <a href="http://www.nonstopsystems.com/radio/frank-radio-dig-mode-freqs.htm" onclick="javascript:urchinTracker ('/outbound/article/www.nonstopsystems.com');">Hellschreiber calling frequencies</a> and engage in conversations with other people who enjoy using this unique mode. Computers have modernized the process, allowing you to send Hellschreiber text by typing on your keyboard and receive it by just looking at your screen. My favorite program (free) to do this is Digital Master 780, part of <a href="http://www.ham-radio-deluxe.com/Downloads.aspx" onclick="javascript:urchinTracker ('/outbound/article/www.ham-radio-deluxe.com');">Ham Radio Deluxe</a>.</p>
<p><iframe width="525" height="393" src="http://www.youtube.com/embed/_MJYwXvwTvY" frameborder="0" allowfullscreen></iframe></p>
<p><b>This is the project I just completed.</b> It takes strings of text stored (or dynamically generated) in an array on a microcontroller (I&#8217;m using an ATMega48, but the code is almost identical for any ATMEL AVR microcontroller, and easy adapted for other architectures) and turns it into an audio tone using PWM. This audio tone could be fed into a speaker and a microphone across the room could receive it and use the software to show the received data, or the audio could be fed into a radio transmitter and a PC hooked to the receiver could decode the audio.  Either way, the text in the microcontroller is converted to Hellschreiber audio tones ready to be used however you see fit!  Although I designed it as a resilient way to transmit GPS/altitude data from a high altitude balloon using a small, cheap, low-power radio transmitter, this project is just the foundation of a plethora of potential projects!<br />
<a href="http://www.SWHarden.com/blog/images/DSCN1663.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1663-525x393.jpg" alt="DSCN1663" title="DSCN1663" width="525" height="393" class="alignnone size-medium wp-image-3080" /></a></p>
<p><b>Here&#8217;s the circuit I&#8217;m using.</b> It&#8217;s actually less complicated than shown &#8211; all those yellow wires are going to my AVR programmer! The chip just receives +5V and GND, and the audio is generated automatically and output on the OC0A pin, which happens to be pin 12 on my ATMega48. The output (audio level square waves) is fed to a crystal oscillator <a href="http://www.taydaelectronics.com/servlet/the-709/OSC-dsh-40M-dsh-MEC-dsh-LF-CRYSTAL-OSCILLATOR-40.00/Detail" onclick="javascript:urchinTracker ('/outbound/article/www.taydaelectronics.com');">like this one</a>, which generates square waves with an amplitude equal that to the input. Thus, by audio-frequency AC from the microchip, decoupled through a series capacitor, added to the power supply of the oscillator (provided by the 5V rail through a 1.8k resistor), we effectively produce an amplitude modulated (AM) radio signal!<br />
<a href="http://www.SWHarden.com/blog/images/DSCN1667.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1667-525x393.jpg" alt="DSCN1667" title="DSCN1667" width="525" height="393" class="alignnone size-medium wp-image-3081" /></a></p>
<p><b>This is the receiver I&#8217;m using.</b> I&#8217;m lucky enough to have an all-mode, general-coverage, 100W amateur radio transceiver! It&#8217;s a <a href="http://www.eham.net/reviews/detail/3046" onclick="javascript:urchinTracker ('/outbound/article/www.eham.net');">Yaesu 857-D</a> and I&#8217;m completely in love with it. It&#8217;s quite pricey though! You can find wide coverage receive-only radios called <a href="http://en.wikipedia.org/wiki/Scanner_(radio)" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">radio scanners</a> (or police scanners), often for $20 or so on eBay which would do just as good a job of receiving all sorts of radio signals! Whatever you use, after tuning into the audio with the ham radio delux software, you&#8217;ll be able to decode Hellschreiber like this:<br />
<a href="http://www.SWHarden.com/blog/images/hell.PNG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/hell-525x380.PNG" alt="hell" title="hell" width="525" height="380" class="alignnone size-medium wp-image-3062" /></a></p>
<p><b>A few notes about the code:</b> Each letter is sent twice vertically and I don&#8217;t think I should have done that. It&#8217;s easy enough to correct by eliminating the second FOR loop in the sendChar() function, and doubling the height of the pixels transmitted by changing on(1) and off(1) to on(2) and off(2). Then again, I could be mistaken &#8211; I don&#8217;t use this mode much.  Also, horizontal width of characters (increase this and horizontally compress the received image to reduce the effects of noise) is controlled by a single variable, dynamically adjustable in software. Characters are created from a 3&#215;5 grid (15 bits) and stored as an integer (16 bits, 2 bytes in AVR-GCC). Custom characters are certainly possible! This program takes 16.1% of program space (658 bytes) and 25.4% of data space (130 bytes) and certainly leaves room for optimization.</p>
<pre class="prettyprint c">
// designed for and tested with ATMega48
#include &lt;avr/io.h&gt;
#define F_CPU 8000000UL
#include &lt;avr/delay.h&gt;
#include &lt;avr/interrupt.h&gt;

/*
character format (3x5):
	KFA
	LGB
	MHC
	NID
	OJE

variable format:
	2-byte, 16-bit int 0b0ABCDEFGHIJKLMNO
	(note that the most significant bit is not used)
*/
#define A 	0b0111111010011111
#define B 	0b0010101010111111
#define C	0b0100011000101110
#define D	0b0011101000111111
#define E	0b0100011010111111
#define F	0b0100001010011111
#define G 	0b0100111000101110
#define H	0b0111110010011111
#define I	0b0100011111110001
#define J	0b0111110000100011
#define K	0b0110110010011111
#define L	0b0000010000111111
#define M	0b0111110110011111
#define N	0b0011111000001111
#define O	0b0011101000101110
#define P	0b0010001010011111
#define Q	0b0111011001011110
#define R	0b0010111010011111
#define S	0b0100101010101001
#define T	0b0100001111110000
#define U	0b0111110000111111
#define V	0b0111100000111110
#define W	0b0111110001111111
#define X	0b0110110010011011
#define Y	0b0110000011111000
#define Z	0b0110011010110011
#define n0	0b0111111000111111
#define n1	0b0000011111101001
#define n2	0b0111011010110111
#define n3	0b0111111010110001
#define n4	0b0111110010011100
#define n5	0b0101111010111101
#define n6	0b0101111010111111
#define n7	0b0110001011110000
#define n8	0b0111111010111111
#define n9	0b0111111010111101
#define SP	0b0000000000000000
#define BK	0b0111111111111111
#define SQ	0b0001000111000100
#define PR	0b0000110001100011
#define AR	0b0001000111011111

volatile char width=1; // width of characters, widen to slow speed

#define spd 8300 // synchronization, incr to make it slant upward

void rest(char times){while (times){times--;_delay_us(spd);}}

void on(char restfor){OCR0A=110;rest(restfor);}
void off(char restfor){OCR0A=0;rest(restfor);}

void sendChar(int tosend){
	char w;
	char bit;
	for(w=0;w&lt;width*2;w++){ // left column
		off(1);
		for (bit=0;bit&lt;5;bit++){
				if ((tosend&gt;&gt;bit)&#038;1) {on(1);}
				else {off(1);}
			}
		off(1);
		}
	for(w=0;w&lt;width*2;w++){ // middle column
		off(1);
		for (bit=5;bit&lt;10;bit++){
				if ((tosend&gt;&gt;bit)&#038;1) {on(1);}
				else {off(1);}
			}
		off(1);
		}
	for(w=0;w&lt;width*2;w++){ // right column
		off(1);
		for (bit=10;bit&lt;15;bit++){
				if ((tosend&gt;&gt;bit)&#038;1) {on(1);}
				else {off(1);}
			}
		off(1);
		}
	off(14); // letter space (1 column)
}

// CUSTOMIZE THE MESSAGE, OR GENERATE IT DYNAMICALLY!
int message[]={AR,AR,AR,S,W,H,A,R,D,E,N,PR,C,O,M,SP,R,O,C,K,S,
	SP,AR,AR,AR,SP,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,
	V,W,X,Y,Z,n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,BK,SP};

void sendMessage(){
	char i;
	for(i=0;i&lt;sizeof(message)/2;i++){
		sendChar(message[i]);
	}
}

int main(){ // ### PROGRAM STARTS HERE ###

	// this sets up CPWM in CTC mode,
	// it may be slightly different for other chips
	DDRD|=255; // OC0A is now an output
	TCCR0A=0b01000010; // toggle on match, CTC mode
	TCCR0B=0B00000011; // set prescalar

	for(;;){
		width=1; // fast mode
		sendMessage();
		width=3; // slow mode
		sendMessage();
	}

	return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2011-08-05-i-before-e-except-after-hellschreiber/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>PC/microcontroller &#8220;wireless&#8221; data transfer (part 1)</title>
		<link>http://www.SWHarden.com/blog/2011-07-26-pcmicrocontroller-wireless-data-transfer/</link>
		<comments>http://www.SWHarden.com/blog/2011-07-26-pcmicrocontroller-wireless-data-transfer/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 03:35:16 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Circuitry]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Microcontrollers]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=2992</guid>
		<description><![CDATA[UPDATE! >>> [FINISHED PROJECT HERE]
Several days ago I had a crazy idea. I was driving to Orlando to pick my wife up from the airport and it was dark and stormy on the highway and I was thinking about the backlash I got from my Sound Card Microcontroller/PC Communication project, where I used an embarrassingly [...]]]></description>
			<content:encoded><![CDATA[<p><code>UPDATE!</code> >>> <b><a href="http://www.swharden.com/blog/2011-07-31-pcmicrocontroller-wireless-data-transfer-part-2/" >[FINISHED PROJECT HERE]</a></b></p>
<p><b>Several days ago I had a crazy idea.</b> I was driving to Orlando to pick my wife up from the airport and it was dark and stormy on the highway and I was thinking about the backlash I got from my <a href="http://www.swharden.com/blog/2011-07-09-sound-card-microcontrollerpc-communication/" >Sound Card Microcontroller/PC Communication</a> project, where I used an embarrassingly simple hardware to accomplish the simple task of exchanging a few bytes of data between a PC and microcontroller (in the face of many people who adamantly prefer more complicated &#8220;traditional standard&#8221; methods). The car in front of me drove with his emergency flashers on, and at times all I could see were his lights. At that moment the crazy idea popped in my head &#8211; I wonder if I could use a PC monitor and phototransistors to send data to a microchip? I can&#8217;t think of any immediate uses for this capability, but perhaps if I make a working prototype I&#8217;ll stumble upon some. Either way, it sounds like a fun project!<br />
<a href="http://www.SWHarden.com/blog/images/DSCN1652.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1652-525x393.jpg" alt="DSCN1652" title="DSCN1652" width="525" height="393" class="size-medium wp-image-3021" /></a></p>
<p><b>The circuit is as simple as it gets.</b> <a href="http://www.SWHarden.com/blog/images/PHOTOTRANSISTOR-MICROCONTROLLER-CIRCUIT.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/PHOTOTRANSISTOR-MICROCONTROLLER-CIRCUIT.png" alt="PHOTOTRANSISTOR MICROCONTROLLER CIRCUIT" title="PHOTOTRANSISTOR MICROCONTROLLER CIRCUIT" width="141" height="233" class="alignright size-full wp-image-2993" /></a>A phototransistor is exactly what it says, a photo (light-triggered) transistor (uses small current to trigger a large current). It&#8217;s a <a href="http://en.wikipedia.org/wiki/Photodiode" onclick="javascript:urchinTracker ('/outbound/article/en.wikipedia.org');">photodiode</a> with a small transistor circuit built in. Make sure you give it right polarity when you plug it in! For some reason (likely known to electrical engineers, not dental students) the larger metal piece in the plastic part, which I normally associate as negative for LEDs, should be plugged in the +5V for my photodiode. Again, make sure you hook yours up right. I purchased mine from eBay quite cheaply, but I&#8217;ll bet you can find some in RadioShack.  Note that the value of the 22k resistor is important, and that your needed value may differ from mine. The resistor relates to sensitivity, the larger the value the more sensitive the device is to light. If it&#8217;s too sensitive, it will sense light even when aimed at a black portion of the screen.<br />
<a href="http://www.SWHarden.com/blog/images/hardcode.jpg" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/hardcode-525x104.jpg" alt="hardcode" title="hardcode" width="525" height="104" class="size-medium wp-image-3020" /></a></p>
<p><b>Initial tests were done</b> using the pins as digital inputs. This was difficult to achieve because, even as transistorized photo-diodes, it took a large difference in light to go from 5V to 0V (even past the 2.5V threshold). After a few minutes of frustration, I decided to use ADC to measure the light intensity. I use only the most significant 8 bits (ADCH). I found that in ambient light the readings are 255, and that white monitor light is around 200. Therefore my threshold is 250 (4.88V?) and I use this for logic decisions. Here&#8217;s my setup showing the ADC value of each phototransistor translated into a 1 and 0 for clock (C) and data (D). Both are aimed toward the lamp, so both show a logical 1:<br />
<a href="http://www.SWHarden.com/blog/images/DSCN1651.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1651-525x393.jpg" alt="DSCN1651" title="DSCN1651" width="525" height="393" class="size-medium wp-image-3022" /></a></p>
<p><b>My first test</b> involved reading the data from the image above. The clock is on the bottom line, data is on the top. Every time the clock transitions from black to white, the value of the data at that point is read (white=1, black=0) and the number is placed on a screen.  Here&#8217;s what it looks like in action:<br />
<iframe width="480" height="390" src="http://www.youtube.com/embed/lvVjsMMCx0U" frameborder="0" allowfullscreen></iframe></p>
<p><b>Hopefully soon we can get a JavaScript interface going!</b> Rather than swiping I&#8217;d like to just point this at the screen and let JS flash some squares for my device to read. This will allow virtually unlimited amounts of data to be transferred, albeit slowly, to the micro-controller. Here&#8217;s a preliminary sketch of how to send strings.<br />
<a href="http://www.SWHarden.com/blog/images/string.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/string-525x228.png" alt="string" title="string" width="525" height="228" class="size-medium wp-image-3024" /></a></p>
<p><b>Remember now we&#8217;re using a time domain, not a 2d barcode.</b> I really stink at writing JavaScript, I&#8217;m going to have to pull in some help on this one!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2011-07-26-pcmicrocontroller-wireless-data-transfer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Frequency Counter Gen2</title>
		<link>http://www.SWHarden.com/blog/2011-07-24-frequency-counter-gen2/</link>
		<comments>http://www.SWHarden.com/blog/2011-07-24-frequency-counter-gen2/#comments</comments>
		<pubDate>Sun, 24 Jul 2011 22:07:24 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Circuitry]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Radio]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=3001</guid>
		<description><![CDATA[I&#8217;m working to further simplify my frequency counter design. This one is simpler than my previous design both in hardware and software! Here&#8217;s a video to demonstrate the device in its current state:

I utilize the ATMega48&#8217;s hardware counter which is synchronous with the system clock, so it can only measure frequency less than half of [...]]]></description>
			<content:encoded><![CDATA[<p><b>I&#8217;m working to further simplify my frequency counter design.</b> This one is simpler than <a href="http://www.swharden.com/blog/2011-03-14-frequency-counter-finished/" >my previous design</a> both in hardware and software! Here&#8217;s a video to demonstrate the device in its current state:<br />
<iframe width="480" height="390" src="http://www.youtube.com/embed/FUdxwntNh1c" frameborder="0" allowfullscreen></iframe></p>
<p>I utilize the ATMega48&#8217;s hardware counter which is synchronous with the system clock, so it can only measure frequency less than half of its clock speed. I solve this issue by dividing the input frequency by 8 and clocking the chip at 12mhz. This allows me to measure frequencies up to about 48MHz, but can be easily adapted to measure over 700MHz (really?) by dividing the input by 128. Division occurs by a 74HC590 8-bit counter (not a 74HC595 as I accidentally said in the video, which is actually a common shift register), allowing easy selection of input divided by 1, 2, 4, 8, 16, 32, 64, or 128. The following image shows the o-scope showing the original signal (bottom) and the divided-by-8 result (top)<br />
<a href="http://www.SWHarden.com/blog/images/DSCN1630.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1630-525x393.jpg" alt="DSCN1630" title="DSCN1630" width="525" height="393" class="alignright size-medium wp-image-3002" /></a></p>
<p><b>The device outputs</b> graphically to a LCD simply enough. That LCD is from eBay and is only $3.88 shipped! I&#8217;m considering buying a big box of them and implementing them in many more of my projects. They&#8217;re convenient and sure do look nice!<br />
<a href="http://www.SWHarden.com/blog/images/DSCN1634.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1634-525x393.jpg" alt="DSCN1634" title="DSCN1634" width="525" height="393" class="alignright size-medium wp-image-3003" /></a></p>
<p><b>The signal I test with</b> comes from an oscillator I built several months ago.  It&#8217;s actually a SA612 style receiver whose oscillator is tapped, amplified, and output through a wire. It&#8217;s tunable over almost all of 40m with a varactor diode configuration. It was the start of a transceiver, but I got so much good use out of it as a function generator that I decided to leave it like it is!<br />
<a href="http://www.SWHarden.com/blog/images/DSCN1637.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1637-525x393.jpg" alt="DSCN1637" title="DSCN1637" width="525" height="393" class="alignright size-medium wp-image-3004" /></a></p>
<p><b>THIS IS HOW THE PROGRAM WORKS:</b> I don&#8217;t supply a schematic because it&#8217;s simple as could be. Divide the input frequency to something relatively slow, &lt;1MHz at least.  Configure the 16-bit counter to accept an external pin as the counter source (not a prescaled clock, as I often use in other applications). Then set the timer value to 0, _delay_ms() a certainly amount of time (1/10th second), and read the counter value. Multiply it by 10 to account for the 1/10th second, then multiply it by 8 to account for the divider, and it&#8217;s done! It will update 10 times a second, with a resolution down to 10*8 = 80 Hz. It&#8217;s well within the range of amateur radio uses! If you&#8217;re considering replicating this, read up on how to use hardware counters with ATMEL AVR microcontrollers. That should be enough to get you started! Here&#8217;s the code I used&#8230;</p>
<p>For the LCD, this code requires <a href="http://homepage.hispeed.ch/peterfleury/avr-lcd44780.html" onclick="javascript:urchinTracker ('/outbound/article/homepage.hispeed.ch');">LCD library</a>. </p>
<pre class="prettyprint python">
#include &lt;stdlib.h&gt;
#include &lt;avr/io.h&gt;
#include &lt;avr/pgmspace.h&gt;
#include &lt;util/delay.h&gt;
#include "lcd.h"
#include "lcd.c"

int main(void)
{
	TCCR1B=0b00000111; // rising edge trigger
    char buffer[8];
	long toshow=0;
	char mhz=0;
	int khz=0;
	int hz=0;
    lcd_init(LCD_DISP_ON);
	for(;;){
    	lcd_clrscr();

    	lcd_gotoxy(0,0);
		itoa(mhz , buffer, 10);
		lcd_puts(buffer);
		lcd_puts(".");

		if (khz&lt;100){lcd_puts("0");}
		itoa(khz , buffer, 10);
		lcd_puts(buffer);

		itoa(hz/100 , buffer, 10);
		lcd_puts(buffer);

		lcd_puts(" MHz");

		TCNT1=0;
		_delay_ms(99);
		_delay_us(312);
		toshow=TCNT1;
		toshow=(long)toshow*16*10; // tenth second period
		mhz=toshow/1000000;
		toshow=toshow-mhz*1000000;
		khz=toshow/1000;
		toshow=toshow-khz*1000;
		hz=toshow;
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2011-07-24-frequency-counter-gen2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Half-Hearted DIY Logic Analyzer Works, a Little</title>
		<link>http://www.SWHarden.com/blog/2011-07-16-half-hearted-diy-logic-analyzer-works-a-little/</link>
		<comments>http://www.SWHarden.com/blog/2011-07-16-half-hearted-diy-logic-analyzer-works-a-little/#comments</comments>
		<pubDate>Sun, 17 Jul 2011 03:52:17 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Circuitry]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=2968</guid>
		<description><![CDATA[While trying to attack the problem described in the previous entry, it became clear that a logic analyzer would be necessary.  I thought I&#8217;d try to build one, and my first attempt was so close to being successful, but not quite there.  It records 19 channels (the maximum pins available on the ATMega48 [...]]]></description>
			<content:encoded><![CDATA[<p><b>While trying to attack the problem described in the previous entry,</b> it became clear that a logic analyzer would be necessary.  I thought I&#8217;d try to build one, and my first attempt was so close to being successful, but not quite there.  It records 19 channels (the maximum pins available on the ATMega48 not being occupied by the status LED or USB connection pins) at a rate just under 1,000 samples per second. The USB connection to the PC is obvious, and it utilizes the V-USB project to bit-bang the USB protocol. I&#8217;m posting this in part because some of the comments to my entry two posts ago were disheartening, discouraging, and even down-right viscous!  I made a simple way to send numbers to a PC through the sound card, so what? Don&#8217;t be nasty about it!  Meh, internet people.  Anyway, here&#8217;s a marginally more proper way to send data to a PC with USB and an AVR (logging and interface designed in python), but I&#8217;ll probably still get yelled at for it.</p>
<p><iframe width="480" height="390" src="http://www.youtube.com/embed/TEHF6b5bqj8" frameborder="0" allowfullscreen></iframe></p>
<p><b>As you can see from the video</b>, it&#8217;s good but not good enough. If I could get samples at 2,000 per second I&#8217;d probably be OK, but it&#8217;s just not quite fast enough with it&#8217;s current, ultra-simplistic method of sample recording. I&#8217;ll figure out a fancier way to build a spectrum analyzer &#8211; it&#8217;s obvious the platform is there, it just needs some refinement.</p>
<p><iframe width="480" height="390" src="http://www.youtube.com/embed/chyJ3Fw0mPc" frameborder="0" allowfullscreen></iframe></p>
<p>A few stills:<br />
<a href="http://www.SWHarden.com/blog/images/diy-logic-analyzer-1.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/diy-logic-analyzer-1-525x237.png" alt="diy logic analyzer 1" title="diy logic analyzer 1" width="525" height="237" class="alignnone size-medium wp-image-2969" /></a><br />
<a href="http://www.SWHarden.com/blog/images/diy-logic-analyzer-2.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/diy-logic-analyzer-2-525x239.png" alt="diy logic analyzer 2" title="diy logic analyzer 2" width="525" height="239" class="alignnone size-medium wp-image-2970" /></a></p>
<p><b>UPDATE!</b> The more I think about it, the more I think this might be just good enough to work!  Look at the stagger in those peaks near the top &#8211; that&#8217;s probably the lines telling which character to display. Data between the peaks indicates the value to be provided, and I should have enough time to accurately measure that&#8230; Maybe this is good enough after all? I&#8217;ll have to run some more tests tomorrow&#8230;</p>
<p><b>Where&#8217;s the code?</b> It kills me to do this, but I need to withhold the chip side code. I&#8217;m working on an idiot&#8217;s guide to USB connectivity with AVR microcontrollers, and I&#8217;d rather post the simplest-case code first, then share complicated stuff like this.  I&#8217;ll post the python scripts:</p>
<pre class="prettyprint python">
# LOGIC.PY - this script will log (or print) raw data from the USB device
from optparse import OptionParser
import time
import usb.core
import usb.util
import os

while True:
        print "\nTrying to communicate with the Gator Keyer ...",
        dev = usb.core.find(find_all=True, idVendor=0x16c0, idProduct=0x5dc)
        if len(dev)==0: print "FAIL"
        dev=dev[0]
        dev.set_configuration()
        print "there it is!"
        break

def readVals():
    x=dev.ctrl_transfer(0xC0, 2, 2, 3, 4).tolist()
    return x

def toBinary(desc):
	bits=[]
	for i in range(7,-1,-1):
		if (2**i&gt;desc):
			bits.append('0')
		else:
			bits.append('1')
			desc=desc-2**i
	return bits

def toStr(lists):
	raw=[]
	for port in lists: raw+=toBinary(port)
	return ''.join(raw)

### PROGRAM START ##################
live=False
#live=True
start=time.time()
if live==True:
	while True:
		a,b,c,d=readVals()
		if not a==123: continue #bad data
		elapsed=time.time()-start
		print "%.010f,%s"%(elapsed,toStr([b,c,d]))
else:
	times=0
	data=''
	f=open("out.txt",'a')
	while True:
		a,b,c,d=readVals()
		if not a==123: continue #bad data
		elapsed=time.time()-start
		data+="%.010f,%s\n"%(elapsed,toStr([b,c,d]))
		times+=1
		if times%1000==999:
			print "%d readings / %.02f = %.02f /sec"%(times,elapsed,times/elapsed)
			f.write(data)
			data=""
</pre>
<pre class="prettyprint python">
#logicGraph.py - this will show the data in a pretty way
import matplotlib.pyplot as plt
import numpy

c={
0:"",
1:"",
2:"blk sol",
3:"yel str",
4:"yel sol",
5:"pur sol",
6:"pur str",
7:"",
8:"",
9:"",
10:"blu sol",
11:"blu str",
12:"orn sol",
13:"orn str",
14:"pnk sol",
15:"pnk str",
16:"",
17:"",
18:"",
19:"",
20:"",
21:"",
22:"",
23:"",
24:"",
}

print "loading"
f=open("out.txt")
raw=f.readlines()
f.close()

print "crunching"
times=numpy.array([])
data=numpy.array([])
for line in raw:
	if len(line)&lt;10: continue
	line=line.replace("\n",'').split(',')
	times=numpy.append(times,float(line[0]))
	bits = []
	for bit in line[1]:
		if bit=="1":bits.append(1)
		else:bits.append(0)
	data=numpy.append(data,bits)

columns=24
rows=len(data)/columns
data=numpy.reshape(data,[rows,columns])
print "DONE processing",len(data),"lines\n\n"
print "plotting..."
plt.figure()
plt.grid()
for i in range(len(c.keys())):
	if c[i]=="": continue
	plt.plot(times,data[:,i]+i*1.1,'-',label=c[i])
plt.legend()
plt.show()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2011-07-16-half-hearted-diy-logic-analyzer-works-a-little/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Frequency Counter Hacked to add USB Functionality</title>
		<link>http://www.SWHarden.com/blog/2011-07-11-aj4vd-arsenal-recently-expanded/</link>
		<comments>http://www.SWHarden.com/blog/2011-07-11-aj4vd-arsenal-recently-expanded/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 22:02:33 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[Circuitry]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Microcontrollers]]></category>
		<category><![CDATA[Radio]]></category>

		<guid isPermaLink="false">http://www.SWHarden.com/blog/?p=2943</guid>
		<description><![CDATA[This is a multi-part blog entry added over 2 days of time documenting the progress of the addition of USB to a simple frequency counter. The final result lets me graph frequency over time on the computer, automatically, over days of time if desired. I&#8217;m quite pleased at the result, especially considering so little circuitry [...]]]></description>
			<content:encoded><![CDATA[<p><table><tr><td style="text-indent: 25px; background-color: #E5E5E5; padding: 10px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 7px;border-top-style: solid; border-right-style: solid;border-bottom-style: solid;border-left-style: solid;border-top-color: #B5B5B5; border-right-color: #B5B5B5;border-bottom-color: #B5B5B5; border-left-color: #B5B5B5;border-right-width: 1px;background-image: url(http://www.swharden.com/graphics/layout_2006_08_12/quotes.jpg); background-position: left top; background-repeat: no-repeat;">This is a multi-part blog entry added over 2 days of time documenting the progress of the addition of USB to a simple frequency counter. The final result lets me graph frequency over time on the computer, automatically, over days of time if desired. I&#8217;m quite pleased at the result, especially considering so little circuitry was required! Although this page documents all the way from conception to completion, if you wish you can <a href="#fqcompl">jump straight to the final product</a>.</td></tr></table></p>
<p><b>It looks like this will be a multi-part blog entry.</b> I&#8217;m in the process of figuring out how to add USB functionality to this simple device, which will be a fun way for me to express my creativity and think a bit outside the box while gaining some simple electrical engineering experience! Here&#8217;s the jist of what I&#8217;m planning&#8230;</p>
<p><iframe width="480" height="390" src="http://www.youtube.com/embed/L5ZWWcXklHs" frameborder="0" allowfullscreen></iframe></p>
<p><b>After a brief trip</b> to Orlando to visit family, I decided to stop by the house of one of my neighbors who worked at the same small engineering company I did when I was first starting college (about the time I decided to peruse biology rather than engineering).  I hadn&#8217;t seen him in a while and we talked about various electronics things (he&#8217;s working on an impressive project currently), and before I left he offered me a brown box. &#8220;Do you have any use for a function generator?&#8221; I got excited and said &#8220;sure!&#8221; On closer inspection, it was actually a frequency counter, and he said &#8220;oh well I don&#8217;t need one of those anyway&#8221; and gave it to me. I was ecstatic! Between <a href="http://www.swharden.com/blog/2011-01-28-home-brew-transceiver-taking-shape/" >this post</a>, <a href="http://www.swharden.com/blog/2011-02-04-frequency-counter-working/" >this post</a>, <a href="http://www.swharden.com/blog/2011-02-09-minimal-radio-project-continues/" >this post</a>, <a href="http://www.swharden.com/blog/2011-02-12-wideband-receiver-works/" >this post</a>, and <a href="http://www.swharden.com/blog/2011-03-14-frequency-counter-finished/" >this final project post</a> you can tell that building a frequency counter was really important to me, and that I was never truly satisfied with the result &#8211; it wasn&#8217;t stable to the Hz! I&#8217;m excited to finally have a real counter at my workstation. (It&#8217;s an instek GFC-8010H, 1-120 MHz range.) Now onto figuring out how to build a spectrum analyzer&#8230; X_x<a href="http://www.SWHarden.com/blog/images/after1.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/after1-525x700.jpg" alt="after" title="after" width="525" height="700" class="alignnone size-medium wp-image-2944" /></a></p>
<h3>Update (2 days later)</h3>
<p><b>I never can leave things alone can I?</b> While basking in happiness over this new acquisition I pondered how easy it would be to interface this to a PC. I would like to graph frequency drift over time directly (not using a radio receiver outputting audio which I graph, since the radio is sensitive to drift). Plus this counter allows sample sizes of 10 seconds! That&#8217;s some serious resolution (compared to what I&#8217;m used to at least).  First step to PC interfacing is to see what I&#8217;ve got to work with. I unscrewed the box and snapped some photos of the surprisingly simple device&#8230; I can&#8217;t believe <a href="http://www.amazon.com/Instek-GFC8010H-Frequency-Counter/dp/B000I3VS0A" onclick="javascript:urchinTracker ('/outbound/article/www.amazon.com');">this costs over $175 (as listed on Amazon.com)</a> &#8211; it&#8217;s so simple!<a href="http://www.SWHarden.com/blog/images/DSCN1540.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1540-525x393.jpg" alt="DSCN1540" title="DSCN1540" width="525" height="393" class="alignnone size-medium wp-image-2949" /></a></p>
<p><b>I guess it all makes sense.</b> AC transformer and rectifier diodes with a smoothing capacitor on the bottom left, fed into a 7805 linear voltage regulator, no doubt powering the micro-controller (big IC), logic buffer (small IC), and whatever analog circuitry is under the panel.<a href="http://www.SWHarden.com/blog/images/DSCN1541.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1541-525x393.jpg" alt="DSCN1541" title="DSCN1541" width="525" height="393" class="alignnone size-medium wp-image-2950" /></a></p>
<p><b>I&#8217;m not going to lift the panel</b> because it&#8217;s obvious what&#8217;s under there. Likely some high gain, high distortion amplifier stages to provide a lot of buffering, eventually the input shape is fed to the chip for counting.</p>
<p><b>After posting and thinking about it,</b> the curiosity got to me! I lifted the panel and this is what I found&#8230;<br />
<a href="http://www.SWHarden.com/blog/images/DSCN1552.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1552-525x393.jpg" alt="DSCN1552" title="DSCN1552" width="525" height="393" class="alignnone size-medium wp-image-2956" /></a><br />
<b>There&#8217;s our buffer and wave shaper!</b> The <a href="http://www.onsemi.com/pub_link/Collateral/MC10H116-D.PDF" onclick="javascript:urchinTracker ('/outbound/article/www.onsemi.com');">full datasheet</a> shows it&#8217;s a (triple) line driver. </p>
<p><a href="http://www.SWHarden.com/blog/images/DSCN1544.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1544-525x393.jpg" alt="DSCN1544" title="DSCN1544" width="525" height="393" class="alignnone size-medium wp-image-2951" /></a></p>
<p><b>Come to think of it,</b> I&#8217;m not entirely sure about that smaller IC.  It&#8217;s a 74HC00N, quad NAND gate. Knee-jerk was to say it was used for dividing-down the frequency, but that&#8217;s silly since it takes 2 NAND gates to make a flip flop, and that chip would be only 2 flip flops (/4), and there are flip flip chips for all that.  Perhaps this has something to do with the buttons on the front panel? Perhaps something to do with square-shaping the oscillator with the 10mhz crystal? The big GFC 9701-1 IC seems to be a custom counter chip used in many Instek products. Here&#8217;s a blurb from a page of their manual for a function generator they make: </p>
<p><table><tr><td style="text-indent: 25px; background-color: #E5E5E5; padding: 10px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 7px;border-top-style: solid; border-right-style: solid;border-bottom-style: solid;border-left-style: solid;border-top-color: #B5B5B5; border-right-color: #B5B5B5;border-bottom-color: #B5B5B5; border-left-color: #B5B5B5;border-right-width: 1px;background-image: url(http://www.swharden.com/graphics/layout_2006_08_12/quotes.jpg); background-position: left top; background-repeat: no-repeat;">The most important function of the internal counter is to show the main frequency on the display. So we take a square signal from the square shaper and change the level to TTL compatible level with a TTL shaper block (is this the role of that NAND gate?) then the signal will connect with the counter GFC-9701. Because the counter directly connects with the MPU system, the MPU can get correct frequency and show it on the display.</td></tr></table></p>
<p><b>So, it seems</b> that chip is already outputting data ready to go into a CPU. I wonder if it&#8217;s outputting some type of data on an unused pin, ripe for the picking? I can&#8217;t find more ICs in this device, so it&#8217;s possible no other MCU is driving the display, and this counter IC is doing that all on its own. Bah, again curiosity is getting the best of me&#8230; [unscrews front panel]<br />
<a href="http://www.SWHarden.com/blog/images/DSCN1560.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1560-525x393.jpg" alt="DSCN1560" title="DSCN1560" width="525" height="393" class="alignnone size-medium wp-image-2958" /></a><br />
<b>More ICs!</b> I couldn&#8217;t see them well before so I&#8217;m glad I opened up the display. The ULN2003A is a 7 channel darlington array, x2 = 14 darlingtons. The CD4511 is a common 7-segment driver &#8211; BINGO! If I&#8217;m going to interface this device by intercepting the display, this is the way to do it!  The darlingtons tell me which character is selected, and the input of this chip tells me the value to be displayed. Pow!<br />
<a href="http://www.SWHarden.com/blog/images/xray_circuit.jpg" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/xray_circuit-525x350.jpg" alt="xray_circuit" title="xray_circuit" width="525" height="350" class="alignnone size-medium wp-image-2960" /></a></p>
<p><b>Let&#8217;s take a closer look at that main chip again&#8230;</b> X-RAY VISION TIME! I used Image-J to extract the red channel of the image and increased contrast, inverted, then used a 10 pixel wide unsharp mask with 0.8 weight to bring-out the leads. I guess I could have just unscrewed it and looked at the bottom, but where&#8217;s the fun in that? I imagine the top left pin is input of frequency. The bottom left pins go to buttons on the front, so they&#8217;re for front panel input. The headers on the right go to the front panel display. The pin going to the smaller IC must be the clock input, so that NAND gate DOES do something with shaping the input clock signal. On the top fight of the image you can see the crystal connecting to that gate. The trace going in the center of the chip on top is probably +5V supply for the chip. I&#8217;m not sure about much else, and I don&#8217;t feel like poking around with a continuity meter right now. UPDATE &#8211; I tested each pin with an analog o-scope. I found that pin 6 (unconnected) outputs a burst of data every time the display updates &#8211; this is my data line! If I had a logic analyzer I&#8217;d know how to read it&#8230; BAH!<br />
<a href="http://www.SWHarden.com/blog/images/DSCN1547.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1547-525x393.jpg" alt="DSCN1547" title="DSCN1547" width="525" height="393" class="alignnone size-medium wp-image-2952" /></a><br />
<b>What&#8217;s this?!</b> The voltage regulator with its hefty heat sink (which obviously gets quite warm) is attached to a 10.000 MHz crystal!  Is this the time base crystal? Doesn&#8217;t accuracy depend on thermostability of this crystal? It&#8217;s not just near it &#8211; it&#8217;s physically connected with it through metal! Does this imply that a loaded 7805 voltage regulator produces heat more steadily, and with a final temperature more stable than room air in a plastic enclosure??</p>
<p><b>update:</b> The following was emailed to me in response to this puzzling issue. It&#8217;s from my good friend Bill!</p>
<p><table><tr><td style="text-indent: 25px; background-color: #E5E5E5; padding: 10px; border-top-width: 1px; border-bottom-width: 1px; border-left-width: 7px;border-top-style: solid; border-right-style: solid;border-bottom-style: solid;border-left-style: solid;border-top-color: #B5B5B5; border-right-color: #B5B5B5;border-bottom-color: #B5B5B5; border-left-color: #B5B5B5;border-right-width: 1px;background-image: url(http://www.swharden.com/graphics/layout_2006_08_12/quotes.jpg); background-position: left top; background-repeat: no-repeat;"><i>It may be an SC-cut crystal which is the best type for precision oscillators because the turn around inflection occurs at a much broader temperature range than the regular AT-cut, el cheapo types we often use.  SC types, if carefully selected, can remain within a fraction of a ppm over a temperature range to 10 to 20 C.  The turn around point temperature is pretty high,  about 90 C, compared to around 25C for the at-cut. So, my guess is that the 7805 provides this really high temperature to the xtal and can be trusted to not vary by more than a few degrees, particularly in a laboratory environment.</i> &#8211;Bill (W4HBK)</td></tr></table></p>
<p><i>Afterthought: This would make one hell of a huff-and-puff oscillator!</i><br />
<a name="fqcompl"></a></p>
<h2>PROJECT COMPLETED!</h2>
<p><b>I&#8217;m quite excited</b>, the end product works wonderfully! It looks pretty spiffy too!</p>
<p><a href="http://www.SWHarden.com/blog/images/DSCN1580.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1580-150x112.jpg" alt="DSCN1580" title="DSCN1580" width="150" height="112" class="alignnone size-thumbnail wp-image-2988" /></a> <a href="http://www.SWHarden.com/blog/images/DSCN1585.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1585-150x112.jpg" alt="DSCN1585" title="DSCN1585" width="150" height="112" class="alignnone size-thumbnail wp-image-2989" /></a></p>
<p><a href="http://www.SWHarden.com/blog/images/DSCN1605.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1605-150x112.jpg" alt="DSCN1605" title="DSCN1605" width="150" height="112" class="alignnone size-thumbnail wp-image-2977" /></a> <a href="http://www.SWHarden.com/blog/images/DSCN1603.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1603-150x112.jpg" alt="DSCN1603" title="DSCN1603" width="150" height="112" class="alignnone size-thumbnail wp-image-2978" /></a> </p>
<p><a href="http://www.SWHarden.com/blog/images/DSCN1609.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1609-150x112.jpg" alt="DSCN1609" title="DSCN1609" width="150" height="112" class="alignnone size-thumbnail wp-image-2979" /></a> <a href="http://www.SWHarden.com/blog/images/DSCN1610.JPG" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/DSCN1610-150x112.jpg" alt="DSCN1610" title="DSCN1610" width="150" height="112" class="alignnone size-thumbnail wp-image-2980" /></a></p>
<p><b>Here&#8217;s some video</b> showing the device at work!</p>
<p><iframe width="480" height="390" src="http://www.youtube.com/embed/c6uFN52LGnc" frameborder="0" allowfullscreen></iframe></p>
<p>Of course Python and MatPlotLib can graph it:<br />
<a href="http://www.SWHarden.com/blog/images/usb-frequency-counter-hack2.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/usb-frequency-counter-hack2-525x399.png" alt="usb frequency counter hack2" title="usb frequency counter hack2" width="525" height="399" class="alignnone size-medium wp-image-2981" /></a></p>
<p>&#8230; but so can Excel!<br />
<a href="http://www.SWHarden.com/blog/images/usb-frequency-counter-hack.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/usb-frequency-counter-hack-525x394.png" alt="usb frequency counter hack" title="usb frequency counter hack" width="525" height="394" class="alignnone size-medium wp-image-2982" /></a></p>
<p><b>UPDATE</b> Oops, I forgot to remove the trailing zero. That&#8217;s 9.9 MHz, not 99 MHz.  That&#8217;s easy enough to do later, so I&#8217;m not going to fix it and re-post updated images. Don&#8217;t email me about it, I know ^_^</p>
<p><b>UPDATE 2</b> Here&#8217;s some useful data! I hooked up a canned oscillator at 3.57 something MHz (very stable) and watched it as my frequency counter warmed up. The result showed that the counter takes about 2 hours to warm up!!! he shift is only about 15 Hz over 2 hours, but still it&#8217;s good to know.<br />
<a href="http://www.SWHarden.com/blog/images/warmup1.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/warmup1-525x396.png" alt="warmup1" title="warmup1" width="525" height="396" class="size-medium wp-image-3011" /></a></p>
<p>Once it&#8217;s warm, it&#8217;s stable!<br />
<a href="http://www.SWHarden.com/blog/images/warm.png" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/warm-525x396.png" alt="warm" title="warm" width="525" height="396" class="size-medium wp-image-3012" /></a></p>
<h2>Schematic</h2>
<p>This device is very simple and specialized for my use and I have not designed a custom schematic. USB functionality is as recommended by V-USB, similar to:<br />
<a href="http://www.SWHarden.com/blog/images/circuit-zoomed.gif" onclick="javascript:urchinTracker ('/outbound/article/www.SWHarden.com');"><img src="http://www.SWHarden.com/blog/images/circuit-zoomed.gif" alt="circuit-zoomed" title="circuit-zoomed" width="362" height="194" class="size-full wp-image-3013" /></a> </p>
<p>For more information on the USB circuitry, view the <a href="http://vusb.wikidot.com/hardware" onclick="javascript:urchinTracker ('/outbound/article/vusb.wikidot.com');">hardware considerations page</a> relating to the <a href="http://www.obdev.at/products/vusb/index.html" onclick="javascript:urchinTracker ('/outbound/article/www.obdev.at');">V-USB project</a>.</p>
<h2>CODE</h2>
<p><b>Microcontroller code &#8211; </b> Although it&#8217;s hard for me, I really don&#8217;t think I can release this right now. I&#8217;m working on an idiot&#8217;s guide to USB connectivity with ATMEL microcontrollers, and it would cause quite a stir to post that code too early. It&#8217;ll be shared soon! Here are the python scripts for the logging and for the graphing:</p>
<pre class="prettyprint python">
#This code polls the USB device and displays/logs frequency
from optparse import OptionParser
import time
import usb.core
import usb.util
import os

while True:
        print "\nTrying to communicate with the Gator Keyer ...",
        dev = usb.core.find(find_all=True, idVendor=0x16c0, idProduct=0x5dc)
        if len(dev)==0: print "FAIL"
        dev=dev[0]
        dev.set_configuration()
        print "there it is!"
        break

def readVals(c):
	x=dev.ctrl_transfer(0xC0, 3, c,4,4).tolist()
	val=x[0]
	if val&gt;9: val=0
	return val

def readDisp():
	c=[]
	for i in range(1,9):
		val=readVals(i)
		c.append(val)
		#print "char",i,"=",val
	disp="%d%d%d%d%d%d%d%d"%(c[0],c[1],c[2],c[5],c[6],c[3],c[4],c[7])
	return disp

def readFreq():
	i=0
	first=readDisp()
	while True:
		if first==readDisp():
			i+=1
			if i==5: break #we're good!
		else: #FAIL! start over...
			i=0
			first=readDisp()
	return first

### PROGRAM START ##################	

start=time.time()
while True:
	line="%.02f,%s"%(time.time()-start,readFreq())
	print line
	f=open("freq.csv",'a')
	f.write(line+"\n")
	f.close()
	time.sleep(1)
</pre>
<pre class="prettyprint python">
#This code reads the log file and graphs it with matplotlib
import matplotlib.pyplot as plt
import numpy

print "loading"
f=open("freq.csv")
raw=f.readlines()
f.close()

print raw

print "crunching"
times=numpy.array([])
data=numpy.array([])
for line in raw:
	if len(line)&lt;10: continue
	line=line.replace("\n",'').split(',')
	times=numpy.append(times,float(line[0]))
	data=numpy.append(data,float(line[1]))

#data=data/1000000.0
print times, data
print "DONE processing",len(data),"lines\n\n"
print "plotting..."
plt.figure()
plt.grid()
plt.plot(times,data,'-')
plt.plot(times,data,'.')
plt.show()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.SWHarden.com/blog/2011-07-11-aj4vd-arsenal-recently-expanded/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

