I am relatively new to arduino and have been messing around with using it to control an AD9850 frequency generator. Found a great tutorial and everything works just as expected. However, what I'd like to do is the ability of adding in a series of frequencies in the Arduino code along with set time frames for each.
I attached the .ino file but here is the raw code. The last line is where the single frequency can manually be entered. Again, my idea is to add a string of frequencies along with the desired run duration of each so it runs through them without manually changing and uploading after each one.
// transfers a byte, a bit at a time, LSB first to the 9850 via serial DATA line
void tfr_byte(byte data)
{
for (int i=0; i<8; i++, data>>=1) {
digitalWrite(DATA, data & 0x01);
pulseHigh(W_CLK); //after each bit sent, CLK is pulsed high
}
}
// frequency calc from datasheet page 8 = * /2^32
void sendFrequency(double frequency) {
int32_t freq = frequency * 4294967295/125000000; // note 125 MHz clock on 9850
for (int b=0; b<4; b++, freq>>=8) {
tfr_byte(freq & 0xFF);
}
tfr_byte(0x000); // Final control byte, all 0 for 9850 chip
pulseHigh(FQ_UD); // Done! Should see output
}
void setup() {
// configure arduino data pins for output
pinMode(FQ_UD, OUTPUT);
pinMode(W_CLK, OUTPUT);
pinMode(DATA, OUTPUT);
pinMode(RESET, OUTPUT);
pulseHigh(RESET);
pulseHigh(W_CLK);
pulseHigh(FQ_UD); // this pulse enables serial mode - Datasheet page 12 figure 10
}
LarryD:
You would set the frequency, start a timer, when the timer expires set the next frequency etc.
Ok, but how do you draft this so that it is all handled in the arduino code at one time. The code now allows me to set a single frequency and upload it to the arduino board -- which works great. It creates a single frequency which runs indefinitely until its powered off or a new single frequency is uploaded.
I want to be able to write a series of frequencies along with each one having a desired run duration, which is then uploaded one time to run through its process.
Any ideas on the best way to modify the .ino provided to do this?
pletchman:
Very informative Robin2. So how do you think it best to incorporate into the existing .ino file I've already been using?
Maybe it would be better to ask yourself how you could incoporate your code into several things at a time (and obviously discarding parts that you don't need) ?
Robin2:
Maybe it would be better to ask yourself how you could incoporate your code into several things at a time (and obviously discarding parts that you don't need) ?