Microcontroller with 24-bit counter

Hi,
I need a microcontroller with a 24-bit counter which can connect up to a computer. I'm wanting to use Arduino or Rasberry Pi but they don't have 24-bit counters. What do I need to add to the microcontroller to make it able to have a 24-bit counter.

Thanks

See the code for micros() how a 16 bit counter can be extended to 32 bits. The timer/counter overflow can trigger an interrupt that can be used to increment an extension variable to the counter.

1 Like

You declare a variable like the following and then use the lower 24-bit as a whole counter.

unsigned long int y;

If you want an actual 24 bit integer, you can use __int24 and __uint24 for a signed and unsigned 24-bit integer, respectively.

1 Like

Hi thank you. Are you suggesting I can get a microcontroller with a lower or different counter then change the code for the clock to be 24 bit

Do you need a 24 bit variable for a counter, or a hardware counter with 24 bits?

What code? What clock? Are you writing code for a clock, or referring to the oscillator running the microcontroller?

1 Like

A bit confused as to what you are looking for. Do you need to count up to 24bits, not a big problem, or are you looking for a MCU with a 24 bit Timer?

1 Like

I think you need at least a Cortex-M3 to have a 24-bit hardware counter

1 Like

What do you want to count and how fast do you want to count it?

2 Likes

SAMD21 (Arduino Zero, assorted MKR boards) has 24bit counters (TCC) and 16bit counters that can be combined into 32bits.
Plus the 24 bit sysTick counter.

millis() can be considered a 32bit counter.

As many have pointed out, it's pretty easy to extend an 8 or 16bit counter in software.

It depends on what you want to do.

1 Like

Sorry if I didn't explain this properly. I have a load cell with a 24-bit ADC Amplifier attached to it and I need a microcontroller to connect upto a computer as well as to supply a clock and process the 24-bit signal from the amplifier. Thank you so much.

Do you need to supply a clock signal to the ADC, or are you referring to a clock to tell the time in hours/minites/seconds?

Where exactly is a 24-bit counter needed?

Please read the forum guidelines, especially the part about how to supply the information that is needed to answer a question.

The explanation in reply #11 is still not nearly enough.

The choice of microcontroller for your application depends on a lot of things that you haven't explained about your circuit. Usually, the number of bits that some peripheral works with, is far, far down on the list of important things to know. So please supply more details about the role that the microcontroller plays and any other requirements.

There are simple things you could convey that would be helpful, such as part numbers. As you can see, asking the wrong question got you a lot of good answers that aren't useful to you.

_int24 x; or _uint24 y; do not get compiled in Arduino IDE?

There is a double underscore at the beginning, you are only using a single underscore. Also, not all processor cores support 24 bit integers.

Here is the tested Solution:
1. Wiring among UNO, ADC, and Load Cell

2. The Sketch

/* This program takes 10 samples from LC + HX711B at
   1-sec interval and then computes the average.
*/

unsigned long x = 0, y = 0;
unsigned long dataArray[10];
int j = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(A1, INPUT); //data line  //Yellow cable in my Setup
  pinMode(A0, OUTPUT);  //SCK line  //Orange cable in my Set up
}

void loop()
{

  for (int j = 0; j < 10; j++)
  {
    digitalWrite(A0, LOW);//SCK is made LL
    while (digitalRead(A1) != LOW) //wait until Data Line goes LOW
      ;
    {
      for (int i = 0; i < 24; i++)  //read 24-bit data from HX711
      {
        clk();      //generate CLK pulse to get MSB-it at A1-pin
        bitWrite(x, 0, digitalRead(A1));
        x = x << 1;
      }
      clk();  //25th pulse
      Serial.println(x, HEX);
      y = x;
      x = 0;
      delay(1000);
    }
    dataArray[j] = y;
  }

  Serial.println("===averaging process=========");
  unsigned long C1 = 0;   //C1 = Count-1 against no fuel in the Tank

  for (j = 0; j < 10; j++)
  {
    C1 += dataArray[j];
  }
  Serial.print("Average Count = ");
  C1 = C1 / 10;
  Serial.println(C1, HEX);
}

void clk()
{
  digitalWrite(A0, HIGH);
  digitalWrite(A0, LOW);
}
1 Like

It is now compiled with double underscore (__int24 x:), but it is not supported by Serial.println() method. The following command gives error:

__int24 x = 1234;
Serial.println(x, DEC);

Error Message:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

D:\ArduinoUNO\7segTwo\7segTwo.ino: In function 'void setup()':

7segTwo:11:24: error: call of overloaded 'println(__int24&, int)' is ambiguous

   Serial.println(x, DEC);

                        ^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Stream.h:26:0,

                 from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:29,

                 from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:233,

                 from sketch\7segTwo.ino.cpp:1:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:81:12: note: candidate: size_t Print::println(unsigned char, int)

     size_t println(unsigned char, int = DEC);

            ^~~~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:82:12: note: candidate: size_t Print::println(int, int)

     size_t println(int, int = DEC);

            ^~~~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:83:12: note: candidate: size_t Print::println(unsigned int, int)

     size_t println(unsigned int, int = DEC);

            ^~~~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:84:12: note: candidate: size_t Print::println(long int, int)

     size_t println(long, int = DEC);

            ^~~~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:85:12: note: candidate: size_t Print::println(long unsigned int, int)

     size_t println(unsigned long, int = DEC);

            ^~~~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:86:12: note: candidate: size_t Print::println(double, int)

     size_t println(double, int = 2);

            ^~~~~~~

exit status 1

call of overloaded 'println(__int24&, int)' is ambiguous



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

type or paste code here

The 24 bit integer types are not widely supported by functions, but are available. The only thing I've ever used it for was arrays of rgb data for LEDs.

1 Like

People, people... who says a 24 bit integer is even necessary? We all should know a 24 bit value fits just fine in an 'uint32_t'.

The question was not how to do it, either. Just what processor to use.

1 Like

Hi. This is perfect thanks. I am using the HX711 Sparkfun Amp.