Receiving signals of various shapes with high frequency accuracy is a very common task when creating various radio amateur and professional electronic devices.
Thanks to the modern component base, today it is possible to implement fairly functional signal generators operating on the principle of DDS or direct digital synthesis. And today we will look at a simple example of creating such a signal generator using the Arduino and AD9850.
For rapid prototyping, let's take the Arduino Nano board and the HC-SR08 board with the AD9850 embedded chip.
The data connection diagram of the two boards is quite simple and may look like this.
The following code for Arduino implements frequency sweep from 1 Hz to 40 MHz, which is the limit. This range can be easily changed to suit your needs. If you want square wave signals, you need to adjust the potentiometer to get the desired duty cycle, otherwise you might get a duty cycle of 0 and not see anything.
#include <SPI.h>
// CLK = 13,
// DATA = 11,
// RST = GND
const byte FQ = 10;
// VCC - Arduino +5V
// GND - Arduino GND
void setup() {
Serial.begin(9600);
Serial.println(__FILE__);
SPI.begin();
SPI.setBitOrder(LSBFIRST);
pinMode(FQ, OUTPUT);
upDownFq();
float f = 1;
while (f < 40E6) {
AD9850_set_frequency(f);
Serial.println(f);
delay(1000);
f = f * 1.5;
}
}
void loop() {}
void AD9850_set_frequency(float frequency) {
frequency = frequency / 1000000 * 4294967295 / 125;
union {
long y;
byte b[4];
} freq;
freq.y = frequency; // float в long
SPI.transfer(freq.b, 4);
SPI.transfer(0);
upDownFq();
}
void upDownFq() {
asm("sbi 5,2 \n\t"
"cbi 5, 2 \n\t");
}
Social Plugin