Skip to content

Commit

Permalink
[calibration] display when input is staurating + split calibration in…
Browse files Browse the repository at this point in the history
… zero and fine
  • Loading branch information
mean committed Sep 11, 2019
1 parent 2384703 commit 927ebdf
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dso_adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct VoltageSettings
const char *name; /// name of the setting i.e 10 ms/div
DSOInputGain::InputGainRange gain;
float displayGain; /// multiply by this to get pixels from volt

int maxSwing;
};

/**
Expand Down
1 change: 1 addition & 0 deletions dso_capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef struct
float avg;
int trigger; // -1 = no trigger; else offset
int frequency; // 0 or -1= unknown
bool saturation;
}CaptureStats;

/**
Expand Down
26 changes: 15 additions & 11 deletions dso_capture_const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@
* Partially filled global gain array
* Remaining columns will be filled at runtime
*/
#define SAT_THRESHOLD 66 //5%
#define SWING(x) (2048-x+SAT_THRESHOLD)


VoltageSettings vSettings[NB_CAPTURE_VOLTAGE]= {
{"GND", DSOInputGain::MAX_VOLTAGE_GND, 24000.},
{"5mv", DSOInputGain::MAX_VOLTAGE_20MV, 4800.}, // "Digital" zoom
{"10mv", DSOInputGain::MAX_VOLTAGE_20MV, 2400.},
{"20mv", DSOInputGain::MAX_VOLTAGE_40MV , 1200.},
{"50mv", DSOInputGain::MAX_VOLTAGE_80MV, 480.},
{"100mv", DSOInputGain::MAX_VOLTAGE_200MV, 240.},
{"200mv", DSOInputGain::MAX_VOLTAGE_250MV, 120.},
{"GND", DSOInputGain::MAX_VOLTAGE_GND, 24000., SWING(2048) },
{"5mv", DSOInputGain::MAX_VOLTAGE_20MV, 4800., SWING(2048)}, // "Digital" zoom
{"10mv", DSOInputGain::MAX_VOLTAGE_20MV, 2400., SWING(2048)},
{"20mv", DSOInputGain::MAX_VOLTAGE_40MV , 1200., SWING(2048)},
{"50mv", DSOInputGain::MAX_VOLTAGE_80MV, 480., SWING(2048)},
{"100mv", DSOInputGain::MAX_VOLTAGE_200MV, 240., SWING(2048)},
{"200mv", DSOInputGain::MAX_VOLTAGE_250MV, 120., SWING(1100)}, // that one will saturate early
//{"500mv", DSOInputGain::MAX_VOLTAGE_800MV, 48.},
{"500mV", DSOInputGain::MAX_VOLTAGE_2V, 48.}, // "digital" zoom
{"1v", DSOInputGain::MAX_VOLTAGE_2V, 24.},
{"2v", DSOInputGain::MAX_VOLTAGE_4V, 12.},
{"5v", DSOInputGain::MAX_VOLTAGE_8V, 4.8}
{"500mV", DSOInputGain::MAX_VOLTAGE_2V, 48., SWING(2048)}, // "digital" zoom
{"1v", DSOInputGain::MAX_VOLTAGE_2V, 24., SWING(2048)},
{"2v", DSOInputGain::MAX_VOLTAGE_4V, 12., SWING(2048)},
{"5v", DSOInputGain::MAX_VOLTAGE_8V, 4.8, SWING(2048)}
};


Expand Down
16 changes: 10 additions & 6 deletions dso_capture_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
#include "DSO_config.h"
#include "dso_adc_gain.h"

extern VoltageSettings vSettings[NB_CAPTURE_VOLTAGE];

static int transformDma(int dc0_ac1,int16_t *in, float *out,int count, int expand,CaptureStats &stats, float triggerValue, DSOADC::TriggerMode mode)
{
static int transformDma(int dc0_ac1,int16_t *in, float *out,int count, int expand,CaptureStats &stats, float triggerValue, DSOADC::TriggerMode mode,int swing)
{
if(!count) return false;
stats.xmin=200;
stats.xmax=-200;
stats.saturation=false;
stats.avg=0;
int ocount=(count*4096)/expand;
if(ocount>240)
Expand All @@ -31,7 +30,10 @@ static int transformDma(int dc0_ac1,int16_t *in, float *out,int count, int expan
// First
float f;
{
f=(float)in[0];
int v=in[0];
if(v<swing) stats.saturation=true;
if(v>(4096-swing)) stats.saturation=true;
f=(float)v;
f-=offset;
f*=multiplier;
if(f>stats.xmax) stats.xmax=f;
Expand Down Expand Up @@ -202,7 +204,9 @@ bool DSOCapturePriv::taskletDmaCommon(const bool trigger)
expand,
set->stats,
triggerValueFloat,
adc->getTriggerMode());
adc->getTriggerMode(),
vSettings[DSOCapturePriv::currentVoltageRange].maxSwing
);

int fint=computeFrequency(fset.set1.samples,fset.set1.data);
if(fint)
Expand Down
15 changes: 10 additions & 5 deletions dso_capture_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
* @param mode
* @return
*/
static int transformTimer(int dc0_ac1,int16_t *in, float *out,int count, VoltageSettings *set,int expand,CaptureStats &stats)
static int transformTimer(int dc0_ac1,int16_t *in, float *out,int count, VoltageSettings *set,int expand,CaptureStats &stats,int swing)
{
if(!count) return false;
stats.xmin=200;
stats.xmax=-200;
stats.avg=0;
stats.saturation=false;
int ocount=(count*4096)/expand;
if(ocount>240)
{
Expand All @@ -41,8 +42,10 @@ static int transformTimer(int dc0_ac1,int16_t *in, float *out,int count, Voltage

for(int i=0;i<ocount;i++)
{

float f=(float)in[i];
int v=in[i];
if(v<swing) stats.saturation=true;
if(v>(4096-swing)) stats.saturation=true;
float f=(float)v;
f-=offset;
f*=multiplier;
if(f>stats.xmax) stats.xmax=f;
Expand Down Expand Up @@ -146,7 +149,8 @@ bool DSOCapturePriv::taskletTimer()
fset.set1.samples,
vSettings+currentVolt,
expand,
set->stats);
set->stats,
vSettings[DSOCapturePriv::currentVoltageRange].maxSwing);
if(fset.set2.samples)
{
CaptureStats otherStats;
Expand All @@ -157,7 +161,8 @@ bool DSOCapturePriv::taskletTimer()
fset.set2.samples,
vSettings+currentVolt,
expand,
otherStats);
otherStats,
vSettings[DSOCapturePriv::currentVoltageRange].maxSwing);
set->stats.avg= (set->stats.avg*set->samples+otherStats.avg*fset.set2.samples)/(set->samples+fset.set2.samples);
set->samples+=sample2;
if(otherStats.xmax>set->stats.xmax) set->stats.xmax=otherStats.xmax;
Expand Down
9 changes: 8 additions & 1 deletion dso_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,17 @@ void DSODisplay::drawStats(CaptureStats &stats)
#define AND_ONE_A(x,y) { tft->setCursor(DSO_INFO_START_COLUMN+2, DSO_HEIGHT_OFFSET+y*DSO_CHAR_HEIGHT); tft->myDrawString(x,DSO_INFO_MAX_WIDTH);}
#define AND_ONE_T(x,y) { tft->setCursor(DSO_INFO_START_COLUMN+4, DSO_HEIGHT_OFFSET+y*DSO_CHAR_HEIGHT); tft->myDrawString(x,DSO_INFO_MAX_WIDTH);}
#define AND_ONE_F(x,y) { tft->setCursor(DSO_INFO_START_COLUMN+4, DSO_HEIGHT_OFFSET+y*DSO_CHAR_HEIGHT);prettyPrint(x,DSO_INFO_MAX_WIDTH);}

if(stats.saturation)
{
tft->setTextColor(RED,BLACK);
}else
{
tft->setTextColor(GREEN,BLACK);
}
AND_ONE_F(stats.xmin,1);
AND_ONE_F(stats.xmax,3);
AND_ONE_F(stats.avg,5);
tft->setTextColor(GREEN,BLACK);
if(stats.frequency>0)
{
AND_ONE_T(fq2Text(stats.frequency),7);
Expand Down
25 changes: 20 additions & 5 deletions dso_eeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
extern uint16_t calibrationHash;

#define FINE_TUNE_OFFSET 64

#if 0
#define CHECK_READ(x) xAssert(x)
#else
#define CHECK_READ(x) if(!(x)) return false;
#endif
/**
*
* @return
Expand All @@ -26,10 +30,20 @@ bool DSOEeprom::read()
}

for(int i=0;i<DSO_NB_GAIN_RANGES;i++)
calibrationDC[i]=e2.read(2+i);
CHECK_READ(EEPROM_OK==e2.read(2+i,calibrationDC+i));
for(int i=0;i<DSO_NB_GAIN_RANGES;i++)
calibrationAC[i]=e2.read(2+i+16);
CHECK_READ(EEPROM_OK==e2.read(2+i+16,calibrationAC+i));
// 15+2+16=33 so far
return true;
}
/**
*
* @return
*/
bool DSOEeprom::readFineVoltage()
{
EEPROMClass e2;
e2.init();
for(int i=0;i<DSO_NB_GAIN_RANGES;i++)
voltageFineTune[i]=0;
int hasFineVoltage=e2.read(FINE_TUNE_OFFSET);
Expand All @@ -40,8 +54,9 @@ bool DSOEeprom::read()
{
float f;
uint16_t *adr=(uint16_t *)&f;
uint16_t high=e2.read(FINE_TUNE_OFFSET+2+i*2+0);
uint16_t low=e2.read(FINE_TUNE_OFFSET+2+i*2+1);
uint16_t high,low;
CHECK_READ(EEPROM_OK==e2.read(FINE_TUNE_OFFSET+2+i*2+0,&high)); // 64+4*2+ 72 or 75
CHECK_READ(EEPROM_OK==e2.read(FINE_TUNE_OFFSET+2+i*2+1,&low));

adr[0]=high;
adr[1]=low;
Expand Down
1 change: 1 addition & 0 deletions dso_eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class DSOEeprom
{
public:
static bool read();
static bool readFineVoltage();
static bool write();
static bool wipe();
};
2 changes: 1 addition & 1 deletion myCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void MainTask( void *a )
adc->setupADCs ();
DSOCalibrate::zeroCalibrate();
}

DSOEeprom::readFineVoltage();


//testAdc();
Expand Down

0 comments on commit 927ebdf

Please sign in to comment.