From f51d0bbb963492a9337a2159a0d74315ae2d58f9 Mon Sep 17 00:00:00 2001 From: Andrew Gillham Date: Mon, 27 Feb 2012 14:36:09 -0800 Subject: [PATCH] Improve pre-trigger sampling on below 500kHz sample rates. The sample loop was not padded properly in the loop waiting for the trigger to fire. As a result it was sampling at a much higher rate than the post trigger sample rate. I've added some delays and padded it out a bit, it needs further measurement, but is usable now. --- logic_analyzer.ino | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/logic_analyzer.ino b/logic_analyzer.ino index 1133998..a887880 100644 --- a/logic_analyzer.ino +++ b/logic_analyzer.ino @@ -25,7 +25,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: logic_analyzer.pde,v 1.17 2011-08-04 02:31:01 gillham Exp $ + * $Id: logic_analyzer.ino,v 1.21 2012/02/27 20:19:44 gillham Exp $ * */ @@ -152,14 +152,14 @@ void debugdump(void); * ATmega2560: 7168 (or lower) */ #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) - #define DEBUG_CAPTURE_SIZE 7168 - #define CAPTURE_SIZE 7168 +#define DEBUG_CAPTURE_SIZE 7168 +#define CAPTURE_SIZE 7168 #elif defined(__AVR_ATmega328P__) - #define DEBUG_CAPTURE_SIZE 1024 - #define CAPTURE_SIZE 1024 +#define DEBUG_CAPTURE_SIZE 1024 +#define CAPTURE_SIZE 1024 #else - #define DEBUG_CAPTURE_SIZE 532 - #define CAPTURE_SIZE 532 +#define DEBUG_CAPTURE_SIZE 532 +#define CAPTURE_SIZE 532 #endif #define DEBUG @@ -682,6 +682,12 @@ void triggerMicro() { if (logicIndex >= readCount) { logicIndex = 0; } + else { + /* pad the same number of cycles as the above assignment (needs verification) */ + __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t"); + } + delayMicroseconds(delayTime - 3); + __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t"); /* PORTD = B10000000; */ } PORTD = B00000000; /* debug timing measurement */ @@ -693,7 +699,10 @@ void triggerMicro() { * This needs adjustment so that we have the right spacing between the * before trigger samples and the after trigger samples. */ - delayMicroseconds(delayTime); + delayMicroseconds(delayTime - 2); + __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"); /* keep sampling for delayCount after trigger */ PORTD = B10000000; /* debug timing measurement */ @@ -884,3 +893,6 @@ void debugdump() { #endif /* DEBUG */ + + +