# Counting

First I have to say that I am not a very fluent programmer but I have general knowledge in C+; this would be my first Arduino project.

I am trying to use the Arduino Mega (donated to me) to count analog voltage pulses coming from an optical interrupter. There is no definitive frequency involved with the pulses. The pulses need to count up to 99 on two, common anode, 7-segment displays. This seems like it should be a simple task but I have no idea where to start.

First, please don't cross-post. I'd go delete the other post.

This is indeed a straightforward project. With a Mega there are enough pins to drive the displays directly, they wouldn't even need to be multiplexed. I'd think most optical interrupters could be treated as a digital input signal as opposed to analog.

So yeah, simple, but we all have to walk before we run. What have you tried so far? Check around for tutorials, GIYF.

I have been doing a lot of surfing trying to figure out the best and cheapest way to do this. I don’t want to use a multiplexing IC. I am wiring the displays directly to pins in the MEGA. I am not sure how to get the display to read 00 then count up from there. I am thinking that I will have to use a line that increments the count. count(i=0, i<9, ++i) I have no idea how to write an array that will allow the count to continue or how to get the system to go beyone 9. I am really good with wiring, I just don’t have enough programming background to accomplish much.

From the Playground: http://arduino.cc/playground/Main/SevenSegmentLibrary

From what I'm finding the Arduino can't simply add 1 to a 7seg display based on seeing a random voltage change from an optical interupter.

Psuedocode: Optical interrupter is set around glass vial with 5V supply When object passes thru the vial interrupter voltage drops to 3.5V Interrupter is activated as a small particle pass the IR therefore the interrupt only last .1mS Vout from interrupter goes to Arduino and reads voltage change processor counts +1 for each voltage drop (drop >1V) count shown on 2 seperate 7segment displays after idle for 3 minutes the count should return to 0

therefore the interrupt only last .1mS

"only 100 microseconds" is equivalent to up to 1600 AVR instructions. That's really quite a long time.

First of all, try to break your project into manageable pieces. I would think you want to build a module that lights up one 7-segment display (digit) and then from there build a two display driver to display a given number.

You can then focus on the counting. Depending on the frequency coming in, the strategy can be quite different. You can configure a timer/counter to count into tens of Mhz, or you can use input capture to go into a fraction of a hz. So think about what signal you are dealing with first.

Then you will need to understand your encoder. What kind of signal does it generate and if it requires decoding, etc.

It is doable, you just need to organize your thought process more.

AWOL: "only 100 microseconds" is equivalent to up to 1600 AVR instructions. That's really quite a long time.

It's quite a short time if you have to guaranty that an A2D conversion occurs during this window to ensure detection.

I think the O/P is going to need some sort of threshold circuit to generate clean digital pulses. A simple comparator would be fine, with the inverting input set at 4V, then the non-invertinng input gets the 5V .. 3.5V signal and the comparator give you a nice clean rising edge suitable for generating an interrupt.

It's quite a short time if you have to guaranty that an A2D conversion occurs during this window to ensure detection.

The assumption that it is necessary to even perform an ADC is where the argument really falls apart. The processor is even equipped with an analogue comparator.