Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Direct Digital Synthesis. (DDS)
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
davidapex

Bascom Member



Joined: 12 Mar 2006
Posts: 42
Location: Auckland

newzealand.gif
PostPosted: Sat May 20, 2006 1:18 am    Post subject: Reply with quote

Hello Luciano,
Thanks for confirming that I'm not getting too old for this activity.
I would like to nod my head in agreement with your finding but to be honest I can't see why the delay is value dependent or is this assumption incorrect?
Can you please expand on how the delay is effected by the "Enable PCInt0"

BTW Have you seen how many views this thread of yours has generated? Could be a high score!

Best regards,
David
Back to top
View user's profile
davidapex

Bascom Member



Joined: 12 Mar 2006
Posts: 42
Location: Auckland

newzealand.gif
PostPosted: Sat May 20, 2006 1:39 am    Post subject: Reply with quote

Hi All,
Just confirming the fix that Luciano posted - everything is now perfect.
I can now enter 100, 1000, 10,000, 100,000, 1,000,000 and the decimal point on the frequency counter just shifts along accordingly. Impressive!

I can highly recommend this as great academic exercise, especially for students wanting an understanding of the principles of DDS.
I am grateful to Luciano for his excellent piece of code that he has shared with us all.

Best regards,
David
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Sat May 20, 2006 9:34 am    Post subject: Reply with quote

David,

You are welcome!
The merit goes to the authors of the original code.

Best regards,
Luciano

* * *

Direct Digital Synthesis. (DDS)

Jesper Hansen author of the original code
http://www.myplace.nu/avr/minidds/

Modified for the Atmel AVR assembler by Leon Heller.
http://www.geocities.com/leon_heller/minidds.html

* * *
Tutorial about DDS:
http://www.analog.com/library/analogDialogue/archives/38-08/dds.html
http://www.analog.com/library/analogDialogue/archives/38-08/dds.pdf
-


Last edited by Luciano on Fri Jul 18, 2008 6:14 am; edited 2 times in total
Back to top
View user's profile
atmega64

Bascom Member



Joined: 23 Feb 2005
Posts: 298
Location: ITALY

italy.gif
PostPosted: Tue Dec 05, 2006 3:49 pm    Post subject: SINE WAVE Reply with quote

Hi Luciano, Laughing

I use ATmega32 µP with 8000000 crystal and I must have as output sine wave with frequency 2.5KHz.

According the above mentioned how can I change the following code?

Best Regards
Tony


********************************************************
Luciano wrote:

Code:

' Direct Digital Synthesis. (DDS)
'
' See this tutorial about DDS:
' http://www.analog.com/UploadedFiles/Tutorials/450968421DDS_Tutorial_rev12-2-99.pdf
'
'
' The author of the original code is Jesper Hansen.
' http://www.myplace.nu/avr/minidds/
'
' Modified for the Atmel AVR assembler by Leon Heller.
' http://www.geocities.com/leon_heller/minidds.html
'
' * * * * *
'
' Connected to PortB there is a resistor ladder (R2R).
' This is just one part of the original code.
' The original code will output sine, sawtooth, triangle. square.
' (See the above two links first).
'
' When you run this sample, on the output of the resistor ladder
' you will see a 1 kHz sine wave. (You will need a 11059200 crystal).
' If you use another AVR chip or if you change the code size you will have
' to recalculate how many bytes you will need in the table Dummy_data.

'
' Luciano, 3/18/2006
'
'
$regfile = "ATtiny2313.DAT"
$crystal = 11059200

$hwstack = 32
$swstack = 16
$framesize = 32

Config Portb = Output 'R2R ladder


$asm

' set pointer to table

ldi ZH,high (Sine_table * 2) ' setup Z pointer hi
ldi ZL,low (Sine_table * 2) ' setup Z pointer lo

' clear accumulator

ldi r29,$00 ' clear accumulator
ldi r28,$00 ' clear accumulator

' setup adder registers

' adder value for 10 Hz
' ldi r24,$88
' ldi r25,$00
' ldi r26,$00


' adder value for 100 Hz
' ldi r24,$55
' ldi r25,$05
' ldi r26,$00

' adder value for 1 kHz
ldi r24,$56
ldi r25,$35
ldi r26,$00

' adder value for 10 kHz
' ldi r24,$55
' ldi r25,$15
' ldi r26,$02 '

' adder value for 100 kHz
' ldi r24,$55
' ldi r25,$D5
' ldi r26,$14


' Output frequency (using 24 bit accumulator) :
'
' f = deltaPhase * fClock/2^24
'
' fClock is in this case the CPU clock divided by the
' number of cycles to output the data ( 9 cycles )
'
' f = r24/r25/r26 * (11059200/9)/16777216
'
' f = r24/r25/r26 * 0.073242188
'
' fMax (theoretical) = 0.5 * fClock

' ===================================================================
Loop1:

add r28,r24 ' 1 cycle
adc r29,r25 ' 1 cycle
adc r30,r26 ' 1 cycle
lpm ' 3 cycles
Out Portb , R0 ' 1 cycle
rjmp Loop1 ' 2 cycles

' -----------------
' Total 9 cycles
'
' The above loop:
'
' r28,r29,r30 is the phase accumulator
' r24,r25,r26 is the adder value determining frequency
'
' add value to accumulator
' load byte from current table in ROM
' output byte to port
' repeat

' ====================================================================
$end Asm


End


Dummy_data:

Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
Data 1 , 2 , 3 , 4 , 5 , 6


' In this program the table MUST begin at 256 byte boundary and the previous
' dummy_data bytes are used to reach the boundary. In this sample we need 146
' bytes to reach 256 byte boundary. Use AVR Studio to find out how many bytes
' your code will need. (AVR Studio, Disassembler window).
'
' The boundaries are at (DEC) : 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048.......
' The boundaries are at (HEX) : 0, 100, 200, 300, 400, 500, 600, 700, 800.......
' You can use any of these boundaries.

Sine_table:
'256 values

Data &H80 , &H83 , &H86 , &H89 , &H8C , &H8F , &H92 , &H95
Data &H98 , &H9C , &H9F , &HA2 , &HA5 , &HA8 , &HAB , &HAE
Data &HB0 , &HB3 , &HB6 , &HB9 , &HBC , &HBF , &HC1 , &HC4
Data &HC7 , &HC9 , &HCC , &HCE , &HD1 , &HD3 , &HD5 , &HD8
Data &HDA , &HDC , &HDE , &HE0 , &HE2 , &HE4 , &HE6 , &HE8
Data &HEA , &HEC , &HED , &HEF , &HF0 , &HF2 , &HF3 , &HF5
Data &HF6 , &HF7 , &HF8 , &HF9 , &HFA , &HFB , &HFC , &HFC
Data &HFD , &HFE , &HFE , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFE , &HFE
Data &HFD , &HFC , &HFC , &HFB , &HFA , &HF9 , &HF8 , &HF7
Data &HF6 , &HF5 , &HF3 , &HF2 , &HF0 , &HEF , &HED , &HEC
Data &HEA , &HE8 , &HE6 , &HE4 , &HE2 , &HE0 , &HDE , &HDC
Data &HDA , &HD8 , &HD5 , &HD3 , &HD1 , &HCE , &HCC , &HC9
Data &HC7 , &HC4 , &HC1 , &HBF , &HBC , &HB9 , &HB6 , &HB3
Data &HB0 , &HAE , &HAB , &HA8 , &HA5 , &HA2 , &H9F , &H9C
Data &H98 , &H95 , &H92 , &H8F , &H8C , &H89 , &H86 , &H83
Data &H80 , &H7C , &H79 , &H76 , &H73 , &H70 , &H6D , &H6A
Data &H67 , &H63 , &H60 , &H5D , &H5A , &H57 , &H54 , &H51
Data &H4F , &H4C , &H49 , &H46 , &H43 , &H40 , &H3E , &H3B
Data &H38 , &H36 , &H33 , &H31 , &H2E , &H2C , &H2A , &H27
Data &H25 , &H23 , &H21 , &H1F , &H1D , &H1B , &H19 , &H17
Data &H15 , &H13 , &H12 , &H10 , &H0F , &H0D , &H0C , &H0A
Data &H09 , &H08 , &H07 , &H06 , &H05 , &H04 , &H03 , &H03
Data &H02 , &H01 , &H01 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H01 , &H01
Data &H02 , &H03 , &H03 , &H04 , &H05 , &H06 , &H07 , &H08
Data &H09 , &H0A , &H0C , &H0D , &H0F , &H10 , &H12 , &H13
Data &H15 , &H17 , &H19 , &H1B , &H1D , &H1F , &H21 , &H23
Data &H25 , &H27 , &H2A , &H2C , &H2E , &H31 , &H33 , &H36
Data &H38 , &H3B , &H3E , &H40 , &H43 , &H46 , &H49 , &H4C
Data &H4F , &H51 , &H54 , &H57 , &H5A , &H5D , &H60 , &H63
Data &H67 , &H6A , &H6D , &H70 , &H73 , &H76 , &H79 , &H7C
**********************************************************
Back to top
View user's profile Visit poster's website
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Tue Dec 05, 2006 6:13 pm    Post subject: Re: SINE WAVE Reply with quote

atmega64 wrote:
According the above mentioned how can I change the following code?


Hi Tony,

You will find the answer if you read the four pages of this thread.

Best regards,

Luciano
Back to top
View user's profile
atmega64

Bascom Member



Joined: 23 Feb 2005
Posts: 298
Location: ITALY

italy.gif
PostPosted: Wed Dec 06, 2006 8:25 am    Post subject: SINUSOID WAVE Reply with quote

Hi,

I had not seen that they were 4 pages..... Confused

thank you however Laughing

Tony
Back to top
View user's profile Visit poster's website
tblough

Bascom Member



Joined: 21 Feb 2007
Posts: 1
Location: Suzho (Shanghai), China

usa.gif
PostPosted: Thu Feb 22, 2007 10:37 am    Post subject: Schematics, board layouts? Reply with quote

David, Luciano,

Just stumbled across this thread and wondered if either of you had any more details on your finished DDS generators? Do you have schematics or board layouts? Any further modifications of the code? One of the earlier posts by Luciano showed a 4x4 keypad and LCD mockup. Did that ever get built?

I'm not near advanced enough at this stage to really understand what you've done, but I would love to copy it!

TIA

_________________
Tom Blough
Back to top
View user's profile Visit poster's website
Matrixx

Bascom Member



Joined: 30 Nov 2005
Posts: 158

mexico.gif
PostPosted: Fri Jan 04, 2008 9:22 pm    Post subject: Reply with quote

Wow!! My best regards all of you for this amazing post!! Luciano and davidapex for keep the thread alive. Cool

I have read the 4 pages as deep as I can, and I belive I will adapt to an M128 with your help.

My actual project is this: Gps Mph to frequency converter.

I'm using a M32 to read a 5hz gps @ 38400. I extract the speed only, but because the Gps keeps very busy the M32, I decided to use a second Avr as the "main" controller, leaving the gps issues to the M32 only. I setup 2 full ports on the M32 (PA.x and PC.x) to output the speed value directly in integer number. To get advantage of the decimals, I have scaled up the mph by 100 so 38.95 mph * 100 will be 3895.

On the other side, I use 2 the M128 to read the M32 value and scale down to normalize it. I have a LCD where the speed is displayed.

***** Here is where you fire a light for me. *******

Do you think the DDS code will work for this... ? updating the registers from the values from the M32 to have a frequency generated that follows the speed values. Will be good to have say a 1khz/mph so the 38.95 mph will be translated to some closer to 3895 hz...

I don't need a sinewave so may be can reduce the table for a square wave with less "points".. ?

Cheers 4 all and hope have you had a Merry Chritsmas!!! Very Happy
Back to top
View user's profile
Matrixx

Bascom Member



Joined: 30 Nov 2005
Posts: 158

mexico.gif
PostPosted: Fri Jan 04, 2008 11:57 pm    Post subject: Reply with quote

This is my actual code of the M128 to read the speed from the M32:

Sub Readspeed
Byteh = Pind 'use 2 8 bit ports to get a 16 bit value
Bytel = Pinc
Bintext = "" 'some tricky conversion...
Bintext = Bin(byteh)
Bintext = Bintext + Bin(bytel)
Tmpword = Binval(bintext)
Speed = Tmpword / 100 'speed value, scaled down from the M32
End Sub


mm.. seems I will end using only a 16 bit adder.. ?

On monday I will continue the development...
Back to top
View user's profile
Matrixx

Bascom Member



Joined: 30 Nov 2005
Posts: 158

mexico.gif
PostPosted: Mon Jan 07, 2008 6:31 pm    Post subject: Reply with quote

This is the graph, looks distorted at the end of each cycle. This is because the boundaries are not adjusted yet.. ?


Back to top
View user's profile
Matrixx

Bascom Member



Joined: 30 Nov 2005
Posts: 158

mexico.gif
PostPosted: Tue Jan 08, 2008 11:46 pm    Post subject: Reply with quote

I have connected a 8 position DIP switch to the portd of the M128. I have pullup resistors for each pin and the DIP switch conmutates to ground. I see the state of the pins change but the output frequency don't change.

this is my try:

Loop1:
'------------------- my modification
ldi r24,portd
ldi r25,portd
ldi r26,$00
'--------------------

add r28,r24 ' 1 cycle
adc r29,r25 ' 1 cycle
adc r30,r26 ' 1 cycle
lpm ' 3 cycles
Out Portb , R0 ' 1 cycle
rjmp Loop1




another try:

Loop1:
'------------------- my modification
add r24,portd
add r25,portd
add r26,$00
'--------------------

add r28,r24 ' 1 cycle
adc r29,r25 ' 1 cycle
adc r30,r26 ' 1 cycle
lpm ' 3 cycles
Out Portb , R0 ' 1 cycle
rjmp Loop1


another try:

Loop1:
'------------------- my modification
In r24,$12 <--- $12 is the portd register as I understand ?
In r25,$12
In r26,$00
'--------------------

add r28,r24 ' 1 cycle
adc r29,r25 ' 1 cycle
adc r30,r26 ' 1 cycle
lpm ' 3 cycles
Out Portb , R0 ' 1 cycle
rjmp Loop1


What I'm missing... ?
Back to top
View user's profile
Matrixx

Bascom Member



Joined: 30 Nov 2005
Posts: 158

mexico.gif
PostPosted: Wed Jan 09, 2008 10:16 pm    Post subject: Reply with quote

I'm not good with assembler. Since I can't find how to read the port D and C using assembler, then I did a change to mix bascom and asm.

I have disabled the asm loop and put all the main code in to a bascom loop, to have chance of read the ports the way I know...

Can you recommend some literature to learn how to find the correct amount of padding data to start at the correct boundary? I know is with avrstudio, I have it but can't figure out how to interpret hoy many dummay data to add....

I'm getting the wave distorted (only the halve and the rest as flat), take a look:



this is my code.
Back to top
View user's profile
Gianni

Bascom Member



Joined: 09 Jul 2004
Posts: 61
Location: Italy

blank.gif
PostPosted: Thu Jan 10, 2008 12:23 am    Post subject: Re: Schematics, board layouts? Reply with quote

tblough wrote:
David, Luciano,

Just stumbled across this thread and wondered if either of you had any more details on your finished DDS generators? Do you have schematics or board layouts? Any further modifications of the code? One of the earlier posts by Luciano showed a 4x4 keypad and LCD mockup. Did that ever get built?

I'm not near advanced enough at this stage to really understand what you've done, but I would love to copy it!

TIA


Look at my web page. (AVR)
Regards
Back to top
View user's profile
Matrixx

Bascom Member



Joined: 30 Nov 2005
Posts: 158

mexico.gif
PostPosted: Fri Jan 11, 2008 3:25 pm    Post subject: Reply with quote

Ok guys. I have solved the distorted waveform. Since I still don't know how to find the "boundary" limit using the avrstudio, I decided to add dummy data in a trial-and-error basis, until I found a clean sinewave. The DDS is working fine for me now, using the M128 and having the PortC and portD as registers input.

I have almost finishing my project and will open a new topic to share this. I think is a very interesting project Very Happy

This is the simulator snapshot:



And this the real scope image...
Back to top
View user's profile
Ismael

Bascom Member



Joined: 17 Jun 2005
Posts: 18
Location: Australia

australia.gif
PostPosted: Mon Jun 23, 2008 3:08 pm    Post subject: Reply with quote

If you follow this link you can see what has been done. Check Page 3 towards the bottom. Excellent job. Here's the link:

http://forum.scienceprog.com/viewtopic.php?f=9&t=281&st=0&sk=t&sd=a

My question is can anyone convert the source code (C code) into Bascom AVR? I am building this but would prefer a program that I can understand better. From what I have read here the code posted here is not full. Attached is the source code. This is the latest modified source that incorporates some filtering changes.

_________________
Regards Ismael
http://www.minelabmods.com
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 4 of 6

 
Jump to:  
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