ADC Calculation is getting wrong

Moderator: Benj

Post Reply
Ali Reza Danish
Posts: 8
Joined: Mon Aug 05, 2019 8:15 pm
Has thanked: 5 times
Contact:

ADC Calculation is getting wrong

Post by Ali Reza Danish »

I'm using a potentiometer to measure angle. Since potentiometers max angle varies I'm using another potentiometer to adjust the max angle.
But this calculation is not working. In the maximum range Shaft angle should have shown 360 but its showing 499.That means only (shaftVolt * 100)
is working. And dividing it with Ratio is not working.
AdjVolt = (AdjVolt * 100) / 1.38611
Ratio = (499 / AdjVolt)
//shaftVolt = (shaftVolt * 100) / 1.38611
shaftVolt = (shaftVolt * 100) / Ratio

Thank you
Attachments
Screenshot_2.png
(79.22 KiB) Downloaded 1695 times
Guddu keypad copied v5 to v8 With Adj.fcfx
(25.52 KiB) Downloaded 194 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: ADC Calculation is getting wrong

Post by LeighM »

Hi
Your Ratio variable is an integer, it should be a float

Ali Reza Danish
Posts: 8
Joined: Mon Aug 05, 2019 8:15 pm
Has thanked: 5 times
Contact:

Re: ADC Calculation is getting wrong

Post by Ali Reza Danish »

I have changed Ratio from Int to Float. Now its showing just 0 wherever the Potentiometer is.

Thanks.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: ADC Calculation is getting wrong

Post by LeighM »

The LCD PrintNumber() can only print integers.
For float values first convert to a string with FloatToString$()
Then print the string

Ali Reza Danish
Posts: 8
Joined: Mon Aug 05, 2019 8:15 pm
Has thanked: 5 times
Contact:

Re: ADC Calculation is getting wrong

Post by Ali Reza Danish »

Thanks Leigh,
It worked. But showing the value e.g as 270.434245 but if I want to show just two or three values after decimal as "176.34" or completely remove the values after decimal point along with the point "." as"176" what should I do.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: ADC Calculation is getting wrong

Post by LeighM »

Code: Select all

flt = 3.14159
str = FloatToString$ (flt,2)

Post Reply