i am working on a project involving the CN-0349 and therefore the AD5934 with a Raspberry Pi Model 3. I already did some tests, which were working fine.
My main problem is to get the right frequency parameters to the AD5934. The data sheet states (page 4), that the maximum clock speed is somewhere around 16 MHz, with a frequency range from 1 kHz to 100 kHz. I tried to use the equations on page 13 and 21 to calculate the code to send to the AD5934. Using the exact same values (start frequency 30 kHz, 10 Hz increment, 150 steps) used on page 13, everything works fine. But i can't seem to go below 25 kHz. Only the start frequency code seems to break my python code. After sending wrong(?) code to the AD5934, the status register only shows no valid data/dft not complete. The only way to get valid data again is to reboot the CN-0349.
Now i already tried to check if something with the equation might be wrong. I checked the baudrate of the raspberry pi(400 kHz) and changed the MCLK in my formula, only to get errors on every try. The start frequency and other parameters do not seem to matter anymore. After changing MCLK back to 16 MHz in the equation (Raspi still 400 kHz), it works again in the range described above (30 kHz +- 5 kHz).
Since many sources state the raspberry pi baudrate is 400 kbps, not 400 kHz and i could not find any I2C bus baudrates of 16 MHz, mabye my understanding of these frequencies/speeds might be wrong? Is there a vaild way to get the baudrate in Hz? Did someone have similar problems with the frequency parameters?
This might not be part of my problem, but i do not understand where the 16 in the equation comes from. Is it derived from the 16 MHz? Do i need to change it with a different MCLK or is it a constant?
I would be very grateful for any help!
All formulas in the datasheet refer to MCLK frequency that it coming to the AD5934 chip from the clock generator U6. It has nothing to do with the I2C interface clock of 400KHz.
Not sure what could be breaking your python code – putting 400KHz instead of MCLK frequency shouldd result in erroneous frequency codes, but should not break the execution. If this could be of help, here is a reference to some Python code for the AD5933 you can look at, especially lines 159 and 160. There is a bit of a difference between formulas for the AD5933 and AD5934: for the AD5934 you need to replace “4” with “16”. I would also recommend using “round” piror to “int”, although the difference is quite miniscule:
min = int(round((min / (self.clk / 16)) * pow(2, 27)))
freq_inc = int(round((freq_inc / (self.clk / 16)) * pow(2, 27)))
Also the AD5934 does not have internal oscillator, so instead of “self.clk” it is necessary to use the frequency of your external U6 oscillator, which is 16000000Hz. Make sure your desired output frequency and MCLK frequency are in the same units, say, Hz.
thanks for the fast reply! I will check out the python code you sent me today, maybe i can figure out what's wrong with my own.
I checked the CN-0349 circuit note again for the U6 oscillator. According to figure 1, the oscillator is the FXO-HC536R-1, which has a frequency of ~1MHz accoding to data sheets. Is the oscillator on the CN-0349 board actually the FXO-HC536R-16, which has 16 MHz?
Unfortunately I do not have my setup handy to check the codes independently. Do you put your part into the standby mode? Hopefully somebody from ADI will be able to help.I can only refer to a another piece of code written specifically for the AD5934 for your review, but it is not Python: https://github.com/No1089/AD5934 .
I am currently sick and not at work. I will look at the new code as soon as I'm at work again.
Yes I put the device in standby mode. I used the flowchart from the ad5934 datasheet to programm it. That's why I'm so confused as to why it does not work. One thing I did not try was to use another RPi, will try that on Monday too.
Will keep posting updates in case i manage to find something out. Anyways, thanks again for your help so far Snorlax!
Get well get well soon!
Back again and it's finally working! Rewrote my code and used the bitshifting which was used in the codes you sent me. Not using bitshifting, but another way (because i didn't know of bitshifting), apparently broke my code. Though i am not sure why, since the same values were programmed to the registers.
Nethertheless, thanks again! Probably would have wasted another few weeks on that.
Happy to hear. Best of luck with the rest of your project!