cancel
Showing results for 
Search instead for 
Did you mean: 

ARM Cortex M4., How can i know how many bytes a variable is taking to store the value?

Apill
Senior

Hi I have configured my ADC as Input 10 bit and i would like to sample the signal from accelerometer at 20KHz. I would like to know how much of address space is the memory taking to store these? Is the memory taking 1 byte, 2 byte, 4 byte ? How can I know that in Keil/ Data sheet ?

4 REPLIES 4

Depends on the definition of the variable, C use sizeof() to determine the size in bytes of a variable, structure, array, etc.

uint16_t takes 2 bytes

uint32_t takes 4 bytes

Some fairly basic data representation stuff...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

10-bits here could minimally use 2 bytes when stored as a 16-bit value

uint16_t array[200]; // 400 bytes

uint8_t array[1024]; // 1024 bytes

uint32_t arrary[1024]; // 4096 bytes

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

if i am using a 10 bit data from sensor, can it be stored in the format of uint8_t array ? If yes, how does the memory foot print work in this case ? will it be stored in two 8 bit addressing formats ?

The processor doesn't have a 10-bit format, it is held at a high precision level. The registers in the part are 32-bit, but it can also be handled as a 16-bit value

A uint16_t would be in two consecutive uint8_t memory locations, in the case of the Cortex part, in Little Endian format, so low order bits in the first byte, high order bits in the second.

An uint16_t array containing 1, 2, 3 would take six bytes in memory

01 00 02 00 03 00

This is Computer Studies 101 level stuff.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..