Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Direct Digital Synthesis. (DDS)
Goto page 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
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Sat Mar 18, 2006 1:13 am    Post subject: Direct Digital Synthesis. (DDS) Reply with quote

Hi,

When I saw the original project I was fascinated...
http://www.myplace.nu/avr/minidds/

Luciano

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
 


Resistor ladder (R2R)


The 1 kHz sine wave on the R2R output:

(Click to enlarge the picture).


Last edited by Luciano on Thu May 03, 2007 8:41 pm; edited 1 time in total
Back to top
View user's profile
davidapex

Bascom Member



Joined: 12 Mar 2006
Posts: 42
Location: Auckland

newzealand.gif
PostPosted: Sat Mar 18, 2006 2:59 am    Post subject: Reply with quote

Hello Luciano,
Many thanks for posting your code for the DDS.
I also have played with simple DDS but my background is with Pics and I am total beginner to AVR.
I just posted some early code under "Sine table" (Bascom-AVR) as I had noise on my waveform and resorted to fitting LCD to read data values going to port d. I since found the simulator -very nice!.
I think you hve answered my problem - my table screws up badly at value 241 of 256 so I suspect your caution of crossing a boundary may be the reason. I would never have found this myself.
Is it possible to use the manual programme function to look at the code and determine where the table is sitting and then add padding values to shift it to a starting point?
Thanks again.

Cheers,
David
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2479
Location: Queensland

australia.gif
PostPosted: Sat Mar 18, 2006 5:31 am    Post subject: Reply with quote

I started with this code too, and soon realised that its even better to preload all the values into a table in RAM, then cycle through them there. Access from RAM is only 1 clock cycle, rather than the 3 needed for an lpm. Also you can specify where the RAM varaibles are by using something like
dim Wavetable(256) as byte at $100
this ensures they are on a page boundary, making the assembly code even easier - you only have to increment 1 register to get the next address.
To get the wavetable from ROM:

restore sinetable
for wPhase = 1 to 256
read WaveTable(wPhase)
next wPhase

I also decided to use an MAX5102 DAC for the output. it allows 2 channels, so you can have stereo, and is a 1 chip solution, rather than a bunch of resistors followed by an opamp.

_________________
Adrian Jansen
Computer language is a framework for creativity
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: Sat Mar 18, 2006 10:32 am    Post subject: Reply with quote

Hi,

The original project was using an AT90S2313 with 128 bytes of SRAM.
Yes, if the AVR chip you are using has more than 256 bytes of SRAM then
load the table in SRAM as Adrian is suggesting.
(The ATmega48 has 512 bytes of SRAM and is cheap).

* * *

Quote:

Is it possible to use the manual programme function to look at the code
and determine where the table is sitting and then add padding values to
shift it to a starting point?


Make sure the Bascom "AVR Studio Object file" is selected.
(Bascom AVR menu Options\Compiler\Output).
Compile the program with Bascom AVR.

In the Atmel AVR studio (free tool from Atmel) go to the menu
"File" and open the Bascom file your_file_name.OBJ.

After you select the object file, AVR Studio asks for a file name
for the project. (Just press Save).

A window will open. Select "AVR Simulator" as debug platform and
the AVR chip you are using from the list on the right.
Press the button "Finish" and AVR Studio will open the project.

From the AVR Studio menu "View" select "Disassembler" and
you will see the disassembled code. (See below an extract).

In this example the table "Sine_table" is located
at the first 256 byte boundary. (HEX 100).

Code:

40:         ldi  ZH,high (Sine_table * 2)
+00000028:   E0F1        LDI     R31,0x01 '0x01 is the address high byte  
            ldi  ZL,low (Sine_table * 2)
+00000029:   E0E0        LDI     R30,0x00 '0x00 is the address low byte
 


If you don't see the address of a 256 byte boundary, (0, 100, 200, 300,
400, 500, 600, 700, 800, ...) then add or remove bytes in the table Dummy_data.

Best regards,

Luciano

Sub-low cost R2R hardware:


Last edited by Luciano on Thu May 03, 2007 8:44 pm; edited 1 time in total
Back to top
View user's profile
davidapex

Bascom Member



Joined: 12 Mar 2006
Posts: 42
Location: Auckland

newzealand.gif
PostPosted: Sat Mar 18, 2006 12:29 pm    Post subject: Reply with quote

Hi Luciano,
I copied your code, changed the device type and output port and bingo....well , not quite but as soon as I adjusted the padding values it all looked very nice.
I found I could view the flash code in the Bascom Programmer by using manual mode and after a couple of adjustments it was starting at the boundary.
I will also try placing the table in RAM as you and Adrian have suggested.

Nice R2R ladder! I was fortunate to get a couple of Dale R2R ladders in 10 pin SIP - very handy little part but yes they do need to be buffered to be useful.

When playing with Pics I found I could run 2 accumulators and their respective phase increment values and output two frequencies by using two 4 bit ports. You could also do quadrature phases of the same frequency. I never had an application for DDS but it always seemed like an interesting concept to get your head around.

Cheers,
David
Back to top
View user's profile
davidapex

Bascom Member



Joined: 12 Mar 2006
Posts: 42
Location: Auckland

newzealand.gif
PostPosted: Sat Mar 25, 2006 12:20 am    Post subject: DDS (again) Reply with quote

Hi All,
After having a play with the code I would like to add other wave tables (as per original article) but would like to select them following an interrupt and a Basic routine.

Can I replace the following assembler code with Basic?

' set pointer to table

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

As I understand it the only fast routine needs to be the Loop1 code (9 cycles) and all other code could run under Basic so I was thinking an interrupt that breaks the loop and jumps to a wave table and frequency selection routine should be OK.

Cheers,
David
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2479
Location: Queensland

australia.gif
PostPosted: Sat Mar 25, 2006 1:35 am    Post subject: Reply with quote

You can do what you want in Basic. What you need to do is get the address of the wavetable into Z.
Define a word variable in ram:
dim wWaveAddress as word

Then change that bit of code into
lds zl,{low wWaveAddress)
lds zh,{high wWaveAddress}

then the routine will pick up the numbers you have put in wWaveAddess and use them to set the start of the wavetable.

So in Basic you just set the variable wWaveAddress to point anywhere in the Flash

eg
wWaveAddress = &h3e00

and of course you can change it anytime you want.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
davidapex

Bascom Member



Joined: 12 Mar 2006
Posts: 42
Location: Auckland

newzealand.gif
PostPosted: Sat Mar 25, 2006 5:28 am    Post subject: Reply with quote

Hello Adrian,
Many thanks for the "pointers". (v small joke)
Will give it a go tonight.

Cheers,
David
Back to top
View user's profile
davidapex

Bascom Member



Joined: 12 Mar 2006
Posts: 42
Location: Auckland

newzealand.gif
PostPosted: Sat Mar 25, 2006 6:55 am    Post subject: Reply with quote

Hello Adrian,
Have I screwed up here?

dim tableloc as word 'var for location of Sin_table

'******wave select********"
tableloc = &H0200 'sine table=&H0200, tri table=&H0300,.....

$asm
lds zl , {low tableloc}
lds zh , {high tableloc}

It compiles with errors on both the last lines "Error 5 - No more space for bit"
What have I missed?

Cheers,
David
Back to top
View user's profile
DToolan

Bascom Member



Joined: 14 Aug 2004
Posts: 1384
Location: Dallas / Fort Worth, Texas (USA)

blank.gif
PostPosted: Sat Mar 25, 2006 6:25 pm    Post subject: Reply with quote

Bascom has a helper function to do that for you...

Code:
LOADADR tableloc, Z
Back to top
View user's profile Yahoo Messenger
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Sat Mar 25, 2006 7:14 pm    Post subject: Reply with quote

Hi,

LOADADR loads the address of a variable into a register pair.
I don't think you can use it to load the content of a variable.

Just use assembly and let the compiler calculate the address.

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

Luciano
Back to top
View user's profile
davidapex

Bascom Member



Joined: 12 Mar 2006
Posts: 42
Location: Auckland

newzealand.gif
PostPosted: Sat Mar 25, 2006 11:05 pm    Post subject: Reply with quote

Hi guys,
I'm not going well here. How do I use Basic to pass the various wave table start addresses to the assembler routine?
e.g. In the following, how do I change Sawtooth to Sine, Square etc

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

Ultimately I would like to sense a pin and change the waveform accordingly.

BTW Just found someone else playing with DDS but using a Silicon Labs micro with an on-board 12bit DAC - nice!

Cheers,
David
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Sun Mar 26, 2006 12:15 am    Post subject: Reply with quote

Hi,

See Help file "Mixing ASM and BASIC".

Luciano

...
...
...
basic code ...
basic code ...
basic code ...
$asm
assembly code...
assembly code...
assembly code...
$end Asm
basic code ...
basic code ...
basic code ...
basic code ...
$asm
assembly code...
assembly code...
assembly code...
$end Asm
basic code ...
basic code ...
basic code ...
basic code ...
...
...


(Click to enlarge)


Last edited by Luciano on Thu May 03, 2007 8:51 pm; edited 2 times in total
Back to top
View user's profile
davidapex

Bascom Member



Joined: 12 Mar 2006
Posts: 42
Location: Auckland

newzealand.gif
PostPosted: Sun Mar 26, 2006 12:12 pm    Post subject: Reply with quote

Hello Luciano,
I'm familiar with the in-line assembler as it very similar to the Pic in-line assembler that I'm more comfortable with.
I'm still not following how to pass the different table locations to the assembler routine so will need to read up on this a bit more.
In the mean time I can have an assembler programme for each waveform and select which one I run from Basic. A bit clunky but the code overhead is minimal.

BTW Nice keypad!

Cheers,
David
Back to top
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Sun Mar 26, 2006 7:58 pm    Post subject: Reply with quote

Hi David,

With the code below you can change the DDS output signal
from within an interrupt routine. The sample below uses INT0.

(I don't have any code for the device of my previous post, it was just an idea).

Best regards,

Luciano

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 was 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, see above links.
'
' When your run this sample, on the output of the resistor ladder
' you will see a 1 kHz sine wave. (You will need a 11059200 crystal).
'
' Connect a push button to GND and to the INT0 pin. When the interrupt
' occurs, the output signal of the DDS will change as following:
'
' Sine 1 kHz > Square 2 kHz > Triangle 3 kHz > Sawtooth 4 kHz > back to Sine
'
' 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/26/2006
'
'
$regfile = "ATtiny2313.DAT"
$crystal = 11059200

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

Config Portb = Output       'R2R ladder

Config Int0 = Falling
On Int0 Int0_isr Nosave    ' Must use NOSAVE
Set Portd.2                'Enable internal pull-up resistor on INT0 pin

Dim Toggle_counter As Byte
Dim Adder_bits_0_7 As Byte
Dim Adder_bits_8_15 As Byte
Dim Adder_bits_16_23 As Byte

Enable Int0
Enable Interrupts

$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

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


' ===================================================================
Main_loop:

  add  r28,r24        ' 1 cycle
  adc  r29,r25        ' 1 cycle
  adc  r30,r26        ' 1 cycle
  lpm                 ' 3 cycles
  Out Portb , R0      ' 1 cycle
  rjmp Main_loop      ' 2 cycles
  '                  -----------------
                      Total 9 cycles
' ====================================================================
$end Asm


End


'***************************************************
'Interrupt routine
'Your Bascom Basic code goes in this Interrupt routine.

Int0_isr:

Disable Int0
Waitms 250   ' wait for contacts debouncing

Incr Toggle_counter


If Toggle_counter = 4 Then

   Toggle_counter = 0

End If


If Toggle_counter = 0 Then

   'We set the variables for 2 kHz     
   Adder_bits_0_7 = &H55  
   Adder_bits_8_15 = &H35
   Adder_bits_16_23 = &H00

   'Must be last two instructions in this IF
   !ldi  ZH,high (Sine_table * 2)     ' setup Z pointer hi
   !ldi  ZL,low (Sine_table * 2)      ' setup Z pointer lo

End If


If Toggle_counter = 1 Then

   'We set the variables for 2 kHz
   Adder_bits_0_7 = &HAA
   Adder_bits_8_15 = &H6A
   Adder_bits_16_23 = &H00

   'Must be last two instructions in this IF
   !ldi  ZH,high (Square_table * 2)   ' setup Z pointer hi
   !ldi  ZL,low (Square_table * 2)    ' setup Z pointer lo

End If


If Toggle_counter = 2 Then

   'We set the variables for 3 kHz
   Adder_bits_0_7 = &HFF
   Adder_bits_8_15 = &H9F
   Adder_bits_16_23 = &H00


   'Must be last two instructions in this IF
   !ldi  ZH,high (Triangle_table * 2)  ' setup Z pointer hi
   !ldi  ZL,low (Triangle_table * 2)   ' setup Z pointer lo


End If


If Toggle_counter = 3 Then

   'We set the variables for 4 kHz
   Adder_bits_0_7 = &H55
   Adder_bits_8_15 = &HD5
   Adder_bits_16_23 = &H00

   'Must be last two instructions in this IF
   !ldi  ZH,high (Sawtooth_table * 2)  ' setup Z pointer hi
   !ldi  ZL,low (Sawtooth_table * 2)   ' setup Z pointer lo

End If

Set EIFR.6   ' clear Int0 flag set by contacts bouncing.
' See the datasheet of your AVR for the location of the "External Interrupt Flag"

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

Loadadr Adder_bits_0_7 , X       'load the address of the variable into R26 and R27 (X)
!ld r24, X                       'load the value of the variable into R24

Loadadr Adder_bits_8_15 , X      'load the address ofthe variable into R26 and R27 (X)
!ld r25, X                       'load the value of the variable into R25

Loadadr Adder_bits_16_23 , X     'load the address of the variable into R26 and R27 (X)
!ld r26, X                       'load the value of the variable into R26


Enable Int0


Return


'***************************************************


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 , 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


' In this program the tables MUST begin at 256 byte boundary and the previous
' dummy_data bytes are used to reach the boundary. In this sample we need 184
' bytes to reach the boundary. Use AVR Studio to find out how many bytes
' your code will needs. (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


Square_table:
'256 values

Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF


Triangle_table:
'256 values

Data &H00 , &H02 , &H04 , &H06 , &H08 , &H0A , &H0C , &H0E
Data &H10 , &H12 , &H14 , &H16 , &H18 , &H1A , &H1C , &H1E
Data &H20 , &H22 , &H24 , &H26 , &H28 , &H2A , &H2C , &H2E
Data &H30 , &H32 , &H34 , &H36 , &H38 , &H3A , &H3C , &H3E
Data &H40 , &H42 , &H44 , &H46 , &H48 , &H4A , &H4C , &H4E
Data &H50 , &H52 , &H54 , &H56 , &H58 , &H5A , &H5C , &H5E
Data &H60 , &H62 , &H64 , &H66 , &H68 , &H6A , &H6C , &H6E
Data &H70 , &H72 , &H74 , &H76 , &H78 , &H7A , &H7C , &H7E
Data &H80 , &H82 , &H84 , &H86 , &H88 , &H8A , &H8C , &H8E
Data &H90 , &H92 , &H94 , &H96 , &H98 , &H9A , &H9C , &H9E
Data &HA0 , &HA2 , &HA4 , &HA6 , &HA8 , &HAA , &HAC , &HAE
Data &HB0 , &HB2 , &HB4 , &HB6 , &HB8 , &HBA , &HBC , &HBE
Data &HC0 , &HC2 , &HC4 , &HC6 , &HC8 , &HCA , &HCC , &HCE
Data &HD0 , &HD2 , &HD4 , &HD6 , &HD8 , &HDA , &HDC , &HDE
Data &HE0 , &HE2 , &HE4 , &HE6 , &HE8 , &HEA , &HEC , &HEE
Data &HF0 , &HF2 , &HF4 , &HF6 , &HF8 , &HFA , &HFC , &HFE
Data &HFF , &HFD , &HFB , &HF9 , &HF7 , &HF5 , &HF3 , &HF1
Data &HEF , &HEF , &HEB , &HE9 , &HE7 , &HE5 , &HE3 , &HE1
Data &HDF , &HDD , &HDB , &HD9 , &HD7 , &HD5 , &HD3 , &HD1
Data &HCF , &HCF , &HCB , &HC9 , &HC7 , &HC5 , &HC3 , &HC1
Data &HBF , &HBD , &HBB , &HB9 , &HB7 , &HB5 , &HB3 , &HB1
Data &HAF , &HAF , &HAB , &HA9 , &HA7 , &HA5 , &HA3 , &HA1
Data &H9F , &H9D , &H9B , &H99 , &H97 , &H95 , &H93 , &H91
Data &H8F , &H8F , &H8B , &H89 , &H87 , &H85 , &H83 , &H81
Data &H7F , &H7D , &H7B , &H79 , &H77 , &H75 , &H73 , &H71
Data &H6F , &H6F , &H6B , &H69 , &H67 , &H65 , &H63 , &H61
Data &H5F , &H5D , &H5B , &H59 , &H57 , &H55 , &H53 , &H51
Data &H4F , &H4F , &H4B , &H49 , &H47 , &H45 , &H43 , &H41
Data &H3F , &H3D , &H3B , &H39 , &H37 , &H35 , &H33 , &H31
Data &H2F , &H2F , &H2B , &H29 , &H27 , &H25 , &H23 , &H21
Data &H1F , &H1D , &H1B , &H19 , &H17 , &H15 , &H13 , &H11
Data &H0F , &H0F , &H0B , &H09 , &H07 , &H05 , &H03 , &H01


Sawtooth_table:
'256 values

Data &H00 , &H01 , &H02 , &H03 , &H04 , &H05 , &H06 , &H07
Data &H08 , &H09 , &H0A , &H0B , &H0C , &H0D , &H0E , &H0F
Data &H10 , &H11 , &H12 , &H13 , &H14 , &H15 , &H16 , &H17
Data &H18 , &H19 , &H1A , &H1B , &H1C , &H1D , &H1E , &H1F
Data &H20 , &H21 , &H22 , &H23 , &H24 , &H25 , &H26 , &H27
Data &H28 , &H29 , &H2A , &H2B , &H2C , &H2D , &H2E , &H2F
Data &H30 , &H31 , &H32 , &H33 , &H34 , &H35 , &H36 , &H37
Data &H38 , &H39 , &H3A , &H3B , &H3C , &H3D , &H3E , &H3F
Data &H40 , &H41 , &H42 , &H43 , &H44 , &H45 , &H46 , &H47
Data &H48 , &H49 , &H4A , &H4B , &H4C , &H4D , &H4E , &H4F
Data &H50 , &H51 , &H52 , &H53 , &H54 , &H55 , &H56 , &H57
Data &H58 , &H59 , &H5A , &H5B , &H5C , &H5D , &H5E , &H5F
Data &H60 , &H61 , &H62 , &H63 , &H64 , &H65 , &H66 , &H67
Data &H68 , &H69 , &H6A , &H6B , &H6C , &H6D , &H6E , &H6F
Data &H70 , &H71 , &H72 , &H73 , &H74 , &H75 , &H76 , &H77
Data &H78 , &H79 , &H7A , &H7B , &H7C , &H7D , &H7E , &H7F
Data &H80 , &H81 , &H82 , &H83 , &H84 , &H85 , &H86 , &H87
Data &H88 , &H89 , &H8A , &H8B , &H8C , &H8D , &H8E , &H8F
Data &H90 , &H91 , &H92 , &H93 , &H94 , &H95 , &H96 , &H97
Data &H98 , &H99 , &H9A , &H9B , &H9C , &H9D , &H9E , &H9F
Data &HA0 , &HA1 , &HA2 , &HA3 , &HA4 , &HA5 , &HA6 , &HA7
Data &HA8 , &HA9 , &HAA , &HAB , &HAC , &HAD , &HAE , &HAF
Data &HB0 , &HB1 , &HB2 , &HB3 , &HB4 , &HB5 , &HB6 , &HB7
Data &HB8 , &HB9 , &HBA , &HBB , &HBC , &HBD , &HBE , &HBF
Data &HC0 , &HC1 , &HC2 , &HC3 , &HC4 , &HC5 , &HC6 , &HC7
Data &HC8 , &HC9 , &HCA , &HCB , &HCC , &HCD , &HCE , &HCF
Data &HD0 , &HD1 , &HD2 , &HD3 , &HD4 , &HD5 , &HD6 , &HD7
Data &HD8 , &HD9 , &HDA , &HDB , &HDC , &HDD , &HDE , &HDF
Data &HE0 , &HE1 , &HE2 , &HE3 , &HE4 , &HE5 , &HE6 , &HE7
Data &HE8 , &HE9 , &HEA , &HEB , &HEC , &HED , &HEE , &HEF
Data &HF0 , &HF1 , &HF2 , &HF3 , &HF4 , &HF5 , &HF6 , &HF7
Data &HF8 , &HF9 , &HFA , &HFB , &HFC , &HFD , &HFE , &HFF


--


Last edited by Luciano on Mon Mar 27, 2006 1:14 pm; edited 2 times in total
Back to top
View user's profile
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 1, 2, 3, 4, 5, 6  Next
Page 1 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