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!
AVR Assembler Problem with DB (ATMega8)
Started by ●April 27, 2009
Reply by ●April 28, 20092009-04-28
Serafin schrieb:> 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 ?)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�<a<180�: sin(a)=sin(180�-a) The implementation of these formula is left as an exercise. ; Sinus Table sinus: .DB 0, 2, 3, 5, 7, 9, 10, 12, 14, 16 .DB 17, 19, 21, 22, 24, 26, 28, 29, 31, 33 .DB 34, 36, 37, 39, 41, 42, 44, 45, 47, 48 .DB 50, 52, 53, 54, 56, 57, 59, 60, 62, 63 .DB 64, 66, 67, 68, 69, 71, 72, 73, 74, 75 .DB 77, 78, 79, 80, 81, 82, 83, 84, 85, 86 .DB 87, 87, 88, 89, 90, 91, 91, 92, 93, 93 .DB 94, 95, 95, 96, 96, 97, 97, 97, 98, 98 .DB 98, 99, 99, 99, 99,100,100,100,100,100 .DB 100 start: ldi R30,low(sinus) ldi R31,high(sinus) in R2, PINB clr R3 add R30,R2 adc R31,R3 lpm R2, Z out PORTD, R2 rjmp start -- Mit freundlichen Gr��en Frank-Christian Kr�gel