Re: [bascom] DDS Signal Generator AD9850


From "R&Dboldt-electronic" <bascom@boldt-electronic.de>
Date Tue, 9 Sep 2003 08:03:17 +0200

Hi Gene,
yes indeed, it´s very helpful to have a base of code to start with, so also
from my side many thanks to you, Thomas for sharing the code.

b.t.w. noramlly I don´t like politics discussed on this list, but since it´s
more history and geography than  politics
some words about your ancestors.
I think they came from the city of Weimar, the name  Weimar Republic
actually wasn´t a republic itself but stands for the regime´s change from
Empire towards Republic after WW I .
Take a look at
http://mars.acnet.wnec.edu/~grempel/courses/germany/lectures/20weimar1.html
and you´ll have a first impression what the w.r. was.
best regards (mit freundlichen Empfehlungen)

Paul
----- Original Message -----
From: "GB" <avr1@allplc.com>
To: <bascom@grote.net>
Sent: Tuesday, September 09, 2003 12:29 AM
Subject: Re: [bascom] DDS Signal Generator AD9850


Hi Thomas,
 Thanks very much for sharing your code with the list! It looks very
promising indeed. I will use it soon, and I suspect others will find it
very useful also.
 I noticed that your email signature says "Weimar" ("Republic", I
assume). I have just done some genealogy research, and it shows that my
ancestors came to the US from the Weimar Republic in 1848. Now I must
learn more about Germany!    :O(sorry for the "off-topic")
Die besten Beachtungen ("Best Regards", I hope - Ich spreche Deutsch
nicht ;O)
Gene
=============================================
>yes, that´s indeed interesting, wouldn´t it be a good idea to make it an
>Application Note and send it to Mark to be published,

It's only my working code. Not yet ready for publishing it on the web.
It's very simple and there is no error checking and so on.

>anyway I am interested in your code snippet.

Because of your (and all the other people) questions I'll put my code
at the end of this message.
Haven't checked the code yet for proper function, but I believe it
should work...
So no warranty at all!

The hardware is:

- AT90S8535
- AD9832BRU
- 24.000 MHz TTL-Oscillator
- optical rotary encoder (Grayhill 62A series)

Have fun!

--
Greetings from Weimar / Germany


Thomas Voigt



And here's the code:

######################### START OF CODE ##############################
'
' Simple DDS for AT90S8535 & AD9832BRU & LCD & rotary encode
'
' Fword's are computed for 24.000 MHz reference clock
'
' Rotary encoder procedures are from
' http://www.grote.net/bascom/msg06492.html
'
' DDS functions are based on
' http://www.njqrp.org/ham-pic/sm6lkm/ad9832_3.asm.txt
'
$regfile = "8535DEF.DAT"
$crystal = 4000000
Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.1 ,
Db7 = Portc.0 , E = Portc.4 , Rs = Portc.5
Config Lcd = 24 * 2

' AD9832
Config Pind.0 = Output 'Sclk
Config Pind.1 = Output 'SData
Config Pind.2 = Output 'Fsync
Sclk Alias Portd.0
Sdata Alias Portd.1
Fsync Alias Portd.2

' Rotary Encoder
Config Pind.6 = Input
Config Pind.7 = Input
Ch_a Alias Pind.6                                           'Channel A
connected to INT0 pin
Ch_b Alias Pind.7                                           'Channel B
can be connected to any other pins


' Using Overlay for accessing the bytes of the word
Dim Fword0 As Long At &H60
Dim Low_byte0 As Byte At &H60 Overlay
Dim Low_mid_byte0 As Byte At &H61 Overlay
Dim High_mid_byte0 As Byte At &H62 Overlay
Dim High_byte0 As Byte At &H63 Overlay

Dim Fword1 As Long At &H64
Fword1 = &H1FBD4DAF                                         ' for
2.975575 MHz
Dim Low_byte1 As Byte At &H64 Overlay
Dim Low_mid_byte1 As Byte At &H65 Overlay
Dim High_mid_byte1 As Byte At &H66 Overlay
Dim High_byte1 As Byte At &H67 Overlay

Dim Fw0 As Long

Dim Encode_old As Byte , Encode_new As Byte , Pos_count As Long ,
Pos_old As Long
Config Timer0 = Timer , Prescale = 8  'INT every 256µS with 8MHz Xtal
On Timer0 Tim0_isr
Enable Timer0
Enable Interrupts

' Step width for DDS
Dim Dds_step As Single
Dds_step = 0.00558793544769287109375

Dim Freq As Single
Freq = 1000000 / Dds_step
Fw0 = Freq
Fword0 = Fw0

Dim Temp As Long

Declare Sub Init_dds()
Declare Sub Load_dds0
Declare Sub Load_dds1
Declare Sub Activate_dds(byval Nr As Byte)
Declare Sub Send_dds(byval Sw As Word)

Call Init_dds
Call Load_dds0
Call Load_dds1
Call Activate_dds(0)
Freq = 1000000

Cls
Lcd "Frequency: "
Do
   Idle
   If Pos_count <> Pos_old Then
      Freq = 1000000 + Pos_count
      Fword0 = Freq / Dds_step
      Call Load_dds0
      Call Activate_dds(0)
      Pos_old = Pos_count
   End If

   Locate 1 , 12
   Lcd Int(freq) ; "  "
Loop
End
'########################################################################
Sub Init_dds
   Upperline
   Lcd "Init DDS..."
   Disable Interrupts
   Call Send_dds(&Hf800)
   Call Send_dds(&Hb000)
   Call Send_dds(&Hc000)
   Enable Interrupts

End Sub

Sub Load_dds0
   Disable Interrupts
   Call Send_dds(&H3000 + Low_byte0)
   Call Send_dds(&H2100 + Low_mid_byte0)
   Call Send_dds(&H3200 + High_mid_byte0)
   Call Send_dds(&H2300 + High_byte0)
   Call Activate_dds(0)
   Enable Interrupts
End Sub

Sub Load_dds1
   Disable Interrupts
   Call Send_dds(&H3400 + Low_byte1)
   Call Send_dds(&H2500 + Low_mid_byte1)
   Call Send_dds(&H3600 + High_mid_byte1)
   Call Send_dds(&H2700 + High_byte1)
   Call Activate_dds(1)
   Enable Interrupts
End Sub

Sub Activate_dds(byval Nr As Byte)
   Select Case Nr
      Case 0 : Call Send_dds(&H5000)
      Case 1 : Call Send_dds(&H5800)
   End Select
End Sub

Sub Send_dds(byval Sw As Word)
   Disable Interrupts
   Reset Fsync
   Home
   Shiftout Sdata , Sclk , Sw , 1 , 16
   Set Fsync
   Reset Sdata
   Enable Interrupts
End Sub

'The following ISR must be called at least every 4*F_pulse
'e.g. every 256µS if the frequency of the encodersignal is < 1kHz
Tim0_isr:
  Encode_new.0 = Ch_a                                       'Cha Input
  Encode_new.1 = Ch_b                                       'Chb Input
  Select Case Encode_old
       Case 0 :
         Select Case Encode_new
            Case 1 : Incr Pos_count
            Case 2 : Decr Pos_count
         End Select
       Case 1 :
         Select Case Encode_new
            Case 0 : Decr Pos_count
            Case 3 : Incr Pos_count
         End Select
       Case 2 :
         Select Case Encode_new
            Case 3 : Decr Pos_count
            Case 0 : Incr Pos_count
         End Select
       Case 3 :
         Select Case Encode_new
            Case 1 : Decr Pos_count
            Case 2 : Incr Pos_count
         End Select
  End Select
  Encode_old = Encode_new
Return
########################### END OF CODE ##############################