Generating Clock and CS signals in background
Philldapill
Posts: 1,283
I recently made a PASM driver for an ADC. The object works great, but I think it COULD work better. Many of the instructions that take alot of time are the clock and Chip Select signals. The clock should be a constant on/off signal, and the CS should be low for about 90% of the time, then high 10%, then back to low.
I'm only starting PASM, so forgive my ignorance. Could the counters be used to generate these signals in the background, allowing me to free up some instruction time for the actual code? If so, how would I go about sync'ing up the counters with my instructions? Examples?
I'm only starting PASM, so forgive my ignorance. Could the counters be used to generate these signals in the background, allowing me to free up some instruction time for the actual code? If so, how would I go about sync'ing up the counters with my instructions? Examples?
Comments
Yes, use the counters and then since your CS and CLK signals go to external devices they appear on IO pins which you can read with the INA instruction. So you could use waitpne and waitpeq to sync up the other parts of your code. Or, you could implement something like the system in FullDuplexSerial where you look at the pin state and if it doesn't match your 'do the next bit' criteria you go away and do a bit more housekeeping, coming back at regular intervals to check the pin state.
I don't recall where the original code is, but here's a version that I've modified a few times.
I've found it provides very accurate frequencies. At least as accurate as I can measure with my scope.
Jim
to generate clocks (but not chip select).
If you had an external circuit that was appreciably faster than the prop it might be worthwhile. It might be possible to use the video circuitry to generate chip select and clock signals, but it would be tricky to synchronize reading or writing data to those signals.
A couple of examples are:
1. TI sound codec that needed a 2.8224 MHz signal to achieve a 44.1 KHz sample rate.
2. A camera chip that needs a high frequency input for VGA frame processing.
These would be almost impossible to do with raw code.
Jim
For writing SPI, you can reduce per-bit times from (probably) four instructions to one using the counters.
Both of these are, in my view, substantial improvements.
rokicki, I agree that using the counters can reduce the number of instructions per bit, and with tight coding can potentially double the read speed and increase write speed even more compared to doing it all in software. What I question is what is gained if the spi or other chips are not fast enough to take advantage of that speed.
I am in favor of using any and all hardware and software tricks and techniques available to speed things up when there is some benefit from doing so. I am currently looking at building a multichannel pulse height analyzer with a minimum of 10 bits of resolution and a 10MHz sample rate. For that project I will be looking to save every cycle possible and using the counters will definitely be considered.