
Originally Posted by
sayzer
At 0 degree, record ADC value. Say it shows 150 (this would be your base value).
At 360 degree, record ADC value. Say it shows 900.
Then each degree would become as;
(900-150) / 360 = 2.
That means, when your ADC reading is 152, you will know that you are at 1st degree, 154 is 2nd, 156 is 3rd. etc...
With an additional math, which I am sure you can figure out, you can get the exact degree.
Was this what you needed, or I am in a different page?
----------------
Hi, Sayzer
... life is easy with you !!!
RF:
at first, be sure to use the posssible max of the ADC range for your measure ...
As said by sayzer, read the min ( 0°) and Max ( 359.9 °)
then you get a result between 0 and 1023 ... no use to look at a better than .1% precision ( humour )
But, to keep decimals, just multiply the result by ... 64 , to use the max counting possibilities of the Pic.
so, let's make it clear:
Scale = MaxValue - MinValue
dummy = ( AdcResult - MinValue ) x 64
' disable interrupts ... if necessary
dummy = dummy x 360
Result_64 = DIV32 Scale
' re enable
Now, dividing Result_64 by ... 64 ( 6 right shifts ...) give the INT part.
... and , if needed, the 6 right digits will give 64 x the decimal part.... a little bits shifting ( or multiplying i.e. by 100 )and you can show it !!!
life is sooooooooo simple ....
Alain
Last edited by Acetronics2; - 2nd October 2006 at 09:43.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Bookmarks