Turn your Arduino into an AM radio transmitter!

Thank you GoForSmoke.

I did wade through the datasheet for the attiny85, and the section on setting the clock is unfortunately over my head. I tried various approaches based on what I found in newsgroups. I had good results using code here:

I could set the frequency based on the following code:

// Timer/Counter0 Compare Match A interrupt handler 
ISR (TIMER0_COMPA_vect) {
   PORTB ^= 1 << PINB4;        // Invert pin PB4
}
 
void setup() {
    OSCCAL += 3;                // User calibration
    pinMode(4,OUTPUT);          // Set PB4 to output
    TCNT0 = 0;                  // Count up from 0
    TCCR0A = 2 << WGM00;        // CTC mode
    if (CLKPR == 3)             // If clock set to 1MHz
        TCCR0B = (1<<CS00);     // Set prescaler to /1 (1uS at 1Mhz)
    else                        // Otherwise clock set to 8MHz
        TCCR0B = (2<<CS00);     // Set prescaler to /8 (1uS at 8Mhz)
    GTCCR |= 1 << PSR0;         // Reset prescaler
    OCR0A = 49;                 // 49 + 1 = 50 microseconds (10KHz)
    TIFR = 1 << OCF0A;          // Clear output compare interrupt flag
    TIMSK |= 1 << OCIE0A;       // Enable output compare interrupt
}
 
void loop()

I found that shrinking the delay (OCR0A) increased the frequency, but I hit a ceiling at about 200 kHz no matter how hard I tried - and that's with setting the ATtiny's internal oscillator to 16 MHz.

So as it turns out, I lack the basic understanding necessary to set the clock on my own without following other people's code. I was looking for a good online tutorial. There were various sites, but the knowledge seems to be finely dispersed in staggered message threads. The whole experience made me REALLY appreciate the Arduino IDE taking care of all these commands for you with the Uno.

To make a long story short, I ended up using a CMOS 555 timer today for the carrier signal, which did the job quite nicely, and broadcast morse code all over my lab at 1 MHz. Since the range is quite limited and I doubt people listen to AM in my building, I don't think anyone heard "scott rocks" repeatedly, the message that was embedded in the example code from here:

http://www.swharden.com/wp/2011-08-06-ridiculously-simple-avr-mcu-am-radio-transmitter/

I really like the 555 solution because I can fine-tune the frequency with a 10K trimmer, rather than perhaps be constrained to multiples of a clock divider. Still, if anyone knows offhand how to elicit a 1MHz signal from an ATtiny85, or would be patient enough to tell me the secrets of setting the clock beyond 200 kHz, it will be useful for this and other projects.

Kind regards,
Dave