![]() |
Forum Index : Microcontroller and PC projects : Maths question
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
This is probably easy for someone experienced but to me I cannot figure it out. I have an anemometer that gives a voltage output depending on the direction of the anemometer and the reference voltage Each degree gives a voltage of 0.0091666666666667V so for example 10 degrees would be 0.091666666666667V 176 degrees would be 1.613333333333339V and so on I need an easy way to convert the reading into a decimal degree ie 1 - 360 It's a "simple" maths equation I believe but I cannot figure out how to express it. I "could" do it by using a lookup table of 360 voltages but thats a lot of wasted code space I already have the code written to display the wind direction as NNE, NE, E, ESE, SE, S, and so on. But I'd like to also be able to display the decimal degree position so that it can upload an accurate wind position to one of the weather servers Any suggestions on how to "phrase" the calculation? |
||||
bigmik![]() Guru ![]() Joined: 20/06/2011 Location: AustraliaPosts: 2949 |
GDay Lew, Wouldn't it be as simple as Angle = MeasuredReading / 0.0091666666666667 I think that level of accuracy couldn't be read on the analog inputs maybe you should stop at say 4-6 decimal places? Kind Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
paceman Guru ![]() Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Just divide your voltage reading by 0.0091666 then round the result with the CINT function. i.e. DIM AS FLOAT degrees, volts degrees = volts/0.0091666 then to round it; degrees = CINT(degrees) You'll need to do a couple of 'sanity' checks on the raw voltage reading too no doubt, like test for negative voltages or voltages outside the 360o range (360x0.0091666). Also you'll probably need to average several readings over whatever time period is appropriate for you and remove any fliers in the averaging set. Greg Edit: Mik beat me to it, same same, and yes anything over four or five significant figures doesn't gain you anything. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks everyone |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
EDIT: Deleted the question because I managed to sort it and got it working ![]() |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |