looking through the datasheets in devices section of this site i found that many avr microcontrollers have integrated hardware multiplication in them.
from what i've known it is implemented in Cypress's PSoCs and Microchip's dsPICs using a MAC unit and enables faster number multiplication (which is nice for DSP).
now, in the datasheets for atmega8 and atmega8515 i haven't found anything on it.
which instructions and registers facilitate hardware multiplication on AVR?
thanx
hardware multiplication
now, in the datasheets for atmega8 and atmega8515 i haven't found anything on it.
First page:
– On-chip 2-cycle Multiplier
Further searches for "multiply" and "multiplier" uncover the relevant bits, like the MUL instruction.
Perhaps your datasheets are defective.
Lee
nonono, you don't understand (or we haven't understood each other :)
PSoC has hardware multiplication devised over a special piece of hardware called the MAC (later i found that dsPIC also has it). it is accessed by storing values into special registers called MUL_X and MUL_Y, and then reading 16bit result from two other specialized registers (MUL_DH and MUL_DL), so everything is done automatically.
here is a better explanation on the subject:
http://www.easypsoc.com/book/cha...
i know about ordinary MUL instruction, but wanted to know if AVRs have something like this in them.
thx anyway
ps "Perhaps your datasheets are defective...." is this sarcasm, passive aggression or honest remark :D
The AVR multiplier is not a MAC! It just multiplies two 8-bit values with a 16-bit result. If you look in the instruction set document, it will tell you where the results are found and how to input the two starting values. A 16-bit add (the upper one with carry) will take a few more instructions.
The AVR processors can certainly be used for DSP, but the maximum throughput in this mode is a lot lower than a true DSP. The AVRs are not targeted at DSP applications but work just fine when the sample rate is not too high.
[edit]No, the data sheet is not faulty! The multiplier in the AVR is treated no differently than any other logic or arithmetic function. Again, check the instruction set document for an example of how to use it.[/edit]
Jim
The DSP types talk about how many kMACs their DSPs can turn. Might be interesting to see if a 20MHz AVR can compete with a low end DSP doing signed 16 bit multiplies (using the 8 bit AVR hw multiply) and a 16 bit add. Anyone have some kMAC numbers for some low end DSPs?
The so-called "hardware multiplier" is, in fact, accessed through the MUL instruction.
AVRs that don't have a "hardware multiplier" would have to implement a "software multiplier" by way of an interative function call in order to obtain equivalent functionality; certainly requiring more than the 2 instruction cycles required by the MUL instruction on those AVRs where the feature exists.
In general, the AVR is not intended to replace the advanced features that you'll only find in a genuine DSP device.
i know it isn't intended for such usage
that is why i was confused when i found that my little mega8 has this "hardware multiplication" in it.
ps "Perhaps your datasheets are defective...." is this sarcasm, passive aggression or honest remark
Sarcasm --yes.
Passive aggression -- hmmm, I've never been accused of being passive before, so probably not.
Honest remark -- At least partly. Each datasheet has a summary of the instructions available. The various forms of MUL for that particular AVR should be listed. The more detailed document often called the "assembler manual" has the details. This includes
which instructions and registers facilitate hardware multiplication on AVR
Why would there be any secret instructions not shown in the datasheet that only posters here would know about? Yes, you alluded to MAC facilities available on some other micros that have DSP-like facilities. But you specifically asked about AVRs as in the quote from your post above.
As mentioned the MUL result is in fact in two specific registers.
Lee
from Atmel appnote AVR201:The component that makes a dedicated digital signal processor (DSP) specially suitable
for signal processing is the Multiply-Accumulate (MAC) unit. This unit is
functionally equivalent to a multiplier directly connected to an Arithmetic Logic Unit
(ALU). The megaAVR microcontrollers are designed to give the AVR family the ability
to effectively perform the same multiply-accumulate operation.
this helps...
That app note seems, at best, misleading.
Yes, the multiplier is a LOT faster than implementing it in software. But, its hardly on par with a dedicated MAC.
Jim
Anyone have some kMAC numbers for some low end DSPs?
Depends on what 'low end' means. The 'lowest cost' (?) Freescale DSP 56F8013 for ~$3@1kunits (with dual 1.2us 12 bit ADC, three phase 96MHz PWM ....) runs at 32 MHz/MIPS. It does single cycle 16x16 MAC, meaning 32000 kMACs. Sorry AVR, no chance.
OK, the ATmega8 costs less than $1 in comparable quantities.
Jörg.
What do you predict for a 16MHz avr? (16 bit signed mult and signed add). 4000 per sec? Of course, it would do twice as many processing 8 bit samples. Is there any DSP application that uses 8 bits??
void main(void) { unsigned int x; unsigned int y; unsigned long test=0; volatile unsigned int result; y=3456; for(x=1000;x<2000;x++) test+=x*y; result = test; }
This compiles to :
\ ??main_0: \ 0000000C E800 LDI R16, 128 \ 0000000E E01D LDI R17, 13 \ 00000010 9F18 MUL R17, R24 \ 00000012 2D10 MOV R17, R0 \ 00000014 9F09 MUL R16, R25 \ 00000016 0D10 ADD R17, R0 \ 00000018 9F08 MUL R16, R24 \ 0000001A 0D11 ADD R17, R1 \ 0000001C 0D40 ADD R20, R0 \ 0000001E 1F51 ADC R21, R17 \ 00000020 9601 ADIW R25:R24, 1 \ 00000022 3D80 CPI R24, 208 \ 00000024 E007 LDI R16, 7 \ 00000026 0790 CPC R25, R16 \ 00000028 F388 BRCS ??main_0
Takes around 20000 cycles for the complete loop with 1000 'MACS'. The 'test+=x*y' takes ~15 cycles. So for a 16MHz AVR this means around 1000 kMACs. Not so bad for the ATmega and quite a lot more than your estimation!
Any DSP application with 8x8? At least not for me at the moment.
Jörg.
[/code]
Yes, the multiplier is a LOT faster than implementing it in software. But, its hardly on par with a dedicated MAC.
i guessed that, but wasn't sure, thought it is better to ask.
Steve, thanks for the instruction set. I will firstly resort to browsing it before asking.
now, i asked that question out of confusion, or to at least listen comparisons on speed of MAC hardware and AVR's hardware MUL, from people who had some experience with both. i didn't ask anyone to spoon-feed me (i believe it is the right phrase, english is not my primary language).
this isn't whining, but i am a beginner, i have some beginner issues with electronics as well as with programming, add to that that i still find many datasheets a bit confusing, and with the only person around me understanding electronics is so old i actually believe he knew tesla in person...and teached him fractions in elementary school... so when faced with the fact that i have to read for 3 hours through (for example) AD appnotes, DSP guide's AD chapter, several sites over google to see schematics people used to connect their sensors to AD channels and other stuff, i hoped to cut the curve by asking someone over here, and not get into discussion on why i didn't read another datasheet with knowing that "On-chip 2-cycle Multiplier" is the thing i need (which i didn't know, and undoubtedly should have known, and i will know from now on), especially when the answer is as simple as "no, that is not it. hardware MUL on AVRs is a poor-man's MAC, now, kiddo, go read through data sheets"
many of you gave me great answers, which really really helped me, this post, and over time on other questions i had, and i thank to those people very much.
worst thing is that i am now rambling and trolling like a manic street preacher (not the band) because i feel i should defend myself, and while that, receiving a bad credo from people with over 1k of posts, for being a whiney who cant stand criticism.
No criticism, at all, at least from me!
We get quite a range of experiences here. And, quite a range of people. Unfortunately, we also get quite a few of "Please tell me, I don't want to bother reading!" Some of us get a bit upset about that, and can sometimes be a bit terse or rude.
You actually asked an intelligent question. Had you known a little more about the technology or where to find the answer, it would have been a pretty easy question. Its easy to see your confusion. Hope you learned a bit and hope you stay with it and turn it all into something useful.
Cheers,
Jim
And another fellow was asking about doing some filtering using an AVR so I became genuinely curious to actually benchmark the capabilities in a filter.
hm, that was my moment of thetricality, which are luckily not happening very often.
whati i said is that with being a newbie some portion of stupid questions always comes as it's toll, and it is not just where do i connect that resistor to get that effect on something, but also a methodology for finding relevant information.
bob, i was actualy cheered by your zealous "those damn new fab fancy DSP borgeois, i would like to see them programming a filter with nothing more than an army-knife and a pair of chicken-fence wires" :)
Does the sentence of "On chip 2 cycle multiplier" means that the AVR proccessor multiply in two cycles or what ?
The opcode manual is here:
http://ww1.microchip.com/downloa...
For MUL is states:
So it is ONE cycle, not two.
Have you looked in the datasheet for a detailed description?
for #20 ok so now microchip start to put errors into the instructions sheet!!!!!!!
A MUL take 2 clk. (perhaps there is a dream of a new chip where it take one cycle).
add:
I think that the data sheet you linked to is the worst version I ever have seen (and there are many bad versions out there)
If you have a Mega328 and want to do a LD. this data sheet say it take 1 clk !!!! and the note say :
LD instruction can load data from program memory since the flash is memory mapped
I guess that all here know that it's not the case.
So my guess is that they have found even lower grade school kids to do the cut and paste work.
it's really sad that the data sheet still is so bad for a chip family that is 20 years old.
Why can't they hire a programmer/engineer to get correct version (something like the GCC handle different AVR's)
Man, so much disinformation in such an important document! The instruction set manual should be a reference...
Well, they have the correct mul timing elsewhere (page 23), 2 cycles on all versions of AVR (that have mul):
but in the same table ST X(+) take 1 clk for a AVR (classic) so it's clear that the one that fill this in don't know anything about AVR's! sad :( just cut paste cut paste and no proofreading.
Obviously AVRs have gooten faster over the years. (like a 5-amp vacuum cleaner that "develops" 2 HP. Is it on an exercise regimen or what?)
6/99 instruction set document:
Same Rev. D 2002
Same Rev. E 2005
Same Rev. I 2010
Same Rev. J 2014 ("blue" Atmel version)
So you with the 1-cycle supposed quote are just giving fake news. Maybe "alternative facts". That seems to be the fashion nowadays. e.g. 1.5 million people in the crowd photo below, stretching all the way to the Washington Monument:
I think that it's only the logic green AVR copies that can do the MUL in 1 clk.
At least Atmelchip got things right here:
https://www.microchip.com/webdoc...
So maybe that is a "better" reference than the actual opcode manual itself?
Does the sentence of "On chip 2 cycle multiplier" means that the AVR proccessor multiply in two cycles or what ?
Going back to the r4esurrection of this old thread, the answer is indeed "or what".
As discussed, many models of AVR8 have a MUL family of instructions. And the simplest unsigned MUL takes two cycles.
But in practice, are you really going to be doing 8x8 => 16 multiply all the time? Actually, probably rarely. A common operation in C might be 16x16 =>16. There are cycles to get the operands into appropriate registers, do the actual multiply, save the partial product, repeat for the second part, combine results, and store.
So more clarification is needed.
??? Now we get aphorisms when doing a quote for the post above?
—
I am living to bring up new earth ,and not to eat and destroy earth.
© 2018 Microchip Technology Inc.
I think that part of the issue may be what the "new OP" is asking about when referring to a "multiply"?
Is it a multiply in the high-level language sense, where various variable values have to be moved into various registers before the physical multiplication takes place, then an answer that has to be moved to some specified variable.
Or, is it multiply in hardware sense, where only the time for the physical multiplication is taken into account.
For the new OP's benefit, the notes above have shown that, yes, the phrase "On chip 2 cycle multiplier" means that it will do a physical multiplication of 2 8-bit values, producing a 16-bit result, in two clock cycles. There is no MAC, which the earlier part of this thread is about.
Jim
It's hard to know when to trust the datasheets any longer. Even if you call to ask them with questions highlighting your doubts, the helper will give you an answer...that they are reading from a datasheet.
They need to include a marking certifying a datasheet has been carefully checked for errors. Every datasheet will eventually get a copy of the mark; then we'll be able to rest in a trance, knowing that all is well.
I think that it's only the logic green AVR copies that can do the MUL in 1 clk.
Correct. Also, they have improved ret/reti form 4 cycles to 2 cycles and rjmp/rcall, adiw/sbiw all take 1 cycle. So, they are definitely faster than real AVRs. But this breaks the timing of some avr-libc delay functions.
this breaks the timing of some avr-libc delay functions.
Do they have a patch for that?
Or alternative library?
Not that I'm aware of. But it's been a while since I last played with these AVR clones.
logic green AVR
what??? Green datasheet? No, logic green means some company named Logic Green, making a clone
No, logic green means some company named Logic Green, making a clone
But you just said in another thread that iphones make your life easier/better.
"Soylent Green is people!"
theusch wrote:
Does the sentence of "On chip 2 cycle multiplier" means that the AVR proccessor multiply in two cycles or what ?
Going back to the r4esurrection of this old thread, the answer is indeed "or what".
As discussed, many models of AVR8 have a MUL family of instructions. And the simplest unsigned MUL takes two cycles.
But in practice, are you really going to be doing 8x8 => 16 multiply all the time? Actually, probably rarely. A common operation in C might be 16x16 =>16. There are cycles to get the operands into appropriate registers, do the actual multiply, save the partial product, repeat for the second part, combine results, and store.
Does you mean that it takes the two cycles for multiplication and another things ??
And what happen if the multiplication become 8*8=>8 ,does it take 1 cycles ?
Does you mean that it takes the two cycles for multiplication and another things ??And what happen if the multiplication become 8*8=>8 ,does it take 1 cycles ?
Yes, there are several operations that take more than one cycle. Near the end of each MCU datasheet, you will find a list of all instructions supported by that particular model and the timings.
AVRs don't have an 8*8=>8 instruction, if you just need 8 bits, you still have to do 8*8=>16 and discard the data you don't need.
Why "On-chip 2-cycle Multiplier "is mentioned as a feature in atmeg32 micro-controller datasheet?
Does it is considered as a progress?
Well, before HW multiplication, SW 8*8 multiplication was a sequence of shifts (7 shifts) and additions (7 16 bits additions).... needed 7 * many + x cycles ... at least...
Why "On-chip 2-cycle Multiplier "is mentioned as a feature in atmeg32 micro-controller datasheet?
Same reason that "Advanced RISC Architecture", and "1024Bytes EEPROM", and "Master/Slave SPI Serial Interface", and all the other features are mentioned!
is mentioned as a feature in atmeg32
EDIT: just downloaded mega32 datasheet (about 2 seconds!) and the errata list shows that the first issue (A) was 03/2002 which makes it 16 years old.
Back then a 2 cycle multiply was quite a sales point!
Indeed.
And the UART is mentioned as a feature - and that was a well-established standard feature even back then!
Can UART multiply (then, it would have some vague logical link with the topic)?
Can UART multiply
Well, over the years -- the Mega16/32 family had one USART; the more-modern Mega164/324 has two. So indeed the USART multiplied; the current population is at least double what it was back then.
[now THAT shows how it is pertinent to the topic...]
Well, that makes a new generation of UARTs every 15 years.
Even pandas, when shown videos and given viagra -maybe FTDI can use it to sell more UART USB adapters- , seem to multiply faster, however.
Well, that makes a new generation of UARTs every 15 years. Even pandas, when shown videos and given viagra, seem to multiply faster, however.
Ok I think this topic is done, can we all just move along now..... nothing to see here.....
The question in #39 was why a particular feature (the multiplier) gets a specific mention in the datasheet.
As that's not really anything to do with the multiplier itself, perhaps this should be split-off as a separate discussion ?
Well, splitting a topic will make reader task of finding something in logical link with their issue even harder....
Readers should really be punished for buying avrs...
Could y'all cut the bullshit if you have nothing useful (or intelligent) to say?
dbrion0606 said :
Well, before HW multiplication, SW 8*8 multiplication was a sequence of shifts (7 shifts) and additions (7 16 bits additions).... needed 7 * many + x cycles ... at least...
I am so sorry for asking so many questions on same subject ,but anyone knows what is the abbreviation of HW and SW that dbrion0606 has mentioned ? and thanks guys...
anyone knows what is the abbreviation of HW and SW
Hard Ware and Soft Ware
Ohhh, i thought that they are types of multiplier.
HW = HARDWARE
SW = SOFTWARE
Jim
Yes, they are types of multiplier. A hardware multiplier implements the multiplication in hardware -- there's actual gates on the chip to do the thing. A software multiplier uses other operations to implement multiplication, and is much slower.
The world is not that simple.
No problems about the SW version, it makes a multiplication as you would do on paper (just in binary).
There are two main ways to look at a HW multiplier, either does the CPU just have multiply instructions, or does really need to have dedicated logic for the multiplication.
The AVR has the last, but the first chips with MUL instructions did it as the SW but whit a sequencer (like 8086 68000 etc.).
And even a cortex M0 can be implemented without dedicated hardware (but all I know of do it in 1 clk)
A hardware multiplier implements the multiplication in hardware
Just like a Hardware UART implements its functionality in hardware, but a Software UART is all code that you write.
Or a Hardware Floating-Point Unit (FPU) performs floating-point calculations in dedicated hardware - as opposed to just using software libraries.
etc, etc, ...
Also, the HW multiplier can either be part of the CPU, in which case it appears to the programmer as one or more assembly instructions, or it can be a separate peripheral, often able to execute it's own separate instruction stream.
For example, some chips from the Texas Instruments MSP430 family have a multiplier peripheral.
The AVR clone LGT8F328P from Logic Green has both a CPU multiplier similar to the ATMegas, and a more powerful multiplier/divider peripheral.
So there is lots of variety out there.