Hi Guys,
So I finally got some time to do some testing.
I have an admission to make - the 60uS I was seeing that started this whole process off seemed to be caused by failing to set my debug output that was watched with the logic analyser to a known state if the values didn't match...
What I did yesterday was run a few different comparison scenarios to see what sort of timing you got. Remember this is a 16f1933 running at 32Mhz, so instruction time is about 0.5us.
What I am doing is comparing the address I want to grab with the current position in the incoming data stream. I reset a counter when I see a header and then count each data packet coming in. When the address matches the count I receive the next three values into a buffer that the main code loop processes. The address can be a value from 1 - 512 so I need to use word variables.
Doing an if..then compare with two word variables takes 5.125 us
Code:
dbg_out = 1 ' set my debug line high for timing test
if current_position = current_add then
' do the buffer loading
endif
dbg_out = 0
Doing an if..then highbyte and lowbyte compare takes 2.125us
Code:
dbg_out = 1 ' set my debug line high for timing test
if current_position.highbyte = current_add.highbyte then ' 2.125 us
if current_position.lowbyte = current_add.lowbyte then
' do the buffer loading
endif
endif
dbg_out = 0
Doing an XORNOT compare takes 4.125us
Code:
dbg_out = 1 ' set my debug line high for timing test
if (current_position XORNOT current_add) then
' do the buffer loading
endif
dbg_out = 0
Doing an XORNOT Lowbyte Highbyte compare takes 7.625us
Code:
dbg_out = 1 ' set my debug line high for timing test
if (current_position.highbyte XORNOT current_add.highbyte) then
if (current_position.lowbyte XORNOT current_add.lowbyte) then
' do the buffer loading
endif
endif
dbg_out = 0
So it looks like Darell was correct that the fastest way is a If..Then with Lowbyte / Highbyte.
Bill.
Bookmarks