Sample bytes at 5MHz without using the counters
Bean
Posts: 8,129
I needed to sample bytes as fast as possible, but the counters are already used for something else.
After some experimenting I came up with this code that samples P0 to P7 at 5MHz.
I hope it helps others.
Bean
After some experimenting I came up with this code that samples P0 to P7 at 5MHz.
I hope it helps others.
' Samples bytes at 5MHz (must use pins P0 thru P7) ' laBufAddr must be set to the hub address of the buffer to hold the samples (must be word aligned) ' sampleCnt must be set to the number of samples to take (must be an even value) ' shr sampleCnt,#1 ' Divide sample count by two (using WRWORD) rdword value,laBufAddr ' ??,+7 Dummy instruction to sync to hub mov value,ina ' +7,+11 Read port put in value sub laBufAddr, #2 ' +11,+15 Adjust buffer address because it get inc'd before the first write capture add laBufAddr,#2 ' +15,+19 Adjust buffer address to next word shl value,#1 ' +19,+23 Move byte in value so MSB is in bit 8 movd value,ina ' +23,+27 Put new data in bit 16 thru 9 shr value,#1 ' +27,+23 Shift value so old data is now in bits 7-0 and new data in bits 15-8 wrword value,laBufAddr ' +31,+32,+7 Save the two data samples mov value,ina ' +7,+11 Read the port djnz sampleCnt,#capture ' +11,+15 Keep doing it until we are done
Bean
Comments
Nifty. Would it run any faster, reading 9 bits (sometimes users want 8 bits + strobe or flag)
A variant on this I've wondered about, is one that stores edge-time-stamps. (so does not store anything when data is static)
Because it stores more, the peak rate has to be a little lower, but the dynamic range is much larger, and I think WAITPNE can give finer sample resolution (with a caveat of some minimum change-spacing )
One application would be a 'Baud Meter' - a frequency counter that can extract actual Baud rates.
Or maybe: Assuming I understand the shadow registers right...
That would be cool if someone came up with that.