10
\$\begingroup\$

Is it true that the ATtiny AVRs have no hardware support for multiplication? It seems to work fine as I do multiplication in my code. I've also included math.h and have a couple of sin() and cos() calculations. Am I running into some huge 800-cycle penalty for these calculations, does anyone know?

\$\endgroup\$
1
  • \$\begingroup\$ use lookup tables for trig, and linear interpolation if you want better resolution (with tolerable error) \$\endgroup\$
    – vicatcu
    Oct 29, 2013 at 14:56

1 Answer 1

14
\$\begingroup\$

The ATtiny does not have a hardware multiplier, but software multiplication is not quite as expensive as you imply. See the AVR200 application note and associated code for some optimized multiplication and division routines.

Sine and cosine calculations can be accelerated using lookup tables, effectively trading memory space for processor cycles. However, as @DaveTweed correctly pointed out, algorithmically approximating sine and cosine in software will push the cycle count up nearer the range you fear.

\$\endgroup\$
2
  • 6
    \$\begingroup\$ Polynomial approximation for sin() and cos() typically involve several (3-5) multiplications, plus multiprecision adds/subtracts, range folding, etc., so 800 clocks per function call is not unrealistic. \$\endgroup\$
    – Dave Tweed
    Oct 29, 2013 at 14:31
  • \$\begingroup\$ @DaveTweed: Thank you, good point. Edited to clarify. \$\endgroup\$ Oct 29, 2013 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.