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