I've been working on a data-collection application using a PICAXE-14M that I'd like to share with the community...
It collects data periodically in 4-bit nibbles from inputs 0-3. It then does some stuff with the data to convert it to human-readable ASCII and writes the data to an outboard memory that has a SPI interface.
The idea is that I want to dump the contents of the memory to a PC once in awhile.
My first try at this was to read the data back from the memory and transmit it to the PC using the sertxd command. Problem is, fetching the data from the memory, and getting in and out of the sertxd command adds a lot of overhead. Even though I'm clocking it at 8MHz and using a 9600baud rate, the aggregate data rate is very slow.
I then realized that I could drive the serial TX line to the PC directly from the output of the memory if I format the data and clock it appropriately.
So, now what I do is whenever I write a character into the SPI memory, I precede it with a "preamble" byte which is all 0x01. That's takes care of the stop and start bits that RS232 needs. When I want to stream the data to a PC, I put the memory in read mode and just clock it like crazy with the pwmout command, wait a certain amount of time with pause, and then shutdown the pwm.
I've been able to achieve 38400baud transfers with great reliability. I could probably go faster if I tried. And the speed-up is incredible. The old method took several minutes to transfer all the data. The new method now takes less than 2 seconds (8192 x 8 / 38400 = 1.7 seconds).
It collects data periodically in 4-bit nibbles from inputs 0-3. It then does some stuff with the data to convert it to human-readable ASCII and writes the data to an outboard memory that has a SPI interface.
The idea is that I want to dump the contents of the memory to a PC once in awhile.
My first try at this was to read the data back from the memory and transmit it to the PC using the sertxd command. Problem is, fetching the data from the memory, and getting in and out of the sertxd command adds a lot of overhead. Even though I'm clocking it at 8MHz and using a 9600baud rate, the aggregate data rate is very slow.
I then realized that I could drive the serial TX line to the PC directly from the output of the memory if I format the data and clock it appropriately.
So, now what I do is whenever I write a character into the SPI memory, I precede it with a "preamble" byte which is all 0x01. That's takes care of the stop and start bits that RS232 needs. When I want to stream the data to a PC, I put the memory in read mode and just clock it like crazy with the pwmout command, wait a certain amount of time with pause, and then shutdown the pwm.
I've been able to achieve 38400baud transfers with great reliability. I could probably go faster if I tried. And the speed-up is incredible. The old method took several minutes to transfer all the data. The new method now takes less than 2 seconds (8192 x 8 / 38400 = 1.7 seconds).