# real number from pic ???

Status
Not open for further replies.

#### capacitor1

##### Member level 3
Hi!

I have an angle in the microcontroller from 0 to 360 , and I want to calculate its Sin , and display this number as analog .

I use CCS compiler , and I think that the Math library exists.

the hard thing how to convert the number from 0 to 1 ( if we neglige the negatif numbers ) , and with 3 digits after the point . (0.000,0.001,....,0.999,1.000) to a voltage .

Ex: if the angle=60 : sin(60)=0.8660254≈0.866 ===> 0.866V

thanks

First you will need to include math.h library, Then convert the angle to radian from degree.

#INCLUDE <math.h>
unsigned int16 angel;
float voltage;
....
voltage=sin(3.141596*angle/180);
...

But note that the built in function of sine will take around 2ms for the conversion considering 20MHz crystal.
instead I will recommend to use lookup table.

Hi
Ok, and how i can convert it to a number from 0 to 1 V

thanks

If you want to output 0 volt to 1 volt on a pin then you will need to generate PWM on that Pin.
If you want to display on LCD etc then the value is already in that format.

Status
Not open for further replies.