I was mistakenly using 16 bits per sample instead of 8 bits.

Change to using an array of bytes instead of integers.  Retune
timing loops now that each sample is not doing a 16 bit update.
We can now record 1024 samples easily.
This commit is contained in:
gillham
2011-02-28 14:08:07 -08:00
parent 8da515d708
commit 7bc04e7766

View File

@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: logic_analyzer.pde,v 1.8 2011-02-20 06:54:16 gillham Exp $ * $Id: logic_analyzer.pde,v 1.11 2011-02-28 22:04:37 gillham Exp $
* *
*/ */
@@ -38,7 +38,7 @@
* 6 channels. * 6 channels.
* *
* NOTE: * NOTE:
* You must DISABLE the Arudion auto reset feature to use this logic analyzer * You must DISABLE the Arduino auto reset feature to use this logic analyzer
* code. There are various methods to do this, some boards have a jumper, * code. There are various methods to do this, some boards have a jumper,
* others require you to cut a trace. You may also install a *precisely* * others require you to cut a trace. You may also install a *precisely*
* 120 Ohm resistor between the reset & 5V piins. Make sure it is really * 120 Ohm resistor between the reset & 5V piins. Make sure it is really
@@ -49,7 +49,7 @@
* *
* Sampling rate: 1MHz (or lower) * Sampling rate: 1MHz (or lower)
* Channel Groups: 0 (zero) only * Channel Groups: 0 (zero) only
* Recording Size: 512 (or lower) * Recording Size: 1024 (or lower)
* Noise Filter: doesn't matter * Noise Filter: doesn't matter
* RLE: disabled (unchecked) * RLE: disabled (unchecked)
* *
@@ -58,7 +58,7 @@
* until after the trigger fires. * until after the trigger fires.
* Please try it out and report back. * Please try it out and report back.
* *
* Release: v0.01 February 19, 2011. * Release: v0.02 February 28, 2011.
* *
*/ */
@@ -109,15 +109,14 @@ void debugdump(void);
#define SUMP_GET_METADATA 0x04 #define SUMP_GET_METADATA 0x04
/* /*
* trying to have 1024 bytes free for logicdata by turning things off. * Capture size of 1024 bytes works on the ATmega328.
* almost works at 908 bytes, but need 1024 for the client. *
* 1024 doesn't work, so still set to 512 for both cases.
*/ */
#define DEBUG #define DEBUG
#ifdef DEBUG #ifdef DEBUG
#define MAX_CAPTURE_SIZE 512 #define MAX_CAPTURE_SIZE 1024
#else #else
#define MAX_CAPTURE_SIZE 512 #define MAX_CAPTURE_SIZE 1024
#endif /* DEBUG */ #endif /* DEBUG */
/* /*
@@ -125,16 +124,16 @@ void debugdump(void);
* SUMP commands are either 1 byte, or for the extended commands, 5 bytes. * SUMP commands are either 1 byte, or for the extended commands, 5 bytes.
*/ */
int cmdByte = 0; int cmdByte = 0;
int cmdBytes[5]; byte cmdBytes[5];
#ifdef DEBUG #ifdef DEBUG
int savebytes[128]; byte savebytes[128];
int savecount = 0; int savecount = 0;
#endif /* DEBUG */ #endif /* DEBUG */
int logicdata[MAX_CAPTURE_SIZE]; byte logicdata[MAX_CAPTURE_SIZE];
/* 908 works initially but then wedges. probably runs out of stack. */ /* 908 works initially but then wedges. probably runs out of stack. */
/* int logicdata[908]; */ /* byte logicdata[908]; */
unsigned int logicIndex = 0; unsigned int logicIndex = 0;
unsigned int triggerIndex = 0; unsigned int triggerIndex = 0;
unsigned int readCount = MAX_CAPTURE_SIZE; unsigned int readCount = MAX_CAPTURE_SIZE;
@@ -419,6 +418,7 @@ void captureMicro() {
for (i = 0 ; i < readCount; i++) { for (i = 0 ; i < readCount; i++) {
logicdata[i] = PINB; logicdata[i] = PINB;
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t"); __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
} }
PORTD = B00000000; /* debug timing measurement */ PORTD = B00000000; /* debug timing measurement */
} }
@@ -430,7 +430,8 @@ void captureMicro() {
PORTD = B10000000; /* debug timing measurement */ PORTD = B10000000; /* debug timing measurement */
for (i = 0 ; i < readCount; i++) { for (i = 0 ; i < readCount; i++) {
logicdata[i] = PINB; logicdata[i] = PINB;
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t"); __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t"); __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t"); __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t"); __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
@@ -449,7 +450,7 @@ void captureMicro() {
for (i = 0 ; i < readCount; i++) { for (i = 0 ; i < readCount; i++) {
logicdata[i] = PINB; logicdata[i] = PINB;
delayMicroseconds(delayTime - 1); delayMicroseconds(delayTime - 1);
__asm__("nop\n\t"); __asm__("nop\n\t""nop\n\t");
} }
PORTD = B00000000; /* debug timing measurement */ PORTD = B00000000; /* debug timing measurement */
} }
@@ -612,6 +613,7 @@ void triggerMicro() {
logicdata[logicIndex++] = PINB; logicdata[logicIndex++] = PINB;
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t"); __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t"); __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
} }
PORTD = B00000000; /* debug timing measurement */ PORTD = B00000000; /* debug timing measurement */
delayMicroseconds(100); delayMicroseconds(100);
@@ -646,7 +648,7 @@ void triggerMicro() {
* This needs adjustment so that we have the right spacing between the * This needs adjustment so that we have the right spacing between the
* before trigger samples and the after trigger samples. * before trigger samples and the after trigger samples.
*/ */
delayMicroseconds(delayTime - 3); delayMicroseconds(delayTime);
/* keep sampling for delayCount after trigger */ /* keep sampling for delayCount after trigger */
PORTD = B10000000; /* debug timing measurement */ PORTD = B10000000; /* debug timing measurement */
@@ -656,8 +658,9 @@ void triggerMicro() {
} }
logicdata[logicIndex++] = PINB; logicdata[logicIndex++] = PINB;
delayMicroseconds(delayTime - 3); delayMicroseconds(delayTime - 3);
__asm__("nop\n\t""nop\n\t""nop\n\t");
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t"); __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
__asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
__asm__("nop\n\t""nop\n\t""nop\n\t");
} }
PORTD = B00000000; /* debug timing measurement */ PORTD = B00000000; /* debug timing measurement */
delayMicroseconds(100); delayMicroseconds(100);
@@ -725,11 +728,11 @@ void get_metadata() {
Serial.print('0', BYTE); Serial.print('0', BYTE);
Serial.print(0x00, BYTE); Serial.print(0x00, BYTE);
/* sample memory (512) */ /* sample memory (1024) */
Serial.print(0x21, BYTE); Serial.print(0x21, BYTE);
Serial.print(0x00, BYTE); Serial.print(0x00, BYTE);
Serial.print(0x00, BYTE); Serial.print(0x00, BYTE);
Serial.print(0x02, BYTE); Serial.print(0x04, BYTE);
Serial.print(0x00, BYTE); Serial.print(0x00, BYTE);
/* sample rate (1MHz) */ /* sample rate (1MHz) */