Sorry to instrude on your thread but since this was also a question of the same nature, I also wish to know this as Im trying to do a caculation on value from AN0 such as:
DataConstant = (5 / 255)
Reading = ReadAD(AN0)
Voltage = Reading * DataConstant
CLS
PRINT "Voltage: "
LOCATE 1,2
LCDInt(Voltage)
Obviously this needs rounding up somehow
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Also, using a precision voltage reference IC has been discussed before on this forum. In short, if a 4.096V reference IC output is applied to the Vref+ pin, and say a word sized a-d input is used (e.g. ReadAD10(AN0)), an integer multiplier is obtained. Your volts per bit is then, 4.096V/1024bits or an even 4, which makes for easy scaling. Probably not necessary for every project you have, but handy when needed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is it possible to do division and multiplication with irrational numbers in GCBASIC? Is there any limitations?
e.g. 12/3.1416
Sorry to instrude on your thread but since this was also a question of the same nature, I also wish to know this as Im trying to do a caculation on value from AN0 such as:
DataConstant = (5 / 255)
Reading = ReadAD(AN0)
Voltage = Reading * DataConstant
CLS
PRINT "Voltage: "
LOCATE 1,2
LCDInt(Voltage)
Obviously this needs rounding up somehow
Try something like this:
Voltage = [word]ReadAD(AN0) * DataConstant
The [word] forces GCBASIC to treat ReadAD as a word variable, which will result in the word routines being used for the calculation.
GCBASIC can only deal with whole numbers at the moment. The best workaround for this is to multiply everything by 1000, so 12000/3142.
Also, using a precision voltage reference IC has been discussed before on this forum. In short, if a 4.096V reference IC output is applied to the Vref+ pin, and say a word sized a-d input is used (e.g. ReadAD10(AN0)), an integer multiplier is obtained. Your volts per bit is then, 4.096V/1024bits or an even 4, which makes for easy scaling. Probably not necessary for every project you have, but handy when needed.