The personal website of Scott W Harden
May 30th, 2009

Prime Number Generator Prototype

In my quest to build a hardware-based prime number generator I built a rapid prototype to assess how quickly primes can be found with an 8-bit microcontroller. There is a lot of room for improvement, but the code works. Instead of messing with tons of little LEDs, this design displays numbers on an LCD. Interestingly the library to run the LCD takes up about 90% of the memory of the chip leaving only a handful of bytes to write the prime calculation code in!

#define F_CPU 1E6
#include <stdlib.h>
#include <avr/io.h>
#include <math.h>
#include <util/delay.h>
#include "lcd.h"
#include "lcd.c"

const unsigned long int primeMax=pow(2,25);
unsigned long int primeLast=2;
unsigned long int primeTest=0;
unsigned int primeDivy=0;

void wait(void);
void init(void);
void updateDisplay(void);
char *toString(unsigned long int);

int main(void){
    init();
    short maybePrime;
    unsigned int i;
    for(primeTest=2;primeTest<sqrt(primeMax);primeTest++){
        maybePrime=1;
        for (i=2;i<=(sqrt(primeTest)+1);i++){
            primeDivy=i;
            updateDisplay();
            if (primeTest%primeDivy==0){maybePrime=0;break;}
        }
        if (maybePrime==1){primeLast=primeTest;updateDisplay();}
    }
    return 0;
}

void updateDisplay(void){
    lcd_gotoxy(12,0);lcd_puts(toString(primeLast));
    lcd_gotoxy(5,1);lcd_puts(toString(primeTest));
    lcd_gotoxy(16,1);lcd_puts(toString(primeDivy));
    return;
}

void init(void){
    lcd_init(LCD_DISP_ON);
    lcd_puts("PRIME IDENTIFICATIONn");
    _delay_ms(2000);
    lcd_clrscr();
    lcd_puts("LAST PRIME:n");
    lcd_puts("TRY:");
    lcd_gotoxy(14,1);lcd_puts("/");
    return;
}

char *toString(unsigned long int x){
    char s1[8];
    ltoa(x,s1,10);
    return s1;
}
Markdown source code last modified on January 18th, 2021
---
title: Prime Number Generator Prototype
date: 2009-05-30 18:22:58
tags: microcontroller, old
---

# Prime Number Generator Prototype

<div class="text-center img-border">

[![](img_1984_thumb.jpg)](img_1984.jpg)

</div>

__In my quest to build a hardware-based prime number generator__ I built a rapid prototype to assess how quickly primes can be found with an 8-bit microcontroller. There is a lot of room for improvement, but the code works. Instead of messing with tons of little LEDs, this design displays numbers on an LCD. Interestingly the library to run the LCD takes up about 90% of the memory of the chip leaving only a handful of bytes to write the prime calculation code in!

<div class="text-center img-border">

![](https://www.youtube.com/embed/F5IkXSKWwXQ)

</div>

```c
#define F_CPU 1E6
#include <stdlib.h>
#include <avr/io.h>
#include <math.h>
#include <util/delay.h>
#include "lcd.h"
#include "lcd.c"

const unsigned long int primeMax=pow(2,25);
unsigned long int primeLast=2;
unsigned long int primeTest=0;
unsigned int primeDivy=0;

void wait(void);
void init(void);
void updateDisplay(void);
char *toString(unsigned long int);

int main(void){
    init();
    short maybePrime;
    unsigned int i;
    for(primeTest=2;primeTest<sqrt(primeMax);primeTest++){
        maybePrime=1;
        for (i=2;i<=(sqrt(primeTest)+1);i++){
            primeDivy=i;
            updateDisplay();
            if (primeTest%primeDivy==0){maybePrime=0;break;}
        }
        if (maybePrime==1){primeLast=primeTest;updateDisplay();}
    }
    return 0;
}

void updateDisplay(void){
    lcd_gotoxy(12,0);lcd_puts(toString(primeLast));
    lcd_gotoxy(5,1);lcd_puts(toString(primeTest));
    lcd_gotoxy(16,1);lcd_puts(toString(primeDivy));
    return;
}

void init(void){
    lcd_init(LCD_DISP_ON);
    lcd_puts("PRIME IDENTIFICATIONn");
    _delay_ms(2000);
    lcd_clrscr();
    lcd_puts("LAST PRIME:n");
    lcd_puts("TRY:");
    lcd_gotoxy(14,1);lcd_puts("/");
    return;
}

char *toString(unsigned long int x){
    char s1[8];
    ltoa(x,s1,10);
    return s1;
}
```

May 19th, 2009

Audio and Video on an ATMega88 Microcontroller!

At least 99% of my blog entries contain original content I created. However, I was so impressed by something I stumbled upon tonight that I absolutely cannot resist sharing it. It's a project which aims to output audio and video simultaneously from a single microcontroller. The author's site has all the details, but if you watch the video below you'll be amazed. (Just get through the 30 second narration at the beginning) Apparently the guy rendered video in horizontal lines from the software and outputted audio signals between horizontal lines! Amazing!

On second thought, this was no big deal in the 80's, so why am I so impressed by it now? The 8-bit microcontrollers this guy is programming is likely on par with the PCs of the 80's. I guess that in the 70's this would have been amazing because it was cutting edge. In the 80's this would have been boring because it was commonplace. In the 2000's, this is amazing because no one in my generation is old enough to remember how amazing this was in the 70's and 80's!

After researching some similar projects I realized I'm becoming fascinated with chiptune synthesizing code, hardware, and music. It's basically a type of code to tell a synthesizer how to synthesize the music, rather than having it play pre-recorded music. It's like a merge of a programming language and MIDI. For non-technical people, it's like giving a microchip the sheet music for all the different instruments of an orchestra and having the microchip play everything from the sheet music, rather than giving it a CD to play. Here's some video of a PC-based front-end to the audio creation process. Notice how each line represents a time, and how certain codes in certain channels represent notes (hence the MIDI aspect). Numbers on the far right represent the location of the memory, and notice also how it goes back and forth, replaying certain areas when necessary (to safe space, hence the coding aspect).

I can't describe my emotional state right now. It's like I have an extreme nostalgia for an era I never even lived in. This chip level audio synthesis stuff sounds amazingly fun to me. (I've already bookmarked nolife-radio.com and 8bitFM.com) I feel drawn toward it... but I'm scared to get sucked in. I wish I were a college student in the 80's studying electrical engineering. Here I am, having just gotten a master's in molecular biology and microbiology, and I feel like I wasted six years of my life in the process. I'm about to start dental school in August. Hopefully when I look back from the future I won't feel like I wasted another four years doing that.

Either way, I have an endless supply of possible projects to do this summer (not even going into the small list of projects I'm trying/expected to complete in the cardioneurophysiology lab I work in). I feel like I'm running out of time. I start dental school in August, and I dread the date. Not necessarily because I expect it to be difficult, but because I feel [however illogical, irrational, or ridiculous] that I'm actually doing something significant, working with my hands and working with my brain to do things that [almost] no one has done before, and doing things in a way that no one has ever thought of doing them. I feel like when I start resume classes, it's another four years of people telling me how I should do things so I can be exactly like everyone else. How can you exercise creativity as a dental student? I'm sure there are ways, but it's certainly leagues away from the projects engineering college students work on. As far as the career goes, if you're an engineer the best case scenario is that you do something no one has ever done before. If you're a dentist, the best case scenario is to do things exactly as everyone else does them. Maybe I'll go crazy and change the wallpaper in my office every few months.

Markdown source code last modified on January 18th, 2021
---
title: Audio and Video on an ATMega88 Microcontroller
date: 2009-05-19 20:49:40
tags: microcontroller
---

# Audio and Video on an ATMega88 Microcontroller!

__At least 99% of my blog entries contain original content I created.__  However, I was so impressed by something I stumbled upon tonight that I absolutely cannot resist sharing it.  It's a project which aims to output audio and video simultaneously from a single microcontroller.  The [author's site](http://www.linusakesson.net/scene/craft/index.php) has all the details, but if you watch the video below you'll be amazed.  (Just get through the 30 second narration at the beginning)  Apparently the guy rendered video in horizontal lines from the software and outputted audio signals between horizontal lines!  Amazing!

![](https://www.youtube.com/embed/sNCqrylNY-0)

__On second thought,__ this was no big deal in the 80's, so why am I so impressed by it now?  The 8-bit microcontrollers this guy is programming is likely on par with the PCs of the 80's.  I guess that in the 70's this would have been amazing because it was cutting edge.  In the 80's this would have been boring because it was commonplace.  In the 2000's, this is amazing because no one in my generation is old enough to remember how amazing this was in the 70's and 80's!

__After researching some similar projects__ I realized I'm becoming fascinated with [chiptune](http://en.wikipedia.org/wiki/Chiptune) synthesizing code, hardware, and music.  It's basically a type of code to tell a synthesizer how to synthesize the music, rather than having it play pre-recorded music.  It's like a merge of a programming language and MIDI.  For non-technical people, it's like giving a microchip the sheet music for all the different instruments of an orchestra and having the microchip play everything from the sheet music, rather than giving it a CD to play.  Here's some video of a PC-based front-end to the audio creation process. Notice how each line represents a time, and how certain codes in certain channels represent notes (hence the MIDI aspect).  Numbers on the far right represent the location of the memory, and notice also how it goes back and forth, replaying certain areas when necessary (to safe space, hence the coding aspect).

![](https://www.youtube.com/embed/17FmzHk_v0g)

__I can't describe my emotional state right now. It's like I have an extreme nostalgia for an era I never even lived in.__  This chip level audio synthesis stuff sounds amazingly fun to me.  (I've already bookmarked [nolife-radio.com](http://nolife-radio.com/) and [8bitFM.com](http://www.8bitfm.com/)) I feel drawn toward it... but I'm scared to get sucked in. I wish I were a college student in the 80's studying electrical engineering. Here I am, having just gotten a master's in molecular biology and microbiology, and I feel like I wasted six years of my life in the process. I'm about to start dental school in August. Hopefully when I look back from the future I won't feel like I wasted another four years doing _that_.

__Either way, I have an endless supply__ of possible projects to do this summer (not even going into the small list of projects I'm trying/expected to complete in the cardioneurophysiology lab I work in).  I feel like I'm running out of time.  I start dental school in August, and I dread the date.  Not necessarily because I expect it to be difficult, but because I feel [however illogical, irrational, or ridiculous] that I'm actually doing something _significant_, working with my hands and working with my brain to do things that [almost] no one has done before, and doing things in a way that no one has ever thought of doing them.  I feel like when I start resume classes, it's another four years of people telling me how I should do things so I can be exactly like everyone else.  How can you exercise creativity as a dental student? I'm sure there are ways, but it's certainly leagues away from the projects engineering college students work on. As far as the career goes, if you're an engineer the best case scenario is that you do something no one has ever done before.  If you're a dentist, the best case scenario is to do things exactly as everyone else does them.  Maybe I'll go crazy and change the wallpaper in my office every few months.
May 14th, 2009

Simple Case AVR/PC Serial Communication via MAX232

I recently had the desire to be able to see data from an ATMEL AVR microcontroller (the ATTiny2313) for development and debugging purposes. I wanted an easy way to have my microcontroller talk to my PC (and vise versa) with a minimum number of parts. The easiest way to do this was to utilize the UART capabilities of the ATTiny2313 to talk to my PC through the serial port. One problem is that the ATTiny2313(as with most microcontrollers) puts out 5V for "high" (on) and 0V for "low" (off). The RS-232 standard (which PC serial ports use) required -15V for high and +15v for low! Obviously the microcontroller needs some help to achieve this. The easiest way was to use the MAX232 serial level converter which costs about 3 bucks at DigiKey. Note that it requires a few 10uF capacitors to function properly.

Here's a more general schematic:

I connected my ATTiny2313 to the MAX232 in a very standard way. (photo) MAX232 pins 13 and 14 go to the serial port, and the ATTiny2313 pins 2 and 3 go to the MAX232 pins 12 and 11 respectively. I will note that they used a oscillator value (3.6864MHz) different than mine (9.216MHz).

Determining the speed of serial communication is important. This is dependent on your oscillator frequency! I said I used a 9.216Mhz oscillator. First, a crystal or ceramic oscillator is required over the internal RC oscillator because the internal RC oscillator is not accurate enough for serial communication. The oscillator you select should be a perfect multiple of 1.8432MHz. Mine is 5x this value. Many people use 2x this value (3.6864Mhz) and that's okay! You just have to make sure your microchip knows (1) to use the external oscillator (google around for how to burn the fuses on your chip to do this) and (2) what the frequency of your oscillator is and how fast it should be sending data. This is done by setting the UBRRL value. The formula to do this is here:

The datasheet of your microcontroller may list a lot of common crystal frequencies, bandwidths, and their appropriate UBRR values. However my datasheet lacked an entry for a 9.216MHz crystal, so I had to do the math myself. I Googled around and no "table" is available! Why not make one? (picture, below). Anyway, for my case I determined that if I set the UBRR value to 239, I could transmit data at 2800 baud (bits/second). This is slow enough to ensure accuracy, but fast enough to quickly dump a large amount of text to a PC terminal.

AVR Baud Calculator

This will make your life easier. The page wormfood.net/avrbaudcalc.php has a chart of common crystals and the baud rates they work best with! Try to pick a combination that provides the least error possible...

This is the bare-minimum code to test out my setup. Just load the code (written in C, compiled with avr-gcc) onto your chip and it's ready to go. Be sure you set your fuses to use an external oscillator and that you set your UBRRL value correctly.

#include <avr/io.h>  
#include <avr/interrupt.h>  
#include <util/delay.h>  

int main (void)  
{  
  unsigned char data=0;  
  UBRRL = 239;  
  UCSRB = (1 < < RXEN) | (1 << TXEN);  
  UCSRC = (1 < < UCSZ1) | (1 << UCSZ0);  

  for (;;)  
  {  
    if (data>'Z'||data< 'A')  
    {  
      UDR = 10; UDR = 13; data='A';_delay_ms(100);  
    }  

    UDR = data;  
    data += 1;  
    _delay_ms(100);  
  }  
}  

Once you load it, it's ready to roll! It continuously dumps letters to the serial port. To receive them, open HyperTerminal (on windows, under accessories) or minicom (on Linux, look it up!). Set your baud rate to 2800 (or whatever you selected) and you're in business. This (picture below) is the output of the microcontroller to HyperTerminal on my PC. Forgive the image quality, I photographed the LCD screen instead of taking a screenshot.

This is the circuit which generates the output of the previous image. I have a few extra components. I have an LED which I used for debugging purposes, and also a switch (labeled "R"). The switch (when pressed) grounds pin 1 of the ATTiny2313 which resets it. If I want to program the chip, I hold "R" down and the PC can program it with the inline programmer "parallel port, straight-through, DAPA style). One cable going into the circuit is for the parallel port programmer, one cable is for the serial port (data transfer), and one is for power (5v which I stole from a USB port).

I hope you found this information useful. Feel free to contact me with any questions you may have, but realize that I'm no expert, and I'm merely documenting my successes chronologically on this website.

Markdown source code last modified on January 18th, 2021
---
title: Simple Case AVR/PC Serial Communication via MAX232
date: 2009-05-14 11:00:19
tags: microcontroller, circuit, old
---

# Simple Case AVR/PC Serial Communication via MAX232

__I recently had the desire__ to be able to see data from an ATMEL AVR microcontroller (the [ATTiny2313](http://www.SWHarden.com/blog/images/attiny-2313.gif)) for development and debugging purposes.  I wanted an easy way to have my microcontroller talk to my PC (and vise versa) with a minimum number of parts.  The easiest way to do this was to utilize the [UART](http://en.wikipedia.org/wiki/UART) capabilities of the [ATTiny2313](http://www.SWHarden.com/blog/images/attiny-2313.gif) to talk to my PC through the serial port. One problem is that the [ATTiny2313](http://www.SWHarden.com/blog/images/attiny-2313.gif)(as with most microcontrollers) puts out 5V for "high" (on) and 0V for "low" (off).  The RS-232 standard (which PC serial ports use) required -15V for high and +15v for low!  Obviously the microcontroller needs some help to achieve this.  The easiest way was to use the [MAX232 serial level converter](http://en.wikipedia.org/wiki/MAX232) which [costs about 3 bucks at DigiKey](http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&amp;name=MAX232CPE%2B-ND). Note that it requires a few 10uF capacitors to function properly.

<div class="text-center img-border">

[![](serialcircuit_thumb.jpg)](serialcircuit.png)

</div>

__Here's a more general schematic:__


<div class="text-center">

![](max232_serial_microcontroller.gif)

</div>

__I connected my ATTiny2313 to the MAX232__ in a very standard way. (photo)   MAX232 pins 13 and 14 go to the serial port, and the ATTiny2313 pins 2 and 3 go to the MAX232 pins 12 and 11 respectively.  I will note that they used a oscillator value (3.6864MHz) different than mine (9.216MHz).

__Determining the speed of serial communication__ is important.  This is dependent on your oscillator frequency!  I said I used a 9.216Mhz oscillator.  First, a crystal or ceramic oscillator is required over the internal RC oscillator because the internal RC oscillator is not accurate enough for serial communication.  The oscillator you select should be a perfect multiple of 1.8432MHz. Mine is 5x this value.  Many people use 2x this value (3.6864Mhz) and that's okay!  You just have to make sure your microchip knows (1) to use the external oscillator (google around for how to burn the fuses on your chip to do this) and (2) what the frequency of your oscillator is and how fast it should be sending data.  This is done by setting the UBRRL value.  The formula to do this is here:

<div class="text-center">

![](ubrrformula.gif)

</div>

__The datasheet of your microcontroller__ may list a lot of common crystal frequencies, bandwidths, and their appropriate UBRR values.  However my datasheet lacked an entry for a 9.216MHz crystal, so I had to do the math myself.  I Googled around and no "table" is available!  Why not make one? (picture, below).  Anyway, for my case I determined that if I set the UBRR value to 239, I could transmit data at 2800 baud (bits/second).  This is slow enough to ensure accuracy, but fast enough to quickly dump a large amount of text to a PC terminal.

<div class="text-center">

![](ubrr-table.gif)

</div>

## AVR Baud Calculator

This will make your life easier. The page <a href="http://www.wormfood.net/avrbaudcalc.php">wormfood.net/avrbaudcalc.php</a> has a chart of common crystals and the baud rates they work best with! Try to pick a combination that provides the least error possible...

__This is the bare-minimum code__ to test out my setup. Just load the code (written in C, compiled with avr-gcc) onto your chip and it's ready to go.  Be sure you set your fuses to use an external oscillator and that you set your UBRRL value correctly.

```c
#include <avr/io.h>  
#include <avr/interrupt.h>  
#include <util/delay.h>  

int main (void)  
{  
  unsigned char data=0;  
  UBRRL = 239;  
  UCSRB = (1 < < RXEN) | (1 << TXEN);  
  UCSRC = (1 < < UCSZ1) | (1 << UCSZ0);  

  for (;;)  
  {  
    if (data>'Z'||data< 'A')  
    {  
      UDR = 10; UDR = 13; data='A';_delay_ms(100);  
    }  
    
    UDR = data;  
    data += 1;  
    _delay_ms(100);  
  }  
}  
```

__Once you load it, it's ready to roll!__  It continuously dumps letters to the serial port.  To receive them, open HyperTerminal (on windows, under accessories) or minicom (on Linux, look it up!).  Set your baud rate to 2800 (or whatever you selected) and you're in business.  This (picture below) is the output of the microcontroller to HyperTerminal on my PC.  Forgive the image quality, I photographed the LCD screen instead of taking a screenshot.

<div class="text-center img-border">

[![](avr_serial_console_thumb.jpg)](avr_serial_console.jpg)

</div>

__This is the circuit__ which generates the output of the previous image.  I have a few extra components.  I have an LED which I used for debugging purposes, and also a switch (labeled "R").  The switch (when pressed) grounds pin 1 of the ATTiny2313 which resets it.  If I want to program the chip, I hold "R" down and the PC can program it with the inline programmer ["parallel port, straight-through, DAPA style](https://wikis.mit.edu/confluence/download/attachments/20512/dapa.png)).  One cable going into the circuit is for the parallel port programmer, one cable is for the serial port (data transfer), and one is for power (5v which I stole from a USB port).

<div class="text-center img-border">

[![](avr_max232_thumb.jpg)](avr_max232.jpg)

</div>

__I hope you found this__ information useful.  Feel free to [contact me](http://www.swharden.com/blog/send-scott-a-message/) with any questions you may have, but realize that I'm no expert, and I'm merely documenting my successes chronologically on this website.
April 30th, 2009

A Foot in the QRSS Door

I've been very busy over the past couple weeks. Last Thursday my boss approached me and asked if I could work over the weekend. He wanted to complete and submit a grant by the deadline (Monday at 5 pm). To make a long story short I worked really hard (really long days) on Friday, Saturday, Sunday, and Monday to accomplish this. Monday afternoon when it was done (at about 4 pm), after which I went home and collapsed from exhaustion. I don't know how my boss does it! He worked on it far more than I did, and over that weekend he didn't sleep much. Anyway, in exchange for my over-weekend work I got Tuesday and Wednesday off.

I knew in advance that I'd have two days off to do whatever I wanted. I prepared ahead of time by ordering a small handful (I think 4?) of ATMEL AVR type ATTiny2313 chips from Digi-Key at $2.26 per chip. They arrived in the mail on Monday. Unlike the simple PICAXE chips which can be programmed a form of BASIC cod from 2 wires of a serial port, the AVR series of chips are usually programmed from assembly-level code. Thankfully, C code can be converted to assembly (thanks to AVR-GCC) and loaded onto these chips. The result is a much faster and more powerful coding platform than the PICAXE chips can delivery. PICAXE seems useful for rapid development (especially if you already know BASIC) but I feel that I'm ready to tackle something new.

I built a straight-through parallel programmer for my ATTiny2313 chips. It was based upon the dapa configuration and connects to the appropriate pins. To be safe I recommend that you protect your parallel port and microcontrollers by installing the proper resisters (~1k?) between the devices, but I didn't do this.

I decided to dive right in to the world of digital RF transmission and should probably go to jail for it. I blatantly violated FCC regulations and simply wired my microcontroller to change the power level given to a 3.579545 MHz oscillator. The antenna is the copper wire sticking vertically out of the breadboard.

These crystals release wide bands of RF not only near the primary frequency (F), but also on the harmonic frequencies (F*n where n=1,2,3...). I was able to pick up the signal on my scanner at its 9th harmonic (32.215905 MHz). I think the harmonic output power is inversely proportional to n. Therefore the frequency I'm listening to represents only a fraction of the RF power the crystal is putting out at its primary frequency. Unfortunately the only listening device I have (currently) is the old scanner, which can only listen above 30 MHz.

Remember when I talked about the illegal part? Yeah, I detected harmonic signals being emitted way up into the high 100s of MHz. I don't think it's a big deal because it's low power and I doubt the signal is getting very far, but I'm always concerned about irritating people (Are people trying to use Morse code at one of the frequencies? Am I jamming my neighbors' TV reception?) so I don't keep it on long. Once I get some more time, I'll build the appropriate receiver circuits (I have another matched crystal) and install a low-pass filter (to eliminate harmonics) and maybe even get a more appropriate radio license (I'm still only technician). But for now, this is a proof-of-concept, and it works. Check out the output of the scanner.

Something I struggled with for half an hour was how to produce a tone with a microcontroller and the oscillator. Simply supplying power to the oscillator produces a strong RF signal, but there is no sound to it. It's just full quieting when it's on, and static noise when it's off. To produce an AM tone, I needed amplitude modulation. I activated the oscillator by supplying power from the microcontroller with one pin (to get it oscillating), and fed it extra juice in the form of timer output from another pin. The fluctuation in power to the oscillator (without power-loss) produced a very strong, loud, clear signal (horizontal lines). I wrote code to make it beep. Frequency can be adjusted by modifying the timer output properties. The code in the screenshot is very primitive, and not current (doesn't use timers to control AM frequency), but it worked. I'm sure I'll write more about it later.

Thoughts from Future Scott (August 2019, 10 years later):

What a good start! But what a bad design =P

Driving a can oscillator's power pin with two microcontroller pins is not a good idea. Also, you were SO CLOSE to getting frequency shift keying to work! Rather than turning the can oscillator on/off with the microcontroller, just leave it on continuously and send a microcontroller pin to the can oscillator's VCO pin. I'm sure I didn't know what that 4th pin does when did when I originally wrote this (and most diagrams of can oscillators online leave that pin disconnected).

Either way, I'm happy this day happened - this was the start of years of hobby radio frequency circuit design!

Markdown source code last modified on January 18th, 2021
---
title: A Foot in the QRSS Door
date: 2009-04-30 09:26:40
tags: qrss, microcontroller, amateur radio, old
---

# A Foot in the QRSS Door

__I've been very busy over the past couple weeks.__ Last Thursday my boss approached me and asked if I could work over the weekend. He wanted to complete and submit a grant by the deadline (Monday at 5 pm). To make a long story short I worked really hard (really long days) on Friday, Saturday, Sunday, and Monday to accomplish this. Monday afternoon when it was done (at about 4 pm), after which I went home and collapsed from exhaustion. I don't know how my boss does it! He worked on it far more than I did, and over that weekend he didn't sleep much. Anyway, in exchange for my over-weekend work I got Tuesday and Wednesday off.

<div class="text-center">

![](attiny2313.jpg)

</div>

__I knew in advance that I'd have two days off to do whatever I wanted.__ I prepared ahead of time by ordering a small handful (I think 4?) of [ATMEL AVR](http://en.wikipedia.org/wiki/Atmel_AVR) type [ATTiny2313 chips from Digi-Key](http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&amp;name=ATTINY2313-20PU-ND) at $2.26 per chip. They arrived in the mail on Monday. Unlike the simple [PICAXE](http://en.wikipedia.org/wiki/PICAXE) chips which can be programmed a form of BASIC cod from 2 wires of a serial port, the AVR series of chips are usually programmed from assembly-level code. Thankfully, C code can be converted to assembly (thanks to AVR-GCC) and loaded onto these chips. The result is a much faster and more powerful coding platform than the PICAXE chips can delivery. PICAXE seems useful for rapid development (especially if you already know BASIC) but I feel that I'm ready to tackle something new.

__I built a straight-through parallel programmer__ for my ATTiny2313 chips. It was based upon the [dapa configuration](https://wikis.mit.edu/confluence/download/attachments/20512/dapa.png) and connects to the appropriate pins. To be safe I recommend that you protect your parallel port and microcontrollers by installing the proper resisters (~1k?) between the devices, but I didn't do this.

<div class="text-center img-border">

[![](img_1555_thumb.jpg)](img_1555.jpg)

</div>

__I decided to dive right in to the world of digital RF transmission__ and should probably go to jail for it. I blatantly violated FCC regulations and simply wired my microcontroller to change the power level given to a 3.579545 MHz oscillator. The antenna is the copper wire sticking vertically out of the breadboard.

__These crystals release wide bands of RF__ not only near the primary frequency (F), but also on the harmonic frequencies (F\*n where n=1,2,3...). I was able to pick up the signal on my scanner at its 9th harmonic (32.215905 MHz). I think the harmonic output power is inversely proportional to n. Therefore the frequency I'm listening to represents only a fraction of the RF power the crystal is putting out at its primary frequency. Unfortunately the only listening device I have (currently) is the old scanner, which can only listen above 30 MHz.

<div class="text-center img-border">

[![](img_1550_thumb.jpg)](img_1550.jpg)

</div>

__Remember when I talked about the illegal part?__ Yeah, I detected harmonic signals being emitted way up into the high 100s of MHz. I don't think it's a big deal because it's low power and I doubt the signal is getting very far, but I'm always concerned about irritating people (Are people trying to use Morse code at one of the frequencies? Am I jamming my neighbors' TV reception?) so I don't keep it on long. Once I get some more time, I'll build the appropriate receiver circuits (I have another matched crystal) and install a low-pass filter (to eliminate harmonics) and maybe even get a more appropriate radio license (I'm still only technician). But for now, this is a proof-of-concept, and it works. Check out the output of the scanner.

<div class="text-center img-border">

[![](ss_thumb.jpg)](ss.png)

</div>

__Something I struggled with for half an hour__ was how to produce a tone with a microcontroller and the oscillator. Simply supplying power to the oscillator produces a strong RF signal, but there is no sound to it. It's just full quieting when it's on, and static noise when it's off. To produce an AM tone, I needed amplitude modulation. I activated the oscillator by supplying power from the microcontroller with one pin (to get it oscillating), and fed it extra juice in the form of timer output from another pin. The fluctuation in power to the oscillator (without power-loss) produced a very strong, loud, clear signal (horizontal lines). I wrote code to make it beep. Frequency can be adjusted by modifying the timer output properties. The code in the screenshot is very primitive, and not current (doesn't use timers to control AM frequency), but it worked. I'm sure I'll write more about it later.

<blockquote class="wp-block-quote"><p><strong>Thoughts from Future Scott (August 2019, 10 years later):</strong></p><p>What a good start! But what a bad design =P</p><p>Driving a can oscillator's power pin with two microcontroller pins is not a good idea. Also, you were SO CLOSE to getting frequency shift keying to work! Rather than turning the can oscillator on/off with the microcontroller, just leave it on continuously and send a microcontroller pin to the can oscillator's VCO pin. I'm sure I didn't know what that 4th pin does when did when I originally wrote this (and most diagrams of can oscillators online leave that pin disconnected).</p><p>Either way, I'm happy this day happened - this was the start of years of hobby radio frequency circuit design!</p></blockquote>

April 1st, 2009

Post-Defense Day 1

Two hours after getting home from work I'm already basking in the newfound carefreeness thanks to the successful completion of my thesis defense (and graduation requirements). Yesterday I went to SkyCraft, early this morning I posted a schematic diagram of a basic circuit concept for a radio/microphone interface box with tone generating functions, and this afternoon I finished its assembly. It's hacked together, I know, but it's just a prototype. What does it do? It's complicated. It's basically just an exercise in microchip programming.

Future Scott reacts to this in August, 2019 (10 years later)

LOL! That's a pipette box! A chip socket was sunk into a plastic enclosure somehow! And that "regulated power supply" is an LM7805 on non-metallic perfboard screwed to two Jenga blocks!

Here's the little setup with the main control unit and a DC to DC regulated power supply / serial microchip programmer I made.

Here's the main control box. Notice the "2-way lighted switches" which I described in the previous entry. I found that proper grounding (floating pin prevention) was critical to their proper function. I'm still new to these chips, so I'm learning, but I'm making progress!

Getting a little artsy with my photographs now... this is the core of the device. It's a picaxe 14m!

This is a 5v regulated power supply I built. The headphone adapter is for easy connection to the serial port. It has a power switch and a program/run switch (allowing use of pin 13, serial out) while still "connected" to the PC.

I've slightly improved the connection between my radio's coax cable to the J-pole antenna I made.

I'm able to get pretty good signals from this antenna, but it's probably not likely to do much to my assembly skills (and lack of tuning), and more likely due to the fact that I have an unobstructed view of middle/southern Orlando from the 3rd story of my apartment balcony. I could probably wire up a rubber duck on a stick and get good results with that location! I'll miss my reception when I move.

Markdown source code last modified on January 18th, 2021
---
title: Post-Defense Day 1
date: 2009-04-01 18:46:34
tags: old, microcontroller, amateur radio
---

# Post-Defense Day 1

__Two hours after getting home from work__ I'm already basking in the newfound carefreeness thanks to the successful completion of my thesis defense (and graduation requirements). Yesterday I went to SkyCraft, early this morning I posted a schematic diagram of a basic circuit concept for a radio/microphone interface box with tone generating functions, and this afternoon I finished its assembly. It's hacked together, I know, but it's just a prototype. What does it do? It's complicated. It's basically just an exercise in microchip programming.

<div class="text-center img-border">

[![](img_13771_thumb.jpg)](img_13771.jpg)

</div>

<div class="text-center img-border">

[![](picaxe_all_thumb.jpg)](picaxe_all.jpg)

</div>

<blockquote class="wp-block-quote"><p><strong>Future Scott reacts to this in August, 2019 (10 years later)</strong></p><p><em>LOL! That's a pipette box! A chip socket was sunk into a plastic enclosure somehow! And that "regulated power supply" is an LM7805 on non-metallic perfboard screwed to two Jenga blocks!</em></p></blockquote>

__Here's the little setup__ with the main control unit and a DC to DC regulated power supply / serial microchip programmer I made.

<div class="text-center img-border">

[![](picaxe_panel_thumb.jpg)](picaxe_panel.jpg)

</div>

__Here's the main control box.__ Notice the "2-way lighted switches" which I described in the previous entry. I found that proper grounding (floating pin prevention) was critical to their proper function. I'm still new to these chips, so I'm learning, but I'm making progress!

<div class="text-center img-border">

[![](picaxe_artsy_thumb.jpg)](picaxe_artsy.jpg)

</div>

__Getting a little artsy__ with my photographs now... this is the core of the device. It's a picaxe 14m!

<div class="text-center img-border">

[![](picaxe_power_thumb.jpg)](picaxe_power.jpg)

</div>

__This is a 5v regulated power supply__ I built. The headphone adapter is for easy connection to the serial port. It has a power switch and a program/run switch (allowing use of pin 13, serial out) while still "connected" to the PC.

<div class="text-center img-border">

[![](jpole_antenna_diy_thumb.jpg)](jpole_antenna_diy.jpg)

</div>

I've slightly improved the connection between my radio's coax cable to the J-pole antenna I made.

<div class="text-center img-border">

[![](jpole_location_thumb.jpg)](jpole_location.jpg)

</div>

__I'm able to get pretty good signals__ from this antenna, but it's probably not likely to do much to my assembly skills (and lack of tuning), and more likely due to the fact that I have an unobstructed view of middle/southern Orlando from the 3rd story of my apartment balcony. I could probably wire up a rubber duck on a stick and get good results with that location! I'll miss my reception when I move.

Pages