Page 1 of 1

Nine Bit Binary Compare

Posted: Wed Mar 07, 2012 5:56 pm
by jbell
All,

I’m embarking on a project that will require me to compare a binary number from an external source with a binary number entered into Flowcode. If they are the same, an output goes high. All fairly straightforward, except I need to be able to count to 1000 so I need 9 bits. My processor is a PIC 18F4520 which is, of course, 8 bits so I’ll need to “borrow” a bit from a second port. My first thought was to simply divide the ports into high-byte and low-byte and do separate comparisons. The problem is that would take more than twice as many clock cycles as a single port and speed is also an issue since the external binary number could be changing as fast as every microsecond. I would very much appreciate any thoughts from the community on how I might do this in the most efficient manner, preferably without the use of C or Assembly as I’m not terribly advanced in that level of programming.

Thanks,

Jim Bell

Re: Nine Bit Binary Compare

Posted: Fri Mar 09, 2012 11:17 am
by DavidA
Hey jbell,

I would imagine that its not possible to do it as efficiently as you are requiring in Flowcode, you could do an 8bit and a 1bit compare in Flowcode but im not sure how the ASM would look and whether it would be more efficient than two 4bit compares. If you want real speed and efficiency i would have thought you would need to use C or ASM to accomplish what you want.

Re: Nine Bit Binary Compare

Posted: Fri Mar 09, 2012 12:08 pm
by Benj
Hello,

The most optimum solution would be to do two 8-bit comparisons.

so you would store your compare variables eg.

compa = 0x01
compb = 0x48

Then you would collect the data from the ports using input icons

portcompa = porta
portcompb = portb

Then mask off the single bit

portcompa = portcompa & 0x01

Then perform the comparison using a decision.

(portcompa == compa) && (portcompb == compb)

Re: Nine Bit Binary Compare

Posted: Fri Mar 09, 2012 10:31 pm
by jbell
Thanks very much David and Ben for your thoughts.

I figured it would be a stretch trying to do this in Flowcode with the throughput I'm going to need. Nonetheless, I'm gonna ramp my processor up to 40MHz and give it a shot.

Worst case I'll have to drop back to a hardware solution and use a couple of 74xx688's to do the compare and just use Flowcode to wait for a "match" signal.

Regards,

Jim Bell