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
Nine Bit Binary Compare
Moderator: Benj
- DavidA
- Matrix Staff
- Posts: 1076
- Joined: Fri Apr 23, 2010 2:18 pm
- Location: Matrix Multimedia Ltd
- Has thanked: 58 times
- Been thanked: 258 times
- Contact:
Re: Nine Bit Binary Compare
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.
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.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Nine Bit Binary Compare
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)
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)
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Nine Bit Binary Compare
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
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