I'm trying to enable on an AD9833 (it's a DDS that can generate waves) using a Raspberry Pi 3 B+.
I just want to know how to create a clock or master clock from the GPIO4 (GPCLK) of a Raspberry Pi B+ but I have no idea on how to do it.
I'm trying to enable on an AD9833 (it's a DDS that can generate waves) using a Raspberry Pi 3 B+.
I just want to know how to create a clock or master clock from the GPIO4 (GPCLK) of a Raspberry Pi B+ but I have no idea on how to do it.
Question
How to enable AD9833?
How to clock it?
Answer
Two good references are:
The AN1070 app notes, where there is an example of frequency calculations. You also need to study very carefully the functions of the pins Master Clock, Frame Sync (See Appendix A below)
Arduino forums. The Arduino guys have more experience on this chip, because Arduino is MCU, not SBC, therefore it is simpler to do real time clocking etc. Of course you might like to start with the much more powerful STM32, especially if you are playing with VHF sig gen things.
Update 2019jun19hkt2122
I used a scope to display the master clock waveform at Ref (pin #1) and found the 25MHz signal OK.
I also study the timing requirements, particular the fsync thing. I found that the minimum requirement is of the order of 5nS, which is nothing if my SPI speed of 400 kHz and output frequency 20 kHz are so low. So I should ignore fsync for my Micky Mouse Midi controller project.
/ to continue, ...
References
1. AD9833 Programmable Waveform Generator Data Sheet - Analog Devices
3. AliExpress CMCJU9833 Module - US$3
4. TaoBao CMCJU9833 Module - ¥25
5. Programming DDS AD9833 signal generator (Arduino Forum Discussion, Read 11,933 times)
6. Waveform Generator for Raspberry Pi 3B+ (AD9850, ICL8038)
7. ProtoSupplies AD9833 Function Generator Module - US$15
8. Simple code to drive AD9833 DDS chip - mjoldfield 2018oct26
9. Poor Man’s Signal Generator - Peter ScarGill 2017nov30
10. AD9833 Waveform Generator DIY - 2015sep
Appendices
Appendix A - AD9833 Master Clock Maximum Frequency
Appendix B - Arduino Style STM32 - ST Electronics
Appendix C - AD8933 Sig Gen Module Setup Picture
Appendix D - AD8933 Master Clock Schematic
Appendix E - Python program to drive AD9833 - by mjoldfield 2018oct26
Simple code to drive AD9833 DDS chip - mjoldfield 2018oct26
#
# Toy code for simple control of the AD9833 DDS chip
#
# Cut down heavily from https://github.com/MajicDesigns/MD_AD9833
# - The SPI code was lifted almost verbatim then manually
# converted to python
#
# Copyright (C) 2018 M J Oldfield
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
import gpiozero
class AD9833:
def __init__(self, data, clk, fsync):
self.dataPin = gpiozero.OutputDevice(pin = data)
self.clkPin = gpiozero.OutputDevice(pin = clk)
self.fsyncPin = gpiozero.OutputDevice(pin = fsync)
self.fsyncPin.on()
self.clkPin.on()
self.dataPin.off()
self.clk_freq = 25.0e6
def set_freq(self, f):
flag_b28 = 1 << 13
flag_freq = 1 << 14
scale = 1 << 28
n_reg = int(f * scale / self.clk_freq)
n_low = n_reg & 0x3fff
n_hi = (n_reg >> 14) & 0x3fff
self.send16(flag_b28)
self.send16(flag_freq | n_low)
self.send16(flag_freq | n_hi)
def send16(self, n):
self.fsyncPin.off()
mask = 1 << 15
for i in range(0, 16):
self.dataPin.value = bool(n & mask)
self.clkPin.off()
self.clkPin.on()
mask = mask >> 1
self.dataPin.off()
self.fsyncPin.on()
ad = AD9833(10, 11, 8)
while 1:
for f in range(10,10000):
ad.set_freq(f)