0

Good morning!

Sorry if my question is the most "asked" in the world but I would like you to clear my mind!

I have this project to do: to count, in some way, pulses coming from an encoder. The program will keep as input a value "limit" that the user can change "on run" (ex. the program reads the input in a thread and store the variable for the following cycle of the thread "counter"). The frequency should be up to 100KHz, 50Khz is good enough but you never know... it would be better to have higher performances... Every time thread counter reaches limit gives a digit in output.

The program on the microcontroller should be in C; the counter should never lose any pulse (reliability is a must).

This is all I know about the project for now, but I don't think I'll have much other specific...

The real question is: What microcontroller should I use of the commercials? Arduino? Raspberry? And if I use Raspberry will I risk SO doing some stuff in background losing pulses? And what about Beaglebone? Is there any beaten path about this problem (Some documentation and tutorial about a particular microcontroller)?

I repeat, I have not incredible specifics except for reliability! And sorry if I asked something is already been discussed but I'm really confused about the best and simplest solution! And please treat me like the worst of the newbies because probably I am!

Thanks a lot guys for your kindness!

  • yes absolutely you can, many perfectly valid solutions, so this is a bit broad of a question. Can be software based or some chips have timers or other peripherals you can stimulate from external sources to do the counting for you. – old_timer Dec 13 '16 at 20:41

3 Answers3

2

Definitely you don't want to use anything that has Linux or Windows operating system (ie. Raspberry, Beaglebone etc.), because they are not real-time and you cannot be sure that you will not miss any pulse.

Almost any modern microcontroller programmed in bare C should be enough. If you take AVR (eg. Atmega8 or Atmega16 or even Attiny2313) clocked 8MHz, and your target resolution is 100kHz, you will have 80 CPU cycles for one pulse. This definitely should be enough if you use hardware interrupt for detecting pulse. To be sure - two ways:

  1. Analyse code (assembly) after compilation. You will see how much instructions you have in your interrupt service routine. Then with you microcontroller datasheet you can count detailed number of cycles it will take
  2. Connect signal generator, set it to square wave and see at which frequency you start to loose pulses. If your target frequency is 2-3 times smaller you are in safe range.

After you finish part with counting, you can send number of pulses in eg. each second to some high-level computer/software, eg using UART or SPI. But this of course depends on your design requirements.

Mazi
  • 182
  • 8
1

There are two channels for Quadrature Enoders (QDEC) in Arduino Due, but original one is "out of stock". Some questions about it were in Arduino SE: How to configure 2nd Quadrature Decoder IO pins in Arduino IDE and Reading Two Quadrature Encoder using a single Arduino Due

Without it you have to use interrupts. However for the frequencies about 100kHz you might need some faster arduinos (ARM based) or external hardware decoder.

Something like:

enter image description here

and bidirectional counter for exmple ...

Community
  • 1
  • 1
KIIV
  • 3,534
  • 2
  • 18
  • 23
1

You can use microcontroller (such as AVR) or Arduino (which most of it also using avr microcontroller). To read pulses, you can use external interrupt feature, and timer feature. External interrupt is used to raise the rps count, which triggered by encoder, and timer feature is used to reset the rps count after calculating the total rotation of "x"-time (i.e : 1 sec)

cureinside
  • 23
  • 3