View previous topic :: View next topic |
Author |
Message |
techknight
Joined: 21 Apr 2008 Posts: 231
|
Posted: Fri Jul 12, 2013 2:40 am Post subject: AVR DDS? |
|
|
I am working on a project where I need a digitally controlled adjustable frequency between roughly 50khz and 1mhz. But the catch here is I need a full output triangle wave.
I was doing some research, and it appears i need a DDS setup. and maybe the AD9833, everything I am finding on the web is pointing me into that direction.
Has anyone written a library/driver for this chip in BASCOM? Just wondering.
I see some test code laying around the web, but most of it is in foreign language and isnt translating well. And the rest is in C, but I dont program in C. |
|
Back to top |
|
|
pippofranco
Joined: 02 Oct 2010 Posts: 6
|
Posted: Fri Jul 12, 2013 8:52 am Post subject: Re: AVR DDS? |
|
|
techknight wrote: | I am working on a project where I need a digitally controlled adjustable frequency between roughly 50khz and 1mhz. But the catch here is I need a full output triangle wave.
I was doing some research, and it appears i need a DDS setup. and maybe the AD9833, everything I am finding on the web is pointing me into that direction.
Has anyone written a library/driver for this chip in BASCOM? Just wondering.
I see some test code laying around the web, but most of it is in foreign language and isnt translating well. And the rest is in C, but I dont program in C. |
You don't actually need a library: the algorithm to calculate the number to send to the DDS to obtain a specific frequency is rather simple.
I used the AD9851 but the mechanism is similar for the AD9833.
Pay attention to the number of bits your DDS will need to set it up, mine needs 40, yours may need less.
I have no direct experience with the AD9833, I think there should be a control byte to set up to obtain the triangle wave
here is a code fragment to load the DDS with the serial pin, as you can see is really simple
Dim Init As Byte
Dim Delta_phase As Single
Dim Freq As Single
Dim Freq_dds As Long
Dds_reset Alias Portb.4
Dds_fq_ud Alias Portb.2
Dds_w_clk Alias Portb.1
Dds_data Alias Portb.0
Config Portb.4 = Output 'Dds_reset
Config Portb.2 = Output 'Dds_fq_ud
Config Portb.1 = Output 'Dds_w_clk
Config Portb.0 = Output 'Dds_data
Const Clk_in = 125000000 ' DDS clock frequency
Const Min_stp = 2 ^ 32 ' DDS Minumum step
Freq = 1000
'****************************************************************
'* AD9850 Initialize *
'****************************************************************
Set Dds_reset : Waitus 10 : Reset Dds_reset : Waitus 10 ' Reset
Set Dds_w_clk : Waitus 10 : Reset Dds_w_clk : Waitus 10 ' W_CLK
Set Dds_fq_ud : Waitus 10 : Reset Dds_fq_ud : Waitus 10 ' FQ_UD
'****************************************************************
'* AD9850 Frequency Set *
'****************************************************************
Delta_phase = Freq * Min_stp
Delta_phase = Delta_phase / Clk_in
Freq_dds = Delta_phase
Shiftout Dds_data , Dds_w_clk , Freq_dds , 3 , 32
Shiftout Dds_data , Dds_w_clk , Init , 3 , 8
Set Dds_fq_ud : Waitus 10 : Reset Dds_fq_ud : Waitus 10
Good luck |
|
Back to top |
|
|
techknight
Joined: 21 Apr 2008 Posts: 231
|
Posted: Sat Jul 13, 2013 12:35 am Post subject: |
|
|
I would use the 9850 which is what everyone else is using, but it has no support for Triangle, which is required. |
|
Back to top |
|
|
n7qwt
Joined: 21 Dec 2006 Posts: 2
|
Posted: Tue Aug 13, 2013 8:56 pm Post subject: |
|
|
My code for programming an AD9833 for sine wave output.
Garrett B. Waltrip
N7QWT
'Start Hardware Configuration
'#######################################################################
$regfile = "8515def.dat"
$crystal = 8000000
Config Pind.3 = Output 'Fsync
Config Pind.4 = Output 'Sclk
Config Pind.5 = Output 'SData
Fsync Alias Portd.3
Sclk Alias Portd.4
Sdata Alias Portd.5
Set Sclk 'Set initial pin state
Set Fsync 'Set initial pin state
'#######################################################################
'End Hardware Configuration
Dim Count As Double
Dim Freq As Double
Dim Setfreq As Long At &H90
Dim Low_byte0 As Word At &H90 Overlay
Dim High_byte0 As Word At &H92 Overlay
'############################################################################################################
'############################################################################################################
Freq = 400 'Change this value to the required Freq. in Hertz
'############################################################################################################
'############################################################################################################
Count = .093132257 'This is based on a 25 MHz Osc driving the 9833.
Freq = Freq / Count
Setfreq = Freq
Shift Setfreq , Left , 2 'The shifts take care of converting from a 16 bit word to a 14 bit.
Shift Low_byte0 , Right , 2
Setfreq = Setfreq + &H40004000
'Declare subroutines
'#######################################################################
Declare Sub Send_dds(byval Sw As Word)
'#######################################################################
'End Declare subroutines
'Start sending commands to the DDS
'#######################################################################
Call Send_dds(&H2100) 'Change this for triangle wave to the appropriate command.
Call Send_dds(low_byte0)
Call Send_dds(high_byte0)
Call Send_dds(&H2000) 'Change this for triangle wave to the appropriate command.
'#######################################################################
'End sending commands to the DDS
Powerdown 'Put CPU in Powerdown state for less noise
End 'End program
'########################################################################
'This is the subroutine that send the data to the DDS
'########################################################################
Sub Send_dds(byval Sw As Word)
Reset Fsync
Waitms 1
Shiftout Sdata , Sclk , Sw , 0 , 16 , 500
Waitms 1
Set Fsync
End Sub
'######################################################################## |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|