My latest project is about building a simple DDS using a AD9850 board I bought off ebay for only 4 euro. I spent one evening putting together a working 14 MHz sinewave generator controlled with a rotary encoder and an LCD display. All controlled with an arduino UNO and about 70 lines of code.
Very cool... could this AD9850 be used to build a mulifrequency detector?


Very cool... could this AD9850 be used to build a mulifrequency detector?

Code:
// Signal generator demonstration using a AD9850, encoder and 4x16 LCD
// Encoder connections:
// Middle pin to ground, outside two pins are connected to pins D2 and D3, so interrupts can be used
// AD9850 connections:
// 13: CLK, 12: FQUP, 11: DATA, 10: RESET
#include <LiquidCrystal.h>
#include <AH_AD9850.h>
LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
AH_AD9850 AD9850(13, 12, 11, 10);
int ENC_LEFT=2;
int ENC_RIGHT=3;
volatile uint8_t pinValues[2] = {0,0};
volatile unsigned long f = 14000000;
void setup()
{
lcd.begin(16, 4);
AD9850.reset();
// Configure encoder pins as input, turn on pullup resistors
pinMode(ENC_LEFT, INPUT);
digitalWrite(ENC_LEFT, HIGH);
pinMode(ENC_RIGHT, INPUT);
digitalWrite(ENC_RIGHT, HIGH);
attachInterrupt(0, knob_turned, CHANGE);
attachInterrupt(1, knob_turned, CHANGE);
}
void rotary_encoder_change(uint8_t changedPin, uint8_t value)
{
pinValues[changedPin] = value;
// only increment for each 'click' of the dial - when both pins have gone back to 0
if (value == 0 && pinValues[0] == pinValues[1]) {
f += ((changedPin) ? 50 : -50);
AD9850.set_frequency(0,0,f);
}
}
void knob_turned()
{
delay(1);
int pin0 = digitalRead(ENC_LEFT);
int pin1 = digitalRead(ENC_RIGHT);
if (pin0 != pinValues[0]) {
rotary_encoder_change(0, pin0);
}
else if (pin1 != pinValues[1]) {
rotary_encoder_change(1, pin1);
}
}
void update_display()
{
char buf[17];
int mhz = f/1000000;
int khz = (f - mhz * 1000000) / 1000;
int hz = f - mhz * 1000000 - khz * 1000;
sprintf (buf, " %d.%03d.%03d", mhz, khz, hz);
lcd.setCursor(0,0);
lcd.print(buf);
sprintf (buf, "%ld", f);
lcd.setCursor(-4,2);
lcd.print(buf);
}
void loop()
{
update_display();
}

Comment