AVR Assembler Problem with DB (ATMega8)

Hello people. I'm sorry, before all, because I write a little of English.

I need to calculate the sinus (trigonometric function). This way:

-The angle will be entered by the PortB, and the sinus come back by the PortD (multiply per 100)

-The calculation will be make with a table.

-The table must have in de flash memory ( Z ?)

This is de table (DB?):

0 10 20 30 40 50 60 70 80 90 0 17 34 50 64 77 87 94 98 100 (Sinus) For example. If I have a 20 in PortB, I need that PortD have a 34.

I have this code, but I don't how continue...

.INCLUDE "m8def.inc"

.DEF n = R16 .DEF suma = R17 .DEF i = R18

.ORG 0x0 rjmp inici

inici:

//ldi XH, high(2*sinus) ; high(0x60) ldi ZL, low(2*angle) ldi ZH, high(2*sinus) angle: .DB "0 10 20 30 40 50 60 70 80 90 100",0 sinus: .DB "0 17 34 50 64 77 87 94 98 100",0 in n, PINB ; take n

fi:rjmp fi

Thank you!

Reply to
Serafin
Loading thread data ...

Serafin schrieb:

The following is a quick, absolutely untested solution. Just a few words: My sinus table is a sequence of sin(0°),sin(1°),sin(2°),... So you just read the degrees from port B, add them to the table start, read the value at that location with lpm, and send it to port D. lpm is limited to 64k flash, for larger flashes you need elpm. The table only needs the values for 0..90°. For larger values you can use symmetries: a>180°: sin(a)=-sin(a-180°) then

90°
Reply to
Frank-Christian Krügel

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.