Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Newbie question about multiplication and data types

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Yokablasta

Bascom Member



Joined: 13 Dec 2017
Posts: 19

PostPosted: Wed Dec 13, 2017 10:07 pm    Post subject: Newbie question about multiplication and data types Reply with quote

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

(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5060
Location: Holland

blank.gif
PostPosted: Wed Dec 13, 2017 10:20 pm    Post subject: Reply with quote

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

this will multiply by .1

_________________
Mark
Back to top
View user's profile Visit poster's website
Yokablasta

Bascom Member



Joined: 13 Dec 2017
Posts: 19

PostPosted: Wed Dec 13, 2017 10:30 pm    Post subject: Reply with quote

Thanks Mark,
That makes sense. Let me give this a try. Hopefully that approach will give me the result I need. Thanks!
-Y
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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