Reading 8 bit binary to output a number.

I am currently working on a shooting chronograph for my digital class. I am forced to go out of my way to make it work by using digital logic. I have a 555 timer outputting a 50khz square wave and a 8 bit JK flip flop counting the number of pulses between the first infrared sensor tripping and the second sensor tripping. The idea is that once the projectile (airsoft bb traveling 250-600 FPS) passes the first IR sensor it will allow the 555 timer pulses to proceed to the JK flip flop counter then the 2nd sensor will stop the counter and I will be left with the number of pulses between the 2 sensors tripping. The number of pulses will be in 8 bit binary and now I want to read the binary with the arduino to get a number such as 200 so I can do the math and output how fast the projectile was traveling in feet per second.

I am unaware of any built in programs to read 8 bits of binary in parallel and convert it into a number. does such a thing exist? If not what way would you recommend for me? Please be aware that I am not a programming expert I know just enough to get by so please try to dumb down the talk if I require more advanced programming features. I greatly appreciate any help you can provide.

Hello,

I'm not sure why you need a 555, or a JK flip flop (to be honest I don't even know what it is). Can't you use just the arduino for that?

Anyway for your question:

read 8 bits of binary in parallel and convert it into a number

  • If the 8 inputs are on the same port (and wired in the correct order), you can just read the port to get the byte. See here and here.

  • To make a byte out of 8 bits:

byte value = bit7 << 7 | bit6 << 6 | bit5 << 5 | bit4 << 4 | bit3 << 3 | bit2 << 2 | bit1 << 1 | bit0;

I am forced to use the 555 timer and the flip flops to do the digital work since it is for my digital class, I have already proved the concept works with the arduino by using 15 lines of code and 2 inputs but now I must do it the hard way for class. The 8 inputs will not be serial they will be parallel but I can read one input after another and place them in a array if needed. Im just not very good at the programming and not 100% sure of the best approach for this. I was hoping there was already a build in program like a BDC decoder that I was just unaware of.

guix:
Anyway for your question:

  • If the 8 inputs are on the same port (and wired in the correct order), you can just read the port to get the byte. See here and here.

So once I have read and saved the byte how do I go about converting it into a number? Also will the byte be saved as a array? I never used the byte feature before.

If you need to read the bits one after another, then it's not parallel, it is serial. So forget my hint about using ports.

You could also replace my hint about how to make a byte out of 8 bits, by a for loop, for example:

byte value;
for ( int8_t i = 7; i >= 0; i-- )
  value |= readOneBit() << i;

A byte is already a number :wink:

To clear up and confusion I made a short video showing the flip flops. I used a 3hz square wave so you can see the action instead of the 50khz wave. Once the bb passes the second sensor the blinking will stop and I will be left with the binary count (the white led is the most significant digit) of how many pulses have passed between the 2 sensors. I would like to use pins 0-7 to read the binary then convert it to decimal.

If I use the byte method as mentioned above how do I use the number? can I just say something like "somevarible = value + 5" and the value will already be converted from binary?

byte value;
for ( int8_t i = 7; i >= 0; i-- )
value |= readOneBit() << i;

Video: View My Video

That is even more confusing :wink:

I would like to use pins 0-7 to read the binary then convert it to decimal.

Then use:

byte value = PIND;
// this can be written like this, too:
uint8_t value = PIND;

That will read the states of pins 0 to 7.

Same as doing digitalRead( 0 to 7 ) and then using bit shifting as in my first post. But much faster :wink:

You dont need to convert anything, a byte is a 8-bits unsigned integer and you are free to do any maths with it, so yes you can do somevariable = value + 5.

Thank you for the help, I will finish the wiring and give it a shot tomorrow afternoon. Ill report back.