Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

real number from pic ???

Status
Not open for further replies.

capacitor1

Member level 3
Member level 3
Joined
Jul 25, 2012
Messages
66
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,744
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.
 

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.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top