If the timebase is too fast to read the actual trigger status sleep
for nearly a sweep time instead to minimize data frames containing
duplicate data.
---
 hardware/rigol-ds/protocol.c |   30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/hardware/rigol-ds/protocol.c b/hardware/rigol-ds/protocol.c
index 5ba110f..3f372d6 100644
--- a/hardware/rigol-ds/protocol.c
+++ b/hardware/rigol-ds/protocol.c
@@ -101,12 +101,32 @@ static int rigol_ds2xx2_trigger_wait(const struct 
sr_dev_inst *sdi)
        char buf[20];
        struct dev_context *devc;
        time_t start;
+        long s;
 
        if (!(devc = sdi->priv))
                return SR_ERR;
 
        start = time(NULL);
 
+        /* 
+         * If timebase < 50 msecs/DIV just sleep about one sweep time except
+         * for really fast sweeps.
+         */
+       if (devc->timebase < 0.0499)
+       {
+                if (devc->timebase > 1.99e-6) {
+                        /*
+                         * Timebase * 14 hor. divs * 100(%) * 1e6(usecs) / 85
+                         * -> 85 percent of sweep time
+                         */
+                        s = (devc->timebase * 14e8) / 85L;
+                        sr_dbg("Sleeping for %ld usecs", s);
+                        g_usleep(s);
+                }
+               devc->trigger_wait_status = 0;
+                return SR_OK;
+       }
+
        /*
         * Trigger status may return:
         * "TD"   - triggered
@@ -158,7 +178,8 @@ static int rigol_ds2xx2_trigger_wait(const struct 
sr_dev_inst *sdi)
  *
  * The workaround is to only wait for the trigger when the timebase is slow
  * enough. Of course this means that for faster timebases sample data can be
- * returned multiple times.
+ * returned multiple times, this effect is mitigated somewhat by sleeping
+ * for about one sweep time.
  */
 
 SR_PRIV int rigol_ds2xx2_acquisition_start(const struct sr_dev_inst *sdi,
@@ -185,15 +206,14 @@ SR_PRIV int rigol_ds2xx2_acquisition_start(const struct 
sr_dev_inst *sdi,
        devc->num_frame_bytes = 0;
        devc->num_block_bytes = 0;
 
-       /* only wait for trigger if timbase 50 msecs/DIV or slower */
-       if (wait_for_trigger && devc->timebase > 0.0499)
+       if (wait_for_trigger)
        {
                devc->trigger_wait_status = 1;
        } else {
                devc->trigger_wait_status = 0;
-       }
+        }
 
-       return SR_OK;
+        return SR_OK;
 }
 
 static int rigol_ds2xx2_read_header(struct sr_serial_dev_inst *serial)
-- 
1.7.10.4


------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing 
conversations that shape the rapidly evolving mobile landscape. Sign up now. 
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to