Is there a way to use decimals in my internal calculations without having to multiply things to huge numbers to make it work, for example: to find voltage of an a/d with 5vdc supply i have a 0.0048828 vdc per a/d value and i want to have the pic calculate the actual voltage so a/d value * 0.0048828 = voltage?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Great Cow BASIC does not support floats currently.
However, this can be worked around. If you factor up your calcualtions and then factor back down after your long divisions (these after factoring up will be integer) you will get the results you require.
There are many examples of factoring integers to decimals - the DS18B20 is a great example.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Huge numbers are not really necessary to do the necessary calculations. A Word variable is enough .
To make the maths easier we can "map" or scale tthe ADC Value so that 1 ADC unit is equal to precisely 10 mV instead of 4.8828 mV.
First scale the ADC for 1000 units instead of 1024. Then Divide by 2
Now full scale ADC 0-1023 wil return 0 - 500 ( 0 - 5 volts
Below is a demo program that shows the maths and displays the Voltage.
Attach a 10K Pot to the ADC Pin, making the POT Ground and Vdd are as close as possible to the PIC Ground and VDD.
Is there a way to use decimals in my internal calculations without having to multiply things to huge numbers to make it work, for example: to find voltage of an a/d with 5vdc supply i have a 0.0048828 vdc per a/d value and i want to have the pic calculate the actual voltage so a/d value * 0.0048828 = voltage?
Hello and welcome,
Great Cow BASIC does not support floats currently.
However, this can be worked around. If you factor up your calcualtions and then factor back down after your long divisions (these after factoring up will be integer) you will get the results you require.
There are many examples of factoring integers to decimals - the DS18B20 is a great example.
Hi Ryan,
Huge numbers are not really necessary to do the necessary calculations. A Word variable is enough .
To make the maths easier we can "map" or scale tthe ADC Value so that 1 ADC unit is equal to precisely 10 mV instead of 4.8828 mV.
First scale the ADC for 1000 units instead of 1024. Then Divide by 2
Now full scale ADC 0-1023 wil return 0 - 500 ( 0 - 5 volts
Below is a demo program that shows the maths and displays the Voltage.
Attach a 10K Pot to the ADC Pin, making the POT Ground and Vdd are as close as possible to the PIC Ground and VDD.