Post Go back to editing

ad9834 square wave

Category: Hardware
Product Number: ad9834

we are trying to generate square waves with a ad9834 and a raspberry pi at 8Mhz. the shape of the square wave gets distorted starting at 1 MHz,

isn't the ad9834 supposed to function at high frequencies? please let us know how to improve the shape?

Here is the python code we use:

---------------------------------------------

import gpiozero

class AD9834:

    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 = 75.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)

        self.send16(0x2028)

    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 = AD9834(10, 11, 8)
f=8000000

#ad.send16(0x2068)

while 1:
    #for f in range(10,10000):
    ad.set_freq(f)