hantek-dso: dso2250: Support sample rates correctly.

Fast mode not done yet, only 125MHz allowed right now.
This commit is contained in:
Philipp Marek 2017-11-18 16:02:02 +01:00 committed by Uwe Hermann
parent 3b2b703177
commit 11e3319656
3 changed files with 61 additions and 37 deletions

View File

@ -130,6 +130,28 @@ static const uint64_t timebases[][2] = {
{ 400, 1000 },
};
static const uint64_t samplerates[] = {
SR_KHZ(20),
SR_KHZ(25),
SR_KHZ(50),
SR_KHZ(100),
SR_KHZ(200),
SR_KHZ(250),
SR_KHZ(500),
SR_MHZ(1),
SR_MHZ(2),
SR_MHZ(5),
SR_MHZ(10),
SR_MHZ(20),
SR_MHZ(25),
SR_MHZ(50),
SR_MHZ(100),
SR_MHZ(125),
/* fast mode not supported yet
SR_MHZ(200),
SR_MHZ(250), */
};
static const uint64_t vdivs[][2] = {
/* millivolts */
{ 10, 1000 },
@ -186,6 +208,7 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof)
devc->profile = prof;
devc->dev_state = IDLE;
devc->timebase = DEFAULT_TIMEBASE;
devc->samplerate = DEFAULT_SAMPLERATE;
devc->ch_enabled[0] = TRUE;
devc->ch_enabled[1] = TRUE;
devc->voltage[0] = DEFAULT_VOLTAGE;
@ -432,9 +455,7 @@ static int config_get(uint32_t key, GVariant **data,
timebases[devc->timebase][1]);
break;
case SR_CONF_SAMPLERATE:
*data = g_variant_new_uint64(
timebases[devc->timebase][1]/
timebases[devc->timebase][0]);
*data = g_variant_new_uint64(devc->samplerate);
break;
case SR_CONF_BUFFERSIZE:
*data = g_variant_new_uint64(devc->framesize);
@ -512,6 +533,13 @@ static int config_set(uint32_t key, GVariant *data,
return SR_ERR_ARG;
devc->timebase = idx;
break;
case SR_CONF_SAMPLERATE:
if ((idx = std_u64_idx(data, ARRAY_AND_SIZE(samplerates))) < 0)
return SR_ERR_ARG;
devc->samplerate = samplerates[idx];
if (dso_set_trigger_samplerate(sdi) != SR_OK)
return SR_ERR;
break;
case SR_CONF_TRIGGER_SOURCE:
if ((idx = std_str_idx(data, ARRAY_AND_SIZE(trigger_sources))) < 0)
return SR_ERR_ARG;
@ -565,6 +593,9 @@ static int config_list(uint32_t key, GVariant **data,
devc = sdi->priv;
*data = std_gvar_array_u64(devc->profile->buffersizes, NUM_BUFFER_SIZES);
break;
case SR_CONF_SAMPLERATE:
*data = std_gvar_samplerates(ARRAY_AND_SIZE(samplerates));
break;
case SR_CONF_TIMEBASE:
*data = std_gvar_tuple_array(ARRAY_AND_SIZE(timebases));
break;

View File

@ -303,41 +303,32 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi)
memset(cmdstring, 0, sizeof(cmdstring));
cmdstring[0] = CMD_2250_SET_SAMPLERATE;
/* Timebase fast */
sr_dbg("Time base index: %d.", devc->timebase);
sr_dbg("Sample rate: %u", devc->samplerate);
base = 100e6;
if (devc->timebase < TIME_40us) {
if (devc->framesize != FRAMESIZE_SMALL) {
sr_err("Timebase < 40us only supported with 10K buffer.");
return SR_ERR_ARG;
}
/* Fast mode on */
base = 200e6;
cmdstring[2] |= 1;
if (devc->samplerate > base) {
/* Timebase fast */
sr_err("Sample rate > 100MHz not yet supported.");
return SR_ERR_ARG;
}
/* Downsampling on */
cmdstring[2] |= 2;
/* Downsampler = 1comp((Base / Samplerate) - 2)
* Base == 100Msa resp. 200MSa
*
* Example for 500kSa/s:
* 100e6 / 500e3 => 200
* 200 - 2 => 198
* 1comp(198) => ff39 */
tmp = base * timebase_to_time(devc->timebase);
tmp = 200;
if (tmp < 0)
return SR_ERR_ARG;
tmp -= 2;
if (tmp < 0)
return SR_ERR_ARG;
tmp = ~tmp;
sr_dbg("sample rate value: 0x%x.", tmp & 0xffff);
cmdstring[4] = (tmp >> 0) & 0xff;
cmdstring[5] = (tmp >> 8) & 0xff;
tmp = base / devc->samplerate;
sr_dbg("sample rate value: %d.", devc->samplerate);
if (tmp) {
/* Downsampling on */
cmdstring[2] |= 2;
/* Downsampler = 1comp((Base / Samplerate) - 2)
* Base == 100Msa resp. 200MSa
*
* Example for 500kSa/s:
* 100e6 / 500e3 => 200
* 200 - 2 => 198
* 1comp(198) => ff39 */
tmp -= 2;
tmp = ~tmp;
sr_dbg("down sampler value: 0x%x.", tmp & 0xffff);
cmdstring[4] = (tmp >> 0) & 0xff;
cmdstring[5] = (tmp >> 8) & 0xff;
}
if (send_begin(sdi) != SR_OK)
return SR_ERR;
@ -375,7 +366,6 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi)
cmdstring[0] = CMD_2250_SET_TRIGGERPOS_AND_BUFFER;
/* TODO for big buffer */
/* TODO */
sr_dbg("Trigger position: %3.2f.", devc->triggerposition);
// tmp = 0x77fff + 0x8000 * devc->triggerposition;
// cmdstring[6] = tmp & 0xff;
@ -404,7 +394,7 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi)
return SR_OK;
}
static int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi)
int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
struct sr_usb_dev_inst *usb;

View File

@ -37,6 +37,7 @@
#define DEFAULT_VOLTAGE VDIV_500MV
#define DEFAULT_FRAMESIZE FRAMESIZE_SMALL
#define DEFAULT_TIMEBASE TIME_100us
#define DEFAULT_SAMPLERATE SR_KHZ(10)
#define DEFAULT_TRIGGER_SOURCE "CH1"
#define DEFAULT_COUPLING COUPLING_DC
#define DEFAULT_HORIZ_TRIGGERPOS 0.5
@ -187,6 +188,7 @@ struct dev_context {
int dev_state;
/* Oscilloscope settings. */
int samplerate;
int timebase;
gboolean ch_enabled[2];
int voltage[2];
@ -220,5 +222,6 @@ SR_PRIV int dso_get_capturestate(const struct sr_dev_inst *sdi,
SR_PRIV int dso_capture_start(const struct sr_dev_inst *sdi);
SR_PRIV int dso_get_channeldata(const struct sr_dev_inst *sdi,
libusb_transfer_cb_fn cb);
SR_PRIV int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi);
#endif