# real number from pic ???

#### capacitor1

Joined Jan 12, 2013
10
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

#### MrCarlos

Joined Jan 2, 2010
400
Hello Capacitor1

especially reads the content of the page 363.
It says SinE3 function is implemented as a lookup table.

#### Attachments

• 2.2 MB Views: 13

#### Markd77

Joined Sep 7, 2009
2,806
If you want to output the voltage to read on a multimeter, etc, you can use a PWM pin / software PWM, and a resistor capacitor filter to make it into a stable voltage.

#### nigelwright7557

Joined May 10, 2008
532
When I did assembler I just used a 90 value look up table.
I mirrored for 90-180 then made negative from 180-359 degrees.

#### capacitor1

Joined Jan 12, 2013
10
Hi

thanks for your help, but the second part that i have to convert it to a real number in volts ??

#### WBahn

Joined Mar 31, 2012
24,970
What do you mean "convert it to a real number in volts"? This doesn't make a lot of sense, just like saying "display this number as analog" doesn't make a lot of sense in your first post.

Are you saying that you need to output a representation of it as an analog voltage? If so, what conversion factor are you trying to get (how many volts per degree)? What about negative angles?

#### thatoneguy

Joined Feb 19, 2009
6,359
If you want AC out, You will need a DAC (Digital to Analog Converter

An approximation can be made with PWM + low pass filter.

Depends on the accuracy you desire as to which method you choose.