trigonometric functions

Go To Last Post
121 posts / 0 new

Pages

Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i want to ask if somebody knows the trigonometric functions sin cos tan for avr assembly AT32MEGA

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In assembly, you will have to implement your own. That is one of the many benefits of using a higher level language.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk said:

In assembly, you will have to implement your own.

Unless you "borrow" them from the AVR-libc floating point code:

/* Copyright (c) 2002  Michael Stumpf  <mistumpf@de.pepperl-fuchs.com>
   Copyright (c) 2006  Dmitry Xmelkov
   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are met:

   * Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in
     the documentation and/or other materials provided with the
     distribution.
   * Neither the name of the copyright holders nor the names of
     contributors may be used to endorse or promote products derived
     from this software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   POSSIBILITY OF SUCH DAMAGE. */

/* $Id: tan.S 2473 2015-04-09 08:10:22Z pitchumani $ */

#include "fp32def.h"
#include "asmdef.h"

/* float tan (float A);
     The tan() function returns the tangent of A, where A is given
     in radians.
 */

/* Calculation:
     0 <= x <= Pi/4	 --> tan(x)		fmod
     Pi/4 < x < Pi/2	 --> 1/tan(Pi/2-x)	fmod, Pi/2-x, 1/x
     Pi/2 <= x <= 3*Pi/4 --> -1/tan(x-Pi/2)	fmod, 1/x, -x
     3*Pi/4 < x < Pi	 --> -tan(Pi-x)		fmod, Pi/2-x, -x
 */
#define	HI40_PIO4	0x3F490FDA	/* (flt40_t) Pi/4	*/
#define	LO40_PIO4	0xA2		/* --"--		*/
#define	HI40_PIO2	0x3FC90FDA	/* (flt40_t) Pi/2	*/
#define	LO40_PIO2	0xA2		/* --"--		*/

#define	rsign	YH

ENTRY tan
  ; save sign
	push	rsign
	mov	rsign, rA3
  ; fmod by Pi/2
	XCALL	_U(__fp_rempio2)
  ; save perion number
	lsr	ZL
	ror	rsign
  ; is A <= Pi/4 ?
#if  LO40_PIO4 == 0xFF		/* HI40_PIO4: increment is not needed	*/
# error
#endif
	ldi	rB0,  lo8(HI40_PIO4)
	ldi	rB1,  hi8(HI40_PIO4)
	ldi	rB2, hlo8(HI40_PIO4)
	ldi	rB3, hhi8(HI40_PIO4)
	cpi	rAE,  LO40_PIO4 + 1
	cpc	rA0, rB0
	cpc	rA1, rB1
	cpc	rA2, rB2
	cpc	rA3, rB3
	ror	rsign		; save comparison result
	brmi	1f		; N == C flag after comparison
  ; for A > Pi/4:  tan(A) == 1/tan(Pi/2 - A)
#if (HI40_PIO4 ^ HI40_PIO2) & 0xFF00FFFF	/* 'ldi' optimization	*/
# error
#endif
	ldi	rBE, LO40_PIO2
	ldi	rB2, hlo8(HI40_PIO2)
	ori	rA3, 0x80
	XCALL	_U(__addsf3x)
	XCALL	_U(__fp_round)
  ; calculate tan(A) for  0 <= A <= Pi/4
1:	ldi	ZL, lo8(.L_table)
	ldi	ZH, hi8(.L_table)
	XCALL	_U(__fp_powsodd)
  ; correct result
	lsl	rsign
	brvs	2f
	XCALL	_U(inverse)
2:	lsl	rsign
	brvc	3f
	subi	rA3, 0x80
3:	pop	rsign
	ret
ENDFUNC
	
	PGM_SECTION
.L_table:
	.byte	6
	.byte	     0x64,0xec,0x1b,0x3c	;  0.0095168091
	.byte	0x04,0xbc,0x16,0x3e,0x3b	;  0.0029005250
	.byte	0xe5,0xb9,0x3c,0xc9,0x3c	;  0.0245650893
	.byte	0x37,0xc2,0x9e,0x5a,0x3d	;  0.0533740603
	.byte	0x66,0x04,0x98,0x08,0x3e	;  0.1333923995
	.byte	0xea,0x69,0xaa,0xaa,0x3e	;  0.3333314036
	.byte	0x00,0x00,0x00,0x80,0x3f	;  1.0000000000
	.end

 

Greg Muth

Portland, OR, US

Xplained/Pro/Mini Boards mostly

 

Make Xmega Great Again!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is sooo much easier to use a high level language.

You can focus on the project and not get tied up with the minutia.

 

In any event, depending upon the resolution you need, you can certainly use a series to calculate the sin of an angle.

You could also pre-load a look up table, depending again upon the resolution you need, and the amount of memory you have available.

 

If you had a LUT for Sin from 0 - 90 degrees, then you obviously can easily calculate the sin of an angle in the other three quadrants.

If you have a sin LUT then you don't need a cos look up table,  just use a trig identity to calc the cos from the sin.

If you use a "double angle formula" then you can calc the cos without even using squares and square roots.

 

If you have the sin LUT, and hence can easily calc the cos, then you can calc the tan with a simple division.

Of course that means you need to write an asm lang floating point division routine, and debug it.

 

If this is a homework assignment, then dig in, cause you have a lot of work ahead of you.

 

If this is for anything other than a homework assignment, you ought to carefully re-think your choice of language with which to undertake your project.

 

JC

 

Edit:  If you go with the look up table approach, then Google Trigonometric Identities for the various equations relating the trig functions.

Last Edited: Sat. Jan 20, 2018 - 05:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

giannismara wrote:
i want to ask if somebody knows the trigonometric functions sin cos tan for avr assembly AT32MEGA

What have you done so far?

 

Do you plan to use a standard encoding such as IEE754, or a custom encoding?

 

Do you have the very basic primitives done, for display and translating to/from integer representation?

 

If so, have you an implementation for the arithmetic primitives addition subtraction multiplication division?  And the adjunct functionality, for normalization and indication of NaN and other exception conditions?

 

Once you have all of the above, then the applicable series to calculate your functions are well known.

 

Why don't you just lift the known-good code generated by a GCC program?

 

Did you do the basic Google search, and have examined and rejected prior work?  What were the reasons for rejection?

 

https://people.ece.cornell.edu/l...

https://www.avrfreaks.net/forum/a...

https://www.avrfreaks.net/forum/a...

https://www.avrfreaks.net/forum/a...

...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bleh, who said floating point?  Here is some good old Cordic:

https://www.youtube.com/watch?v=Ze4UnE8R4FM

 

Along with some fast assembly code:

 

https://www.dropbox.com/s/a8iaiopcvsz6tbn/CORDIC_Demo.asm

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Before you move forward, determine the accuracy you need, and (related) both your input and your output resolutions.  No reason to calculate out to 20 bits if your input or output is limited to 6 bits.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Now I'm thinking that there should be a angular measurement unit call "brads", with 1024 in a complete circle.  (similar to "grads", which have 400 in a circle, so a right angle is 100.  Which my calculator used to support, but I don't think I've ever seen actually used.)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
"grads" ...  Which my calculator used to support, but I don't think I've ever seen actually used.

I remember my calculator had that option. Never knew what it meant!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can I be a heretic and ask why you think you even need float in an 8 bit micro? Almost anything you want to achieve can be done in integers or using LUTs or some less computationally intensive method. That's what you REALLY should be learning in an 8 bit micro programmed in Asm. 

 

Oh and if the project IS Asm do you really intend to write 32K binary?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you for  your help..i really appriciated..But i dont know so much for microcontroller and i i have to do exercise just the code or the program for the trigonometric functions..in the class we use avr studio 4 and AT32MEGA..if somebody write the code i appeciated too..thank you!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you for  your help..i really appriciated..But i dont know so much for microcontroller and i i have to do exercise just the code or the program for the trigonometric functions..in the class we use avr studio 4 and AT32MEGA..if somebody write the code i appeciated too..thank you!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

giannismara wrote:
if somebody write the code i appeciated too

No - nobody is going to do your homework for you!

 

The assignment has been give to you as an exercise for you to do.

 

Your teacher wouldn't have given you this exercise if it was beyond what has been taught in the class.

Therefore, if you really can't do it, it is of the utmost importance that you talk to your teacher - otherwise you will just fall further behind.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

unfortunately i haven't only this work...but this code will help me very very much..i don't tell somebody do the work for me..but if i have the program i could start more easy

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As has already been suggested just list the Asm routines from an open source C compiler.

 

However can you confirm you already know what IEEE754 is already? It's fundamental to using float variables on micros. I think that without exception any language offering SIN/COS on an AVR is using IEEE754 under the hood so it's vital you understand the encoding and handling. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It hasn't been stated that the homework requires Floating point - maybe fixed-point or even integer would be sufficient ... ?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It would be interesting f there were a cryptic way to calculate it--could be super fast and small. 

 

Something like:  Given 16 bit angle, take the low nibble & xor it into bits [11:8], rotate all 16 bits right 2 places, clear bit 4, add 27, swap bits 12 & 6, repeat all this twice,  gives the cos of the angle.  

 

Since every angle maps to an answer value, it could be formulated as some sort of crazy logic minimization problem...if  lucky it could be very compact (but unlikely).

 

Who knows what this mapping (input to output) would give?...maybe I actually just described the llama function, with the first documented fast approximation.

 

I saw some insane method to calculate something (cubic root?) many years ago...it was super compact along these lines. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

As a  "homework assignment", the OP still hasn't given enough details to provide any useful advice (like the type of the angle provided.)

I wouldn't normally expect an assembly language class to generating floating point algorithms from scratch, and there are at least three more reasonable possibilities:

  1. demonstrate that you know how to call the avr-libc trig functions from assembler.  (A useful skill.)
  2. lookup table
  3. smaller lookup table plus interpolation.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wouldn't do it myself, but you can call library functions from (gnu) assembler.

 

#include <avr/io.h>

.data
        
format:
        .string	"sin(pi/4) = %f\n"
        
.text

.global	 main
main:	
        
        call 	usart_init

        sei

        // load pi/4 = 0x3f490fdb in r22:r25
        ldi	r25, 0x3f
        ldi	r24, 0x49
        ldi	r23, 0x0f
        ldi	r22, 0xdb
        // Calculate sin(pi/4)
        call	sin
        // Push return value from sin
        push	r25
        push	r24
        push	r23
        push	r22
        // push address to format string
        ldi	r16, hi8(format)
        push	r16
        ldi	r16, lo8(format)
        push	r16
        // rint the result
        call	printf

        // Balance the stack
.rept	6
        pop	r0
.endr
        
        // Endless loop
main_loop:
        rjmp 	main_loop

(the output is "sin(pi/4) = 0.707107")

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

If the OP is really trying to steal our cycles for completing his assignment, then we should provide some form of "alternative support" in clearly bringing the principles of the real world to his attention: IMHO, this thread should have been locked immediately after post #13, with all code examples being removed. 

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I see two advantages on points 2 and 3 (treated in this order; linear interpolation adds complexity of code/data structures):

 

a) it can be reused for many complicated -but continuous, being differneciable helps, too -  functions, on a given interval (PC (has python, fortran, c, excel ...) generates asm/C look-up tables.

 

b) if one forgets assembly, maybe there are MCU with a less elaborated library than avr-libc. (if one has forgotten assembly, gcc can generate assembly edited or -incl- use already written assembly ....)

 

Perhaps OP should elaborate on what (s)he wants and already did (there is nothing more annoying than not finding a blocking detail -if such thing exists in OP s case-)

 

 

Last Edited: Mon. Jan 22, 2018 - 10:33 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't agree. We can show the OP the methods that exist without giving him the actual code.

 

Edit: better contribute with something-> Chebyshev/Taylor approximation

http://people.sc.fsu.edu/~jburka...

https://www.quora.com/Mathematic...

http://mooooo.ooo/chebyshev-sine...

 

Last Edited: Mon. Jan 22, 2018 - 10:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I always like to provide solutions that a teacher will immediately realize are ringers submitted by other people, but which the student won't spot.

 

For instance, asked to populate an array with the numbers 1-100, a loop with

 

</p>
<p>a[i] = (scanf, "%d", i);</p>
<p>

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

can you help me for t program please? i want function for sin cos tan at avr assembler atmega32a at 8 bit

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Many people gave you links / ,ideas to program them (and I am thankfull to them, as they gave me ideas, and to you, for asking question)

* asm functions still exist with avr - libc for trigiometry and are very satisfying (telling your teacher you spent a lot of time finding already written renewn functions migh show him/her you have efficient, flexible methods) .

 

* using table look up or taylor expansion  will teach you maths, according to el tangas links (and this knowledge can be ported to other MCUs).

 

* if you have an idea with C, avr-gcc can convert c into asm (the "-save-temps " option works with x86-gcc, arm_any_gcc, and many others-gcc)

 

If one goes further, that might give you an unfair advantage w/r your  fellow students (some people can be very fierce with that idea).

OTOH, if you show you have ideas and a detail worries you/blocks you and if it takes little time to fix it (one can wait for days before seing a blocking typo, say), one can help you to fix/improve  almost already done work, for a given blocking  feature -but not a full project- .

Last Edited: Tue. Jan 23, 2018 - 06:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David (aka frog_jr)

Last Edited: Tue. Jan 23, 2018 - 06:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

giannismara wrote:
can you help me for t program please?

So what "help", exactly, do you require?

 

Where are you stuck in applying the help that's already been given?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i want the program for the sin cos tan at 32mega32a to use on avr assembler..or the sin only..the most easy program 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

can you write  here the program??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But in #14 you said you were not asking for people to do your homework for you

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

its not the ONLY this the exercise...if you can i appreciate you..its just the 10% for my exercise but the program help me very much...just this...can you help me???

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, it's your homework - so it is clearly expected that you should do it yourself.

 

Again, if you have a problem with that, you need to take it up with your teacher

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

So how did you spend the last 3 days since you posted your original question? How was that important party you had to attend instead of sitting down at your desk and simply READ, LEARN, APPLY stuff that has been available for dozens (particular applications) and hundreds of years (the theory)? Did your girl friend appreciate all the time you spent with her instead of doing what your parents will expect? I think even the laziest student, at this point of the discussion, should have grasped the idea that (s)he won't get his/her homework done here.

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

http://www.nongnu.org/avr-libc/u...

lists each and every mathematic function (I just google searched some keywords which were given in this very discussion!)

sin is part of them (cos, too, tan, too) . There is a "home" link on this very page, and a download link on the very home.

Then with eyes, optical nerve and brain, you will notice you have been hited towards  the most renewn (useful for Arduini, IIRC, and many others) ASM functions.

 

I bet that, if you extract, make work these functions, your teacher , either will feel very cruel (with you and people trying to help you)  telling you to make such a useful thing or will feel proud of you, -especially if you quote the writer of this library-)...

 

Edited : you remind me of a Malagsy proverb "mangetaheta ao ambon'ny lakana" -thirsty upon a river boat- : you were given a lot of useful links and ideas you just have to select,  to pickup and adapt.

 

Last Edited: Tue. Jan 23, 2018 - 08:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Several of us said "lift what you need from a C compiler". Which bit of that are you having trouble understanding?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"lift" - that sounds a bit like work !

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If we simply give out the answer, it would be a sin

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Before we go on a tangent, another interesting link: http://dmuw.zum.de/wiki/Calculat...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cos it ain't the right thing to do!

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's rad!

David (aka frog_jr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

to a degree ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

frog_jr wrote:

That's rad!

awneil wrote:

to a degree ...

 

Naturally, ask any Babylonian

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Wed. Jan 24, 2018 - 01:46 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OP didn't mention if he has to log the data as well.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sometimes you want your trig functions in ASM for absolute speed.

 

Make the circle have 256 "degrees" in it.

 

Pre-load a 256 byte table with the 8 bit result for for each angle.

 

Make sure that table is aligned to a 256 byte boundary

 

sin: 

   LDI ZH, hi8(table)

   MOV  ZL, r24

   LD     r24, Z

   RET

 

Of course if your doing everything in ASM there is no need to mess around moving things into R24 and doing that RET.  Just make a macro that does the LDI and LD part into your registers of choice :)

 

/me sits back and waits.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Pre-load a 256 byte table with the 8 bit result for for each angle.

 

Well, unless OP can compute, scale and type 256 sinuses, that is tedious...

solution is in the PC world (R, python, fortran, c ... and hundreds of others)

binf=0.

bsup=2*pi

step = (bsup -binf) /256.0

i = 0

x = binf

scale=128.0

offset = 127.0

while (x <= bsup) {

  value= (uint16_t) ( offset + scale * sin(x))

  write walue to an include file; manage side effects -commas- or send to the console to cut'n paste......if OP likes manual work

}

 

 

does the job (if I want  LU tables) for me, with some adaptations (ex: one does not need to explore the full circle for trigonometric functions)

 

Edited : tried to remove an obscene word

Last Edited: Wed. Jan 24, 2018 - 11:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Due to symmetry, you don't need the full circle, just 1/4 circle (0 - π/2 radians).

 

edit: Of course you need to do some preprocessing of the angle and negate the result if needed, in this case. But you get a lookup table 4 times smaller, or 4 times better resolution with the same size LUT.

Last Edited: Wed. Jan 24, 2018 - 12:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Even if you use a LUT there's still the question of the data type of those samples. Are they going to be IEEE754 float anyway? Or if some kind of integer format then with what scaling? If you don't scale up most of your entries (as integer) would simply be 0 ;-)

 

This kind of comes back to why you wanted sin/cos/tan in the first place? Is it about drawing circles and other "wave derived" shapes on a screen? Or playing audio (or other frequency range) "tones"? Or some other use?

 

BTW as to "lifting" code from a C compiler. If I write:

#include <avr/io.h>
#include <math.h>

int main(void) {
    PORTD = sin(PINB);
}

it generates:

0000008a <main>:
#include <avr/io.h>
#include <math.h>

int main(void) {
    PORTD = sin(PINB);
  8a:   66 b3           in      r22, 0x16       ; 22
  8c:   70 e0           ldi     r23, 0x00       ; 0
  8e:   80 e0           ldi     r24, 0x00       ; 0
  90:   90 e0           ldi     r25, 0x00       ; 0
  92:   0e 94 82 00     call    0x104   ; 0x104 <__floatunsisf>
  96:   0e 94 e8 00     call    0x1d0   ; 0x1d0 <sin>
  9a:   0e 94 53 00     call    0xa6    ; 0xa6 <__fixunssfsi>
  9e:   62 bb           out     0x12, r22       ; 18
}
  a0:   80 e0           ldi     r24, 0x00       ; 0
  a2:   90 e0           ldi     r25, 0x00       ; 0
  a4:   08 95           ret

000000a6 <__fixunssfsi>:
  a6:   0e 94 c7 00     call    0x18e   ; 0x18e <__fp_splitA>
  aa:   88 f0           brcs    .+34            ; 0xce <__fixunssfsi+0x28>
  ac:   9f 57           subi    r25, 0x7F       ; 127
  ae:   98 f0           brcs    .+38            ; 0xd6 <__fixunssfsi+0x30>
  b0:   b9 2f           mov     r27, r25
  b2:   99 27           eor     r25, r25
  b4:   b7 51           subi    r27, 0x17       ; 23
  b6:   b0 f0           brcs    .+44            ; 0xe4 <__fixunssfsi+0x3e>
  b8:   e1 f0           breq    .+56            ; 0xf2 <__fixunssfsi+0x4c>
  ba:   66 0f           add     r22, r22
  bc:   77 1f           adc     r23, r23
  be:   88 1f           adc     r24, r24
  c0:   99 1f           adc     r25, r25
  c2:   1a f0           brmi    .+6             ; 0xca <__fixunssfsi+0x24>
  c4:   ba 95           dec     r27
  c6:   c9 f7           brne    .-14            ; 0xba <__fixunssfsi+0x14>
  c8:   14 c0           rjmp    .+40            ; 0xf2 <__fixunssfsi+0x4c>
  ca:   b1 30           cpi     r27, 0x01       ; 1
  cc:   91 f0           breq    .+36            ; 0xf2 <__fixunssfsi+0x4c>
  ce:   0e 94 e1 00     call    0x1c2   ; 0x1c2 <__fp_zero>
  d2:   b1 e0           ldi     r27, 0x01       ; 1
  d4:   08 95           ret
  d6:   0c 94 e1 00     jmp     0x1c2   ; 0x1c2 <__fp_zero>
  da:   67 2f           mov     r22, r23
  dc:   78 2f           mov     r23, r24
  de:   88 27           eor     r24, r24
  e0:   b8 5f           subi    r27, 0xF8       ; 248
  e2:   39 f0           breq    .+14            ; 0xf2 <__fixunssfsi+0x4c>
  e4:   b9 3f           cpi     r27, 0xF9       ; 249
  e6:   cc f3           brlt    .-14            ; 0xda <__fixunssfsi+0x34>
  e8:   86 95           lsr     r24
  ea:   77 95           ror     r23
  ec:   67 95           ror     r22
  ee:   b3 95           inc     r27
  f0:   d9 f7           brne    .-10            ; 0xe8 <__fixunssfsi+0x42>
  f2:   3e f4           brtc    .+14            ; 0x102 <__fixunssfsi+0x5c>
  f4:   90 95           com     r25
  f6:   80 95           com     r24
  f8:   70 95           com     r23
  fa:   61 95           neg     r22
  fc:   7f 4f           sbci    r23, 0xFF       ; 255
  fe:   8f 4f           sbci    r24, 0xFF       ; 255
 100:   9f 4f           sbci    r25, 0xFF       ; 255
 102:   08 95           ret

00000104 <__floatunsisf>:
 104:   e8 94           clt
 106:   09 c0           rjmp    .+18            ; 0x11a <__floatsisf+0x12>

00000108 <__floatsisf>:
 108:   97 fb           bst     r25, 7
 10a:   3e f4           brtc    .+14            ; 0x11a <__floatsisf+0x12>
 10c:   90 95           com     r25
 10e:   80 95           com     r24
 110:   70 95           com     r23
 112:   61 95           neg     r22
 114:   7f 4f           sbci    r23, 0xFF       ; 255
 116:   8f 4f           sbci    r24, 0xFF       ; 255
 118:   9f 4f           sbci    r25, 0xFF       ; 255
 11a:   99 23           and     r25, r25
 11c:   a9 f0           breq    .+42            ; 0x148 <__floatsisf+0x40>
 11e:   f9 2f           mov     r31, r25
 120:   96 e9           ldi     r25, 0x96       ; 150
 122:   bb 27           eor     r27, r27
 124:   93 95           inc     r25
 126:   f6 95           lsr     r31
 128:   87 95           ror     r24
 12a:   77 95           ror     r23
 12c:   67 95           ror     r22
 12e:   b7 95           ror     r27
 130:   f1 11           cpse    r31, r1
 132:   f8 cf           rjmp    .-16            ; 0x124 <__floatsisf+0x1c>
 134:   fa f4           brpl    .+62            ; 0x174 <__floatsisf+0x6c>
 136:   bb 0f           add     r27, r27
 138:   11 f4           brne    .+4             ; 0x13e <__floatsisf+0x36>
 13a:   60 ff           sbrs    r22, 0
 13c:   1b c0           rjmp    .+54            ; 0x174 <__floatsisf+0x6c>
 13e:   6f 5f           subi    r22, 0xFF       ; 255
 140:   7f 4f           sbci    r23, 0xFF       ; 255
 142:   8f 4f           sbci    r24, 0xFF       ; 255
 144:   9f 4f           sbci    r25, 0xFF       ; 255
 146:   16 c0           rjmp    .+44            ; 0x174 <__floatsisf+0x6c>
 148:   88 23           and     r24, r24
 14a:   11 f0           breq    .+4             ; 0x150 <__floatsisf+0x48>
 14c:   96 e9           ldi     r25, 0x96       ; 150
 14e:   11 c0           rjmp    .+34            ; 0x172 <__floatsisf+0x6a>
 150:   77 23           and     r23, r23
 152:   21 f0           breq    .+8             ; 0x15c <__floatsisf+0x54>
 154:   9e e8           ldi     r25, 0x8E       ; 142
 156:   87 2f           mov     r24, r23
 158:   76 2f           mov     r23, r22
 15a:   05 c0           rjmp    .+10            ; 0x166 <__floatsisf+0x5e>
 15c:   66 23           and     r22, r22
 15e:   71 f0           breq    .+28            ; 0x17c <__floatsisf+0x74>
 160:   96 e8           ldi     r25, 0x86       ; 134
 162:   86 2f           mov     r24, r22
 164:   70 e0           ldi     r23, 0x00       ; 0
 166:   60 e0           ldi     r22, 0x00       ; 0
 168:   2a f0           brmi    .+10            ; 0x174 <__floatsisf+0x6c>
 16a:   9a 95           dec     r25
 16c:   66 0f           add     r22, r22
 16e:   77 1f           adc     r23, r23
 170:   88 1f           adc     r24, r24
 172:   da f7           brpl    .-10            ; 0x16a <__floatsisf+0x62>
 174:   88 0f           add     r24, r24
 176:   96 95           lsr     r25
 178:   87 95           ror     r24
 17a:   97 f9           bld     r25, 7
 17c:   08 95           ret

0000017e <__fp_split3>:
 17e:   57 fd           sbrc    r21, 7
 180:   90 58           subi    r25, 0x80       ; 128
 182:   44 0f           add     r20, r20
 184:   55 1f           adc     r21, r21
 186:   59 f0           breq    .+22            ; 0x19e <__fp_splitA+0x10>
 188:   5f 3f           cpi     r21, 0xFF       ; 255
 18a:   71 f0           breq    .+28            ; 0x1a8 <__fp_splitA+0x1a>
 18c:   47 95           ror     r20

0000018e <__fp_splitA>:
 18e:   88 0f           add     r24, r24
 190:   97 fb           bst     r25, 7
 192:   99 1f           adc     r25, r25
 194:   61 f0           breq    .+24            ; 0x1ae <__fp_splitA+0x20>
 196:   9f 3f           cpi     r25, 0xFF       ; 255
 198:   79 f0           breq    .+30            ; 0x1b8 <__fp_splitA+0x2a>
 19a:   87 95           ror     r24
 19c:   08 95           ret
 19e:   12 16           cp      r1, r18
 1a0:   13 06           cpc     r1, r19
 1a2:   14 06           cpc     r1, r20
 1a4:   55 1f           adc     r21, r21
 1a6:   f2 cf           rjmp    .-28            ; 0x18c <__fp_split3+0xe>
 1a8:   46 95           lsr     r20
 1aa:   f1 df           rcall   .-30            ; 0x18e <__fp_splitA>
 1ac:   08 c0           rjmp    .+16            ; 0x1be <__fp_splitA+0x30>
 1ae:   16 16           cp      r1, r22
 1b0:   17 06           cpc     r1, r23
 1b2:   18 06           cpc     r1, r24
 1b4:   99 1f           adc     r25, r25
 1b6:   f1 cf           rjmp    .-30            ; 0x19a <__fp_splitA+0xc>
 1b8:   86 95           lsr     r24
 1ba:   71 05           cpc     r23, r1
 1bc:   61 05           cpc     r22, r1
 1be:   08 94           sec
 1c0:   08 95           ret

000001c2 <__fp_zero>:
 1c2:   e8 94           clt

000001c4 <__fp_szero>:
 1c4:   bb 27           eor     r27, r27
 1c6:   66 27           eor     r22, r22
 1c8:   77 27           eor     r23, r23
 1ca:   cb 01           movw    r24, r22
 1cc:   97 f9           bld     r25, 7
 1ce:   08 95           ret

000001d0 <sin>:
 1d0:   9f 93           push    r25
 1d2:   0e 94 f2 00     call    0x1e4   ; 0x1e4 <__fp_rempio2>
 1d6:   0f 90           pop     r0
 1d8:   07 fc           sbrc    r0, 7
 1da:   ee 5f           subi    r30, 0xFE       ; 254
 1dc:   0c 94 1b 01     jmp     0x236   ; 0x236 <__fp_sinus>
 1e0:   0c 94 a9 01     jmp     0x352   ; 0x352 <__fp_nan>

000001e4 <__fp_rempio2>:
 1e4:   0e 94 c7 00     call    0x18e   ; 0x18e <__fp_splitA>
 1e8:   d8 f3           brcs    .-10            ; 0x1e0 <sin+0x10>
 1ea:   e8 94           clt
 1ec:   e0 e0           ldi     r30, 0x00       ; 0
 1ee:   bb 27           eor     r27, r27
 1f0:   9f 57           subi    r25, 0x7F       ; 127
 1f2:   f0 f0           brcs    .+60            ; 0x230 <__fp_rempio2+0x4c>
 1f4:   2a ed           ldi     r18, 0xDA       ; 218
 1f6:   3f e0           ldi     r19, 0x0F       ; 15
 1f8:   49 ec           ldi     r20, 0xC9       ; 201
 1fa:   06 c0           rjmp    .+12            ; 0x208 <__fp_rempio2+0x24>
 1fc:   ee 0f           add     r30, r30
 1fe:   bb 0f           add     r27, r27
 200:   66 1f           adc     r22, r22
 202:   77 1f           adc     r23, r23
 204:   88 1f           adc     r24, r24
 206:   28 f0           brcs    .+10            ; 0x212 <__fp_rempio2+0x2e>
 208:   b2 3a           cpi     r27, 0xA2       ; 162
 20a:   62 07           cpc     r22, r18
 20c:   73 07           cpc     r23, r19
 20e:   84 07           cpc     r24, r20
 210:   28 f0           brcs    .+10            ; 0x21c <__fp_rempio2+0x38>
 212:   b2 5a           subi    r27, 0xA2       ; 162
 214:   62 0b           sbc     r22, r18
 216:   73 0b           sbc     r23, r19
 218:   84 0b           sbc     r24, r20
 21a:   e3 95           inc     r30
 21c:   9a 95           dec     r25
 21e:   72 f7           brpl    .-36            ; 0x1fc <__fp_rempio2+0x18>
 220:   80 38           cpi     r24, 0x80       ; 128
 222:   30 f4           brcc    .+12            ; 0x230 <__fp_rempio2+0x4c>
 224:   9a 95           dec     r25
 226:   bb 0f           add     r27, r27
 228:   66 1f           adc     r22, r22
 22a:   77 1f           adc     r23, r23
 22c:   88 1f           adc     r24, r24
 22e:   d2 f7           brpl    .-12            ; 0x224 <__fp_rempio2+0x40>
 230:   90 48           sbci    r25, 0x80       ; 128
 232:   0c 94 9d 01     jmp     0x33a   ; 0x33a <__fp_mpack_finite>

00000236 <__fp_sinus>:
 236:   ef 93           push    r30
 238:   e0 ff           sbrs    r30, 0
 23a:   07 c0           rjmp    .+14            ; 0x24a <__fp_sinus+0x14>
 23c:   a2 ea           ldi     r26, 0xA2       ; 162
 23e:   2a ed           ldi     r18, 0xDA       ; 218
 240:   3f e0           ldi     r19, 0x0F       ; 15
 242:   49 ec           ldi     r20, 0xC9       ; 201
 244:   5f eb           ldi     r21, 0xBF       ; 191
 246:   0e 94 40 01     call    0x280   ; 0x280 <__addsf3x>
 24a:   0e 94 ce 01     call    0x39c   ; 0x39c <__fp_round>
 24e:   0f 90           pop     r0
 250:   03 94           inc     r0
 252:   01 fc           sbrc    r0, 1
 254:   90 58           subi    r25, 0x80       ; 128
 256:   e4 e5           ldi     r30, 0x54       ; 84
 258:   f0 e0           ldi     r31, 0x00       ; 0
 25a:   0c 94 ac 01     jmp     0x358   ; 0x358 <__fp_powsodd>
 25e:   0e 94 c0 01     call    0x380   ; 0x380 <__fp_pscA>
 262:   38 f0           brcs    .+14            ; 0x272 <__fp_sinus+0x3c>
 264:   0e 94 c7 01     call    0x38e   ; 0x38e <__fp_pscB>
 268:   20 f0           brcs    .+8             ; 0x272 <__fp_sinus+0x3c>
 26a:   39 f4           brne    .+14            ; 0x27a <__fp_sinus+0x44>
 26c:   9f 3f           cpi     r25, 0xFF       ; 255
 26e:   19 f4           brne    .+6             ; 0x276 <__fp_sinus+0x40>
 270:   26 f4           brtc    .+8             ; 0x27a <__fp_sinus+0x44>
 272:   0c 94 a9 01     jmp     0x352   ; 0x352 <__fp_nan>
 276:   0e f4           brtc    .+2             ; 0x27a <__fp_sinus+0x44>
 278:   e0 95           com     r30
 27a:   e7 fb           bst     r30, 7
 27c:   0c 94 95 01     jmp     0x32a   ; 0x32a <__fp_inf>

00000280 <__addsf3x>:
 280:   e9 2f           mov     r30, r25
 282:   0e 94 bf 00     call    0x17e   ; 0x17e <__fp_split3>
 286:   58 f3           brcs    .-42            ; 0x25e <__fp_sinus+0x28>
 288:   ba 17           cp      r27, r26
 28a:   62 07           cpc     r22, r18
 28c:   73 07           cpc     r23, r19
 28e:   84 07           cpc     r24, r20
 290:   95 07           cpc     r25, r21
 292:   20 f0           brcs    .+8             ; 0x29c <__addsf3x+0x1c>
 294:   79 f4           brne    .+30            ; 0x2b4 <__addsf3x+0x34>
 296:   a6 f5           brtc    .+104           ; 0x300 <__addsf3x+0x80>
 298:   0c 94 e1 00     jmp     0x1c2   ; 0x1c2 <__fp_zero>
 29c:   0e f4           brtc    .+2             ; 0x2a0 <__addsf3x+0x20>
 29e:   e0 95           com     r30
 2a0:   0b 2e           mov     r0, r27
 2a2:   ba 2f           mov     r27, r26
 2a4:   a0 2d           mov     r26, r0
 2a6:   0b 01           movw    r0, r22
 2a8:   b9 01           movw    r22, r18
 2aa:   90 01           movw    r18, r0
 2ac:   0c 01           movw    r0, r24
 2ae:   ca 01           movw    r24, r20
 2b0:   a0 01           movw    r20, r0
 2b2:   11 24           eor     r1, r1
 2b4:   ff 27           eor     r31, r31
 2b6:   59 1b           sub     r21, r25
 2b8:   99 f0           breq    .+38            ; 0x2e0 <__addsf3x+0x60>
 2ba:   59 3f           cpi     r21, 0xF9       ; 249
 2bc:   50 f4           brcc    .+20            ; 0x2d2 <__addsf3x+0x52>
 2be:   50 3e           cpi     r21, 0xE0       ; 224
 2c0:   68 f1           brcs    .+90            ; 0x31c <__addsf3x+0x9c>
 2c2:   1a 16           cp      r1, r26
 2c4:   f0 40           sbci    r31, 0x00       ; 0
 2c6:   a2 2f           mov     r26, r18
 2c8:   23 2f           mov     r18, r19
 2ca:   34 2f           mov     r19, r20
 2cc:   44 27           eor     r20, r20
 2ce:   58 5f           subi    r21, 0xF8       ; 248
 2d0:   f3 cf           rjmp    .-26            ; 0x2b8 <__addsf3x+0x38>
 2d2:   46 95           lsr     r20
 2d4:   37 95           ror     r19
 2d6:   27 95           ror     r18
 2d8:   a7 95           ror     r26
 2da:   f0 40           sbci    r31, 0x00       ; 0
 2dc:   53 95           inc     r21
 2de:   c9 f7           brne    .-14            ; 0x2d2 <__addsf3x+0x52>
 2e0:   7e f4           brtc    .+30            ; 0x300 <__addsf3x+0x80>
 2e2:   1f 16           cp      r1, r31
 2e4:   ba 0b           sbc     r27, r26
 2e6:   62 0b           sbc     r22, r18
 2e8:   73 0b           sbc     r23, r19
 2ea:   84 0b           sbc     r24, r20
 2ec:   ba f0           brmi    .+46            ; 0x31c <__addsf3x+0x9c>
 2ee:   91 50           subi    r25, 0x01       ; 1
 2f0:   a1 f0           breq    .+40            ; 0x31a <__addsf3x+0x9a>
 2f2:   ff 0f           add     r31, r31
 2f4:   bb 1f           adc     r27, r27
 2f6:   66 1f           adc     r22, r22
 2f8:   77 1f           adc     r23, r23
 2fa:   88 1f           adc     r24, r24
 2fc:   c2 f7           brpl    .-16            ; 0x2ee <__addsf3x+0x6e>
 2fe:   0e c0           rjmp    .+28            ; 0x31c <__addsf3x+0x9c>
 300:   ba 0f           add     r27, r26
 302:   62 1f           adc     r22, r18
 304:   73 1f           adc     r23, r19
 306:   84 1f           adc     r24, r20
 308:   48 f4           brcc    .+18            ; 0x31c <__addsf3x+0x9c>
 30a:   87 95           ror     r24
 30c:   77 95           ror     r23
 30e:   67 95           ror     r22
 310:   b7 95           ror     r27
 312:   f7 95           ror     r31
 314:   9e 3f           cpi     r25, 0xFE       ; 254
 316:   08 f0           brcs    .+2             ; 0x31a <__addsf3x+0x9a>
 318:   b0 cf           rjmp    .-160           ; 0x27a <__fp_sinus+0x44>
 31a:   93 95           inc     r25
 31c:   88 0f           add     r24, r24
 31e:   08 f0           brcs    .+2             ; 0x322 <__addsf3x+0xa2>
 320:   99 27           eor     r25, r25
 322:   ee 0f           add     r30, r30
 324:   97 95           ror     r25
 326:   87 95           ror     r24
 328:   08 95           ret

0000032a <__fp_inf>:
 32a:   97 f9           bld     r25, 7
 32c:   9f 67           ori     r25, 0x7F       ; 127
 32e:   80 e8           ldi     r24, 0x80       ; 128
 330:   70 e0           ldi     r23, 0x00       ; 0
 332:   60 e0           ldi     r22, 0x00       ; 0
 334:   08 95           ret

00000336 <__fp_mpack>:
 336:   9f 3f           cpi     r25, 0xFF       ; 255
 338:   31 f0           breq    .+12            ; 0x346 <__fp_mpack_finite+0xc>

0000033a <__fp_mpack_finite>:
 33a:   91 50           subi    r25, 0x01       ; 1
 33c:   20 f4           brcc    .+8             ; 0x346 <__fp_mpack_finite+0xc>
 33e:   87 95           ror     r24
 340:   77 95           ror     r23
 342:   67 95           ror     r22
 344:   b7 95           ror     r27
 346:   88 0f           add     r24, r24
 348:   91 1d           adc     r25, r1
 34a:   96 95           lsr     r25
 34c:   87 95           ror     r24
 34e:   97 f9           bld     r25, 7
 350:   08 95           ret

00000352 <__fp_nan>:
 352:   9f ef           ldi     r25, 0xFF       ; 255
 354:   80 ec           ldi     r24, 0xC0       ; 192
 356:   08 95           ret

00000358 <__fp_powsodd>:
 358:   9f 93           push    r25
 35a:   8f 93           push    r24
 35c:   7f 93           push    r23
 35e:   6f 93           push    r22
 360:   ff 93           push    r31
 362:   ef 93           push    r30
 364:   9b 01           movw    r18, r22
 366:   ac 01           movw    r20, r24
 368:   0e 94 df 01     call    0x3be   ; 0x3be <__mulsf3>
 36c:   ef 91           pop     r30
 36e:   ff 91           pop     r31
 370:   0e 94 4c 02     call    0x498   ; 0x498 <__fp_powser>
 374:   2f 91           pop     r18
 376:   3f 91           pop     r19
 378:   4f 91           pop     r20
 37a:   5f 91           pop     r21
 37c:   0c 94 df 01     jmp     0x3be   ; 0x3be <__mulsf3>

00000380 <__fp_pscA>:
 380:   00 24           eor     r0, r0
 382:   0a 94           dec     r0
 384:   16 16           cp      r1, r22
 386:   17 06           cpc     r1, r23
 388:   18 06           cpc     r1, r24
 38a:   09 06           cpc     r0, r25
 38c:   08 95           ret

0000038e <__fp_pscB>:
 38e:   00 24           eor     r0, r0
 390:   0a 94           dec     r0
 392:   12 16           cp      r1, r18
 394:   13 06           cpc     r1, r19
 396:   14 06           cpc     r1, r20
 398:   05 06           cpc     r0, r21
 39a:   08 95           ret

0000039c <__fp_round>:
 39c:   09 2e           mov     r0, r25
 39e:   03 94           inc     r0
 3a0:   00 0c           add     r0, r0
 3a2:   11 f4           brne    .+4             ; 0x3a8 <__fp_round+0xc>
 3a4:   88 23           and     r24, r24
 3a6:   52 f0           brmi    .+20            ; 0x3bc <__fp_round+0x20>
 3a8:   bb 0f           add     r27, r27
 3aa:   40 f4           brcc    .+16            ; 0x3bc <__fp_round+0x20>
 3ac:   bf 2b           or      r27, r31
 3ae:   11 f4           brne    .+4             ; 0x3b4 <__fp_round+0x18>
 3b0:   60 ff           sbrs    r22, 0
 3b2:   04 c0           rjmp    .+8             ; 0x3bc <__fp_round+0x20>
 3b4:   6f 5f           subi    r22, 0xFF       ; 255
 3b6:   7f 4f           sbci    r23, 0xFF       ; 255
 3b8:   8f 4f           sbci    r24, 0xFF       ; 255
 3ba:   9f 4f           sbci    r25, 0xFF       ; 255
 3bc:   08 95           ret

000003be <__mulsf3>:
 3be:   0e 94 f2 01     call    0x3e4   ; 0x3e4 <__mulsf3x>
 3c2:   0c 94 ce 01     jmp     0x39c   ; 0x39c <__fp_round>
 3c6:   0e 94 c0 01     call    0x380   ; 0x380 <__fp_pscA>
 3ca:   38 f0           brcs    .+14            ; 0x3da <__mulsf3+0x1c>
 3cc:   0e 94 c7 01     call    0x38e   ; 0x38e <__fp_pscB>
 3d0:   20 f0           brcs    .+8             ; 0x3da <__mulsf3+0x1c>
 3d2:   95 23           and     r25, r21
 3d4:   11 f0           breq    .+4             ; 0x3da <__mulsf3+0x1c>
 3d6:   0c 94 95 01     jmp     0x32a   ; 0x32a <__fp_inf>
 3da:   0c 94 a9 01     jmp     0x352   ; 0x352 <__fp_nan>
 3de:   11 24           eor     r1, r1
 3e0:   0c 94 e2 00     jmp     0x1c4   ; 0x1c4 <__fp_szero>

000003e4 <__mulsf3x>:
 3e4:   0e 94 bf 00     call    0x17e   ; 0x17e <__fp_split3>
 3e8:   70 f3           brcs    .-36            ; 0x3c6 <__mulsf3+0x8>

000003ea <__mulsf3_pse>:
 3ea:   95 9f           mul     r25, r21
 3ec:   c1 f3           breq    .-16            ; 0x3de <__mulsf3+0x20>
 3ee:   95 0f           add     r25, r21
 3f0:   50 e0           ldi     r21, 0x00       ; 0
 3f2:   55 1f           adc     r21, r21
 3f4:   62 9f           mul     r22, r18
 3f6:   f0 01           movw    r30, r0
 3f8:   72 9f           mul     r23, r18
 3fa:   bb 27           eor     r27, r27
 3fc:   f0 0d           add     r31, r0
 3fe:   b1 1d           adc     r27, r1
 400:   63 9f           mul     r22, r19
 402:   aa 27           eor     r26, r26
 404:   f0 0d           add     r31, r0
 406:   b1 1d           adc     r27, r1
 408:   aa 1f           adc     r26, r26
 40a:   64 9f           mul     r22, r20
 40c:   66 27           eor     r22, r22
 40e:   b0 0d           add     r27, r0
 410:   a1 1d           adc     r26, r1
 412:   66 1f           adc     r22, r22
 414:   82 9f           mul     r24, r18
 416:   22 27           eor     r18, r18
 418:   b0 0d           add     r27, r0
 41a:   a1 1d           adc     r26, r1
 41c:   62 1f           adc     r22, r18
 41e:   73 9f           mul     r23, r19
 420:   b0 0d           add     r27, r0
 422:   a1 1d           adc     r26, r1
 424:   62 1f           adc     r22, r18
 426:   83 9f           mul     r24, r19
 428:   a0 0d           add     r26, r0
 42a:   61 1d           adc     r22, r1
 42c:   22 1f           adc     r18, r18
 42e:   74 9f           mul     r23, r20
 430:   33 27           eor     r19, r19
 432:   a0 0d           add     r26, r0
 434:   61 1d           adc     r22, r1
 436:   23 1f           adc     r18, r19
 438:   84 9f           mul     r24, r20
 43a:   60 0d           add     r22, r0
 43c:   21 1d           adc     r18, r1
 43e:   82 2f           mov     r24, r18
 440:   76 2f           mov     r23, r22
 442:   6a 2f           mov     r22, r26
 444:   11 24           eor     r1, r1
 446:   9f 57           subi    r25, 0x7F       ; 127
 448:   50 40           sbci    r21, 0x00       ; 0
 44a:   9a f0           brmi    .+38            ; 0x472 <__stack+0x13>
 44c:   f1 f0           breq    .+60            ; 0x48a <__stack+0x2b>
 44e:   88 23           and     r24, r24
 450:   4a f0           brmi    .+18            ; 0x464 <__stack+0x5>
 452:   ee 0f           add     r30, r30
 454:   ff 1f           adc     r31, r31
 456:   bb 1f           adc     r27, r27
 458:   66 1f           adc     r22, r22
 45a:   77 1f           adc     r23, r23
 45c:   88 1f           adc     r24, r24
 45e:   91 50           subi    r25, 0x01       ; 1
 460:   50 40           sbci    r21, 0x00       ; 0
 462:   a9 f7           brne    .-22            ; 0x44e <__mulsf3_pse+0x64>
 464:   9e 3f           cpi     r25, 0xFE       ; 254
 466:   51 05           cpc     r21, r1
 468:   80 f0           brcs    .+32            ; 0x48a <__stack+0x2b>
 46a:   0c 94 95 01     jmp     0x32a   ; 0x32a <__fp_inf>
 46e:   0c 94 e2 00     jmp     0x1c4   ; 0x1c4 <__fp_szero>
 472:   5f 3f           cpi     r21, 0xFF       ; 255
 474:   e4 f3           brlt    .-8             ; 0x46e <__stack+0xf>
 476:   98 3e           cpi     r25, 0xE8       ; 232
 478:   d4 f3           brlt    .-12            ; 0x46e <__stack+0xf>
 47a:   86 95           lsr     r24
 47c:   77 95           ror     r23
 47e:   67 95           ror     r22
 480:   b7 95           ror     r27
 482:   f7 95           ror     r31
 484:   e7 95           ror     r30
 486:   9f 5f           subi    r25, 0xFF       ; 255
 488:   c1 f7           brne    .-16            ; 0x47a <__stack+0x1b>
 48a:   fe 2b           or      r31, r30
 48c:   88 0f           add     r24, r24
 48e:   91 1d           adc     r25, r1
 490:   96 95           lsr     r25
 492:   87 95           ror     r24
 494:   97 f9           bld     r25, 7
 496:   08 95           ret

00000498 <__fp_powser>:
 498:   df 93           push    r29
 49a:   cf 93           push    r28
 49c:   1f 93           push    r17
 49e:   0f 93           push    r16
 4a0:   ff 92           push    r15
 4a2:   ef 92           push    r14
 4a4:   df 92           push    r13
 4a6:   7b 01           movw    r14, r22
 4a8:   8c 01           movw    r16, r24
 4aa:   68 94           set
 4ac:   06 c0           rjmp    .+12            ; 0x4ba <__fp_powser+0x22>
 4ae:   da 2e           mov     r13, r26
 4b0:   ef 01           movw    r28, r30
 4b2:   0e 94 f2 01     call    0x3e4   ; 0x3e4 <__mulsf3x>
 4b6:   fe 01           movw    r30, r28
 4b8:   e8 94           clt
 4ba:   a5 91           lpm     r26, Z+
 4bc:   25 91           lpm     r18, Z+
 4be:   35 91           lpm     r19, Z+
 4c0:   45 91           lpm     r20, Z+
 4c2:   55 91           lpm     r21, Z+
 4c4:   a6 f3           brts    .-24            ; 0x4ae <__fp_powser+0x16>
 4c6:   ef 01           movw    r28, r30
 4c8:   0e 94 40 01     call    0x280   ; 0x280 <__addsf3x>
 4cc:   fe 01           movw    r30, r28
 4ce:   97 01           movw    r18, r14
 4d0:   a8 01           movw    r20, r16
 4d2:   da 94           dec     r13
 4d4:   69 f7           brne    .-38            ; 0x4b0 <__fp_powser+0x18>
 4d6:   df 90           pop     r13
 4d8:   ef 90           pop     r14
 4da:   ff 90           pop     r15
 4dc:   0f 91           pop     r16
 4de:   1f 91           pop     r17
 4e0:   cf 91           pop     r28
 4e2:   df 91           pop     r29
 4e4:   08 95           ret

The core of that calls 0x104 to convert an integer value that has been read from a port to float (IEEE754) then it calls sin() at 0x1D0.

 

To understand that further it's probably worth exploring the source at:

 

http://svn.savannah.gnu.org/view...

 

in particular sin() is in:

 

http://svn.savannah.gnu.org/view...

 

The first function it call is:

 

http://svn.savannah.gnu.org/view...

 

and so on....

Last Edited: Wed. Jan 24, 2018 - 12:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

El Tangas - I wasted the extra 192 bytes for speed last time I did it.

 

clawson - Well its not going to be a float in 8bits in the  LDI/LD Z  3 clock cycle variant.  Just an 8 bit signed fraction.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We still need to know what it is OP want integer (size ?), fraction (size?) or FP

The way he repeat to answer I don't think he know :( 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What the OP wants is someone to do the homework for him/her

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I always assume that is someone is doing ASM then they want speed.  So that is normally some kind of fixed point.

 

Of course most of the people seeking speed from ASM are probably better of with C because they may well end up doing a worse job than the compiler.

 

I think OP may just be a troll.

Pages