Driver for the AD9833
CODE: ad9833.bas
D0=16:D1=5:D2=4:D3=0:D4=2:D5=14:D6=12:D7=13:D8=15:D9=3:D10=1
'SCK=14:MISO=12:MOSI=13:SS=15 SCK=D5:MISO=D6:MOSI=D7:SS=D8 ' AD9833 ref datasheet http://www.analog.com/media/en/technical-documentation/data-sheets/AD9833.pdf' MCP41010 ref datasheet http://ww1.microchip.com/downloads/en/DeviceDoc/11195c.pdf FSY = D8 ' pin for AD9833 chip select(FSY) pin on modulepin(FSY) = 1 Pin.Mode FSY, output POT_CS = D0 ' pin for MCP41010 chip select (CS) pin on modulepin(POT_CS) = 1 Pin.Mode POT_CS, output'set SPI to mode 2spi.setup 1000000 ,2 AD9833_reset for l = 1 to 2 for f = 100 to 5000 step 10 AD9833_SetFreq f, 2 next f for f = 5000 to 100 step -10 AD9833_SetFreq f, 2 next f next l AD9833_SetFreq 440, 2 for z = 0 to 255 AD9833_level z pause 10 next z end'----------------------------------------------------------------------' set the potentiometer level from 0 to 255sub AD9833_level(level) local a pin(POT_CS) = 0 a = SPI.Word(level or &h1100) pin(POT_CS) = 1 end sub'reet the AD98333sub AD9833_reset local a Pin(FSY) = 0 a = SPI.WORD(&h2100) ' reset and B28 a = spi.word(&hc000) ' phase = 0 Pin(FSY) = 1 end sub ' sets the frequency (Hz) and waveform output' mode is 1 for triangle, 2 for sine, 3 for squareSub AD9833_SetFreq(Freq, mode) Local a, f, f1, f2, m oscillator = 25000000 'Crystal frequency f = (Freq * (1 << 28)) \ oscillator f1 = (f And &H3FFF) Or &H4000 f2 = (f >> 14) Or &H4000 'print "freq " , freq, f, f1, f2 Pin(FSY) = 0 select case mode case 1 m = &h02 ' triangle (bit MODE) case 2 m = 0 ' sine case else m = &h28 ' square ( bits OPBITEN and DIV2) end select a = SPI.WORD(&H2000 or m) ' B28 no reset + wave mode a = spi.word(f1) ' 14 bits MSB a = spi.word(f2) ' 14bits LSB Pin(FSY) = 1 End Sub