Author Topic: Trying to decipher some AVR assembly code  (Read 3993 times)

0 Members and 1 Guest are viewing this topic.

Offline hazzer123Topic starter

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
Trying to decipher some AVR assembly code
« on: March 31, 2008, 02:53:57 PM »
I am trying to make a signal generator.

I have found an DDS algorithm which i think might be good to use. Its just that it is currently writen in AVR assembly, and im a PIC guy.

I have tried to learn a bit of the avr lingo, but there are still bits im unsure of.  (I have put what i don't understand after each line)

Here it is (source - http://www.scienceprog.com/avr-dds-signal-generator-v20/)

Code: [Select]
asm volatile(                 "eor r18, r18 ;r18<-0"
"eor r19, r19 ;r19<-0"
"1:" ?I guess this is a jump-to label?
"add r18, %0 ;1 cycle" ?What is the %0?
"adc r19, %1 ;1 cycle"       ?ditto?
"adc %A3, %2 ;1 cycle"     ?What is the %A3?
"lpm ;3 cycles"  ?WUH?
"out %4, __tmp_reg__ ;1 cycle" ?HMMMM?
"sbis %5, 2 ;1 cycle if no skip"  ?not a clue?
"rjmp 1b ;2 cycles. Total 10 cycles" ?...?
:
:"r" (ad0),"r" (ad1),"r" (ad2),"e" (signal),"I" (_SFR_IO_ADDR(PORTA)), "I" (_SFR_IO_ADDR(SPCR)) ?...?
:"r18", "r19"  ?...?
);

Would any of you kind folk like to give me help in understanding this foreign language?

Thankyou

Harry
« Last Edit: March 31, 2008, 03:00:38 PM by hazzer123 »
Imperial College Robotics Society
www.icrobotics.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Trying to decipher some AVR assembly code
« Reply #1 on: April 06, 2008, 11:24:56 AM »
What kind of signal are you trying to generate?

Might be easier to just write your own code.

Offline hazzer123Topic starter

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
Re: Trying to decipher some AVR assembly code
« Reply #2 on: April 07, 2008, 02:50:20 AM »
I am trying to create a signal generator that will output sinewaves, squarewaves (with varying duty cycle), triangle waves and sawtooth waves.

The most efficient way of doing this (it seems) is using the DDS algorithm described here - http://en.wikipedia.org/wiki/Direct_Digital_Synthesis.

In order to create higher frequencies, the algorithm must be as time efficient as possible. And the guys at scienceprog managed to make it 10 cpu cycles long. I can't see how they made it so short, so i would really like to understand that one.. :)

I have made some progress in understanding it. The %0, %1 etc are variables that were passed in from the C-code to the assembly.

The line "add r18, %0" is the same as "add r18, ad0". This is because the first variable in the list at the bottom of the assembly is ad0.

What i still don't understand is the %A3 which is in the 6th line.

Can you offer any help with that?
Imperial College Robotics Society
www.icrobotics.co.uk

 


Get Your Ad Here

data_list