Created
October 11, 2014 16:48
-
-
Save kik/97386a3a53340fb9685e to your computer and use it in GitHub Desktop.
ArduinoによるAMラジオテスト用の信号発生器
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ブレッドボードで作ったAMラジオが全然動かないので、Arduino Leonardでお手軽に作ったAMラジオの信号発生器 | |
搬送波は1MHzで矩形波なので高調波が乗りまくってると思われる。 | |
音声信号は500-1000Hzぐらいの音階で矩形波。 | |
AM変調は搬送波をon/offするだけ。 | |
5番ピンに適当な長さの電線を繋いでバーアンテナに近づけると動く。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> | |
#include <avr/interrupt.h> | |
#include <avr/io.h> | |
#define FC 1000000 | |
int ledPin = 13; | |
volatile int note_on = 0; | |
ISR(TIMER1_COMPA_vect) { | |
if (note_on) { | |
TCCR3A ^= _BV(COM3A0); | |
} else { | |
TCCR3A &= ~_BV(COM3A0); | |
} | |
} | |
void setup() | |
{ | |
pinMode(ledPin, OUTPUT); | |
digitalWrite(ledPin, HIGH); | |
pinMode(5, OUTPUT); | |
digitalWrite(5, LOW); | |
cli(); | |
// carrier signal | |
// WGM = 0100 = CTC | |
// CS = 001 = clk / 1 | |
// COM3A = 01 or 00 = toggle or nc | |
TCCR3A = 0; | |
TCCR3B = _BV(WGM32) | _BV(CS30); | |
OCR3A = F_CPU / (2 * FC); | |
// base signal | |
// WGM = 0100 = CTC | |
// CS = 001 = clk / 1 | |
// COM1 = 0 = nc | |
TCCR1A = 0; | |
TCCR1B = _BV(WGM12) | _BV(CS10); | |
OCR1A = 1024; // temp value | |
TIMSK1 |= _BV(OCIE1A); | |
sei(); | |
} | |
void note(int hz) | |
{ | |
OCR1A = F_CPU / (2 * hz); | |
note_on = 1; | |
} | |
void loop() | |
{ | |
for (;;) { | |
note(523); | |
delay(250); | |
note(587); | |
delay(250); | |
note(659); | |
delay(250); | |
note(698); | |
delay(250); | |
note(783); | |
delay(250); | |
note(880); | |
delay(250); | |
note(987); | |
delay(250); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment