Posted: Wed Dec 13, 2017 10:07 pm Post subject: Newbie question about multiplication and data types
Hello,
I am a hardware engineer that's somewhat new to BASCOM. I have been working on a sensor project that calculates the center of mass of an object by using 16 force sensors. I am using the 10-bit ADC on an ATMEGA48P to scan 16 force sensors and record the readings in an array. The data type of the ADC readings is a word. That part of my program works fine. I run into issues when I try to multiply those readings by a scaling factor. I keep getting an assignment error, which I believe is due to me not using the correct data types. I'm having some difficulty finding a clear source of info about how to multiply and divide in Bascom AVR. If I have a 10-bit ADC reading, and I want to multiply it by something like .10, what data type should the result be? What data type should the .01 be? Any pointers would be appreciated.
-Y
the data types should be equal. if you really need floating point math, you need to use a single or a double.
but your data is in a word. is the a/d converter 1024 maximum?
If you want to multiply by 0.1 it is the same as dividing by 10
so it is best to keep everything in a word when the value fits, and otherwise a long or dword.
dim ar(10) as word
dim scale as word
scale=10
ar(1)=ar(1) / scale
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum