]> sigrok.org Git - libsigrok.git/commitdiff
hantek-dso: proper protocol implementation of trigger/samplerate setting
authorBert Vermeulen <redacted>
Mon, 14 May 2012 00:33:37 +0000 (02:33 +0200)
committerBert Vermeulen <redacted>
Wed, 30 May 2012 21:56:12 +0000 (23:56 +0200)
hardware/hantek-dso/dso.c
hardware/hantek-dso/dso.h

index ab6d09ecb8a8332fb7b464a819f146284322a507..552ee17b050d8ed42a582f0ea8b5296df9b0b639 100644 (file)
@@ -221,8 +221,6 @@ SR_PRIV int dso_set_trigger_samplerate(struct context *ctx)
 {
        int ret, tmp;
        uint8_t cmdstring[12];
-       uint8_t timebasefast_small[] = {1, 2, 3, 4};
-       uint8_t timebasefast_large[] = {0, 0, 2, 3};
        uint16_t timebase_small[] = { 0xffff, 0xfffc, 0xfff7, 0xffe8, 0xffce,
                        0xff9c, 0xff07, 0xfe0d, 0xfc19, 0xf63d, 0xec79, 0xd8f1 };
        uint16_t timebase_large[] = { 0xffff, 0x0000, 0xfffc, 0xfff7, 0xffe8,
@@ -235,33 +233,53 @@ SR_PRIV int dso_set_trigger_samplerate(struct context *ctx)
        cmdstring[0] = CMD_SET_TRIGGER_SAMPLERATE;
 
        /* Trigger source */
-       cmdstring[2] = (ctx->triggersource & 0x03) << 6;
+       cmdstring[2] = (ctx->triggersource & 0x03);
 
        /* Frame size */
-       cmdstring[2] |= (ctx->framesize == FRAMESIZE_SMALL ? 0x01 : 0x02) << 3;
-
-       /* Timebase fast (no idea what this means) */
-       if (ctx->timebase < TIME_20us)
-               tmp = 0;
-       else if (ctx->timebase > TIME_200us)
-               tmp = 4;
-       else {
-               if (ctx->framesize == FRAMESIZE_SMALL)
-                       tmp = timebasefast_small[ctx->timebase - 1];
-               else
-                       tmp = timebasefast_large[ctx->timebase - 1];
+       cmdstring[2] |= (ctx->framesize == FRAMESIZE_SMALL ? 0x01 : 0x02) << 2;
+
+       /* Timebase fast */
+       switch (ctx->framesize) {
+       case FRAMESIZE_SMALL:
+               if (ctx->timebase < TIME_20us)
+                       tmp = 0;
+               else if (ctx->timebase == TIME_20us)
+                       tmp = 1;
+               else if (ctx->timebase == TIME_40us)
+                       tmp = 2;
+               else if (ctx->timebase == TIME_100us)
+                       tmp = 3;
+               else if (ctx->timebase >= TIME_200us)
+                       tmp = 4;
+               break;
+       case FRAMESIZE_LARGE:
+               if (ctx->timebase < TIME_40us) {
+                       sr_err("hantek-dso: timebase < 40us only supported with 10K buffer");
+                       return SR_ERR_ARG;
+               }
+               else if (ctx->timebase == TIME_40us)
+                       tmp = 0;
+               else if (ctx->timebase == TIME_100us)
+                       tmp = 2;
+               else if (ctx->timebase == TIME_200us)
+                       tmp = 3;
+               else if (ctx->timebase >= TIME_400us)
+                       tmp = 4;
+               break;
        }
-       cmdstring[2] |= tmp & 0x07;
-cmdstring[2] = 0x45;
-       /* Enabled channels */
+       cmdstring[2] |= (tmp & 0x07) << 5;
+
+       /* Enabled channels: 00=CH1 01=CH2 10=both */
        tmp = (((ctx->ch2_enabled ? 1 : 0) << 1) + (ctx->ch1_enabled ? 1 : 0)) - 1;
        cmdstring[3] = tmp;
 
-       /* TODO: Fast rates channel */
-       cmdstring[3] |= 0 << 5;
+       /* Fast rates channel */
+       /* TODO: is this right? */
+       tmp = ctx->timebase < TIME_10us ? 1 : 0;
+       cmdstring[3] |= tmp << 2;
 
-       /* Trigger slope */
-       cmdstring[3] |= (ctx->triggerslope ? 1 : 0) << 4;
+       /* Trigger slope: 0=positive 1=negative */
+       cmdstring[3] |= (ctx->triggerslope == SLOPE_NEGATIVE ? 1 : 0) << 3;
 
        /* Timebase */
        if (ctx->timebase < TIME_100us)
@@ -274,15 +292,13 @@ cmdstring[2] = 0x45;
                else
                        tmp = timebase_large[ctx->timebase - 3];
        }
-tmp = 0xebff;
+       cmdstring[4] = tmp & 0xff;
+       cmdstring[5] = (tmp >> 8) & 0xff;
+
+       /* Horizontal trigger position */
+       tmp = 0x77fff + 0x8000 * ctx->triggerposition;
        cmdstring[6] = tmp & 0xff;
        cmdstring[7] = (tmp >> 8) & 0xff;
-
-       /* Trigger position (time) */
-       tmp = 0x77660 + ctx->triggerposition;
-tmp = 0x7006f;
-       cmdstring[8] = tmp & 0xff;
-       cmdstring[9] = (tmp >> 8) & 0xff;
        cmdstring[10] = (tmp >> 16) & 0xff;
 
        if (send_begin(ctx) != SR_OK)
@@ -388,7 +404,7 @@ relays[0] = 0x01;
        if (ctx->coupling_ch2 != COUPLING_AC)
                relays[6] = ~relays[6];
 
-       if (ctx->triggersource == TRIGGER_EXT || ctx->triggersource == TRIGGER_EXT10)
+       if (ctx->triggersource == TRIGGER_EXT)
                relays[7] = ~relays[7];
 
        if ((ret = libusb_control_transfer(ctx->usb->devhdl,
index 1a0c69deb4326ee2884b704e13cebbc2b4f528a0..a0f5c5a1efdf70968e35c407204dc0d6b7044f88 100644 (file)
 
 #define DEFAULT_VOLTAGE            VOLTAGE_2V
 #define DEFAULT_FRAMESIZE          FRAMESIZE_SMALL
-#define DEFAULT_TIMEBASE           TIME_1ms
+#define DEFAULT_TIMEBASE           TIME_400us
 #define DEFAULT_TRIGGER_SOURCE     TRIGGER_CH1
 #define DEFAULT_COUPLING           COUPLING_AC
-/* Halfway between min and max = 0V */
-#define DEFAULT_HORIZ_TRIGGERPOS   0x1400
-
+#define DEFAULT_HORIZ_TRIGGERPOS   0.5
 #define DEFAULT_VERT_OFFSET        0.5
 #define DEFAULT_VERT_TRIGGERPOS    0.0
 
@@ -117,9 +115,7 @@ enum trigger_slopes {
 enum trigger_sources {
        TRIGGER_CH2 = 0,
        TRIGGER_CH1,
-       TRIGGER_ALT,
        TRIGGER_EXT,
-       TRIGGER_EXT10
 };
 
 enum capturestates {
@@ -193,7 +189,7 @@ struct context {
        gboolean filter_trigger;
        int triggerslope;
        int triggersource;
-       int triggerposition;
+       float triggerposition;
        int triggermode;
 };