Good Morning
I'm working on a project since a long time. I need a changeable frequency about 0 - 300 hz.
For a short discription. This is not the first project. The first one was very easy, works also with a signal generator, called AD9833. It was an Arduino Nano with the AD9833 and a SPI display. I used the following code for this project.
This code was shortened…..
I tried to understand this code but I have a problem. The code included the Wire.h. But this AD9833 is for a SPI port. The pins are also not SPI (6, 5, 7). How is it possible that this code runs???
Now I want to take this part of this code to use it with an Teensy 4.0. But the code dont run on the Teensy….
The SPI port from the Teensy was already used. I cant use him for the AD9833.
Someone who could explain the code for me or could help to write this code for the Teensy 4.0
Sorry for my english. It's not my first language ;-)
Greetings
Gary
I'm working on a project since a long time. I need a changeable frequency about 0 - 300 hz.
For a short discription. This is not the first project. The first one was very easy, works also with a signal generator, called AD9833. It was an Arduino Nano with the AD9833 and a SPI display. I used the following code for this project.
Code:
#include "Wire.h"
int FSYNC = 6;
int SDATA = 7;
int SCLK = 5;
unsigned long freq;
byte wave=3;
void setup() {
pinMode(FSYNC, OUTPUT);
pinMode(SDATA, OUTPUT);
pinMode(SCLK, OUTPUT);
digitalWrite(FSYNC, HIGH);
digitalWrite(SDATA, LOW);
digitalWrite(SCLK, HIGH);
Wire.begin();
Serial.begin(38400);
UpdateRegister(0x2100); // Nach Application Note AN-1070 von Analog Devices
UpdateRegister(0x50C7);
UpdateRegister(0x4000);
UpdateRegister(0xC000);
UpdateRegister(0x2000);
freq=10;
UpdateFreq(freq, 0x2020); // Sinus 1000 Hz
}
void loop() {
int ser, len;
char buf[10];
UpdateFreq(freq, 0x2020); // Rechteck
void UpdateFreq(long freq, int form){
// Die Frequenz Register schreiben.
long FreqReg;
unsigned int MSB, LSB;
FreqReg = (freq * pow(2, 28)) / 25000000; // 25MHz Quarz
if (form == 0x2020) FreqReg = FreqReg << 1; // Rechteck 1/2 Frequenz
MSB = (int)((FreqReg & 0xFFFC000) >> 14);
LSB = (int)(FreqReg & 0x3FFF);
LSB |= 0x4000;
MSB |= 0x4000;
UpdateRegister(0x2100); // Control Register, Reset Bit DB8 gesetzt
UpdateRegister(LSB); // Frequency Register 0 LSB
UpdateRegister(MSB); // Frequency Register 0 MSB
UpdateRegister(0xC000); // Phase Register
UpdateRegister(form); // Exit Reset : Wellenform nach dem Reset
}
void UpdateRegister(unsigned int data){
// Ein DDS Register schreiben
unsigned int pointer = 0x8000;
digitalWrite(FSYNC, LOW);
for (int i=0; i<16; i++){
if ((data & pointer) > 0) {
digitalWrite(SDATA, HIGH);
}
else {
digitalWrite(SDATA, LOW);
}
digitalWrite(SCLK, LOW);
digitalWrite(SCLK, HIGH);
pointer = pointer >> 1 ;
}
digitalWrite(FSYNC, HIGH);
}
This code was shortened…..
I tried to understand this code but I have a problem. The code included the Wire.h. But this AD9833 is for a SPI port. The pins are also not SPI (6, 5, 7). How is it possible that this code runs???
Now I want to take this part of this code to use it with an Teensy 4.0. But the code dont run on the Teensy….
The SPI port from the Teensy was already used. I cant use him for the AD9833.
Someone who could explain the code for me or could help to write this code for the Teensy 4.0
Sorry for my english. It's not my first language ;-)
Greetings
Gary