Controlling two AD9850 Signal Generators with one board

Hi. I am building a project with two AD9850 Signal Generators , Two Rotary Encoders, and one 2x16 LCD display.

  • One encoder sets the frequency of the first AD9850 (rx)
  • The push button sets the digit to displace the frequency
  • One character at the bottom LCD row indicates which digit of the frequency is being adjusted.
  • The second AD9850 will run at the same frequency (rx) plus a value (ry) that is set with the second encoder

I have frankestenized code from different sources and everything is working, with the exception of the second AD9850. I don’t know how to define it.

I have tried to mess with the library AH_AD9850.h and I have also tried to create a second library AH_AD9850_2.h to define the second generator, but I don’t know how to do it.

Has anyone connected two generators into one board, or can give me some tip about how to modify the library in order to include more than one generator?

Here is a picture of the experiment. This is my first experience with Ardunino, and my first post at this community where I have learned almost everything that I know so far. Thank you!!! :slight_smile:

I attach a file with the sketch and the library.

Sorry, wrong attachments. Here are the correct ones

AH_AD9850.zip (2.95 KB)

Encoder_Polling_V2.zip (3.97 KB)

AD9850_Bina_6.ino (9.51 KB)

#include <AH_AD9850_2.h>                           /// 2nd AD9850 doesn't work yet
// I don't know if the correct way is to create and redefine a second library (named AD9850_2.h)
// or to modify the existing AD9850.h - but that is still pending

That is not the correct way of declaring a second instance of a class. Delete this line.

Use the code below to define your second instance

AH_AD9850 AD9850_2(W_CLK_2, FQ_UD, DATA_2, RESET);

Thank you for your answer, Grumpyu_Mike

I have modified the code like that to define the second instance. However, I don't know how to modify the library AD9850.h in order to define the second generator.

pinfloid:
However, I don't know how to modify the library AD9850.h in order to define the second generator.

You shouldn't need to modify the header file (I though it was called AH_AD9850.h?), you just need to instantiate another AH_AD9850 object.

//First AD9850                                    
#define W_CLK 10   // Word load clock pin (CLK)
#define FQ_UD 11   // Freq update pin (FQ)
#define DATA 12   // Serial data load pin (DATA)
#define RESET 13  // Reset pin (RST) 
AH_AD9850 AD9850(W_CLK, FQ_UD, DATA, RESET);

//Second AD9850                                     /// 2nd AD9850 doesn't work yet
#define W_CLK_2 7   // Word load clock pin (CLK)
#define FQ_UD_2 8   // Freq update pin (FQ)(Common Pin)
#define DATA_2 9   // Serial data load pin (DATA)
#define RESET_2 0  // Reset pin (RST) (Common Pin)
AH_AD9850 AD9850_2(W_CLK_2, FQ_UD, DATA_2, RESET);

Or you could have an array of two AH_AD9850s.

Yes! now it’s working. It was more simple than I thought. No need to modify the library

Additionally, there were other errors at my program that prevented the second module from working. Here is a simple test code that works

#include <AH_AD9850.h>

#define W_CLK 10   // Word load clock pin (CLK)
#define FQ_UD 11   // Freq update pin (FQ)
#define DATA 12   // Serial data load pin (DATA)
#define RESET 13  // Reset pin (RST) 
AH_AD9850 AD9850(W_CLK, FQ_UD, DATA, RESET);
                                    
#define W_CLK_2 7   // Word load clock pin (CLK)
#define FQ_UD_2 8   // Freq update pin (FQ)
#define DATA_2 9   // Serial data load pin (DATA)
#define RESET_2 0  // Reset pin (RST) 
AH_AD9850 AD9850_2(W_CLK_2, FQ_UD_2, DATA_2, RESET_2);

void setup()
{
    AD9850.reset();                   
    AD9850_2.reset(); 
}

void loop(){

 AD9850.set_frequency(1000);        
 AD9850_2.set_frequency(1000);     
}

Thank you very much for your kind help. I’ve learnt something new :slight_smile:

I attach the complete sketch with the errors corrected, in the case that someone wants to use it.

My scope is doing curious dancing waves when joining the signal from the two generators.

Thank you again.

Binaural_02.ino (9.39 KB)

Lissajous figures?