sin(x) is not in radians nor degrees, it is just a number between -1.0 and 1.0
Anyway the math.h defines the function as double sin(double); so unless you do a sin of pi/4 you will allways get 0 on the output.
sin(x) is not in radians nor degrees, it is just a number between -1.0 and 1.0
Anyway the math.h defines the function as double sin(double); so unless you do a sin of pi/4 you will allways get 0 on the output.
Sin() doesn´t return radians, it allways returns a fraction without any units, but it is true that the parameter is in radians.
(sinus of an angle is equal to a ratio of two sides in a triangle, so it can´t have any units)
Sin() doesn´t return radians, it allways returns a fraction without any units, but it is true that the parameter is in radians.
(sinus of an angle is equal to a ratio of two sides in a triangle, so it can´t have any units)
If you already have the sin(a) function you can easily generate it using that. Just multiply by a constant to form the table value. The highest value is 1 and that is at 90 degree, and the lowest value is -1 and that is at 270 degrees (convert degrees to radians as needed) but we usually only need the values for 0 to 90 degrees which returns a float value 0 to 1. So if 0x0FFF is the highest value you need at 90 degrees, then multiply all the return values of sin(a) by 0x0FFF.
For example in a simplified language:
for k=0 to 19 do
a=sin(k/19*pi/4)
y=sin(a)
Y=y*0x0FFF
Table[k]=Y
end for
That creates a table that is entered into ram that covers 0 to 90 degrees, and that provides enough values to cover the full range of 0 to 360 degrees.
A sine table in a microcontroller is straightforward.
Since microcontrollers don't read or store decimal numbers, these sine values must be scaled. Precalculate these sine wave values as a microcontroller will have a tough time working on it.
Then discretize the sine values for one period. Example, for 256-value sine table, sin(x/256*2pi*127) + 127 and rounded. So after getting these 256 values, dump them inside the array. The values should be 0 - 255 and plotting this in excel will get you a sine wave.
For a controllable synthesis of sine wave, it's advisable to read up on Digital Direct Synthesis (DDS). It is a simple algorithm to generate a sine wave on a microcontroller. However, some filtering is required on the output.
I made my own sine wave generators (it's for the toy music boxes) all using this method, without involving math.h or whatsoever.