Forum - MCS Electronics

Author Message
Yokablasta

Joined: 13 Dec 2017
Posts: 19

 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 (BASCOM-AVR version : 2.0.7.8 )
albertsm

Joined: 09 Apr 2004
Posts: 5060
Location: Holland

 Posted: Wed Dec 13, 2017 10:20 pm    Post subject: 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
Yokablasta

Joined: 13 Dec 2017
Posts: 19

 Posted: Wed Dec 13, 2017 10:30 pm    Post subject: Thanks Mark, That makes sense. Let me give this a try. Hopefully that approach will give me the result I need. Thanks! -Y
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1

 Jump to: Select a forum BASCOM AVR/8051----------------BASCOM-AVRBASCOM-8051BASCOM-ARDUINOShare your working BASCOM-8051 code hereShare your working BASCOM-AVR code hereBASCOM BETA-SLA BASCOM Related----------------EASY TCP/IPAVR-DOSAR7212KokkeKat FAT-free SD card libBASCOM Project Blog Other Stuff----------------VariousPCB'sRoboticsNew WebSiteAnnouncementsAVR Archive----------------BASCOM-AVR ArchiveBASCOM-8051 ArchiveBASCOM-AVR Unsupported versionsEasy TCP/IP ArchiveBASCOM-EDB
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