Skip to content

Commit

Permalink
- в continuous mode если не сильно изменилось значение, не пересчитыв…
Browse files Browse the repository at this point in the history
…аем заново результат
  • Loading branch information
balmerdx committed May 1, 2014
1 parent dcfb89a commit 30ba37d
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 34 deletions.
5 changes: 4 additions & 1 deletion 3code/inc/calc_rc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ typedef complex float complexf;
#include "adc.h"
#include "process_measure.h"


void OnCalculate();

extern complexf lastZx;
extern bool lastZxFilled;


#endif//_CALC_RC_H_
13 changes: 12 additions & 1 deletion 3code/inc/lcd_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@

void LcdRepaint();

void printInt(int32_t value, uint8_t font);
void printInt(int32_t value, uint8_t font);

extern int printD;

extern float Rre;
extern float Rim;

extern bool isSerial;
extern bool valueIsC;
extern bool calculatedValues;
extern float valueL;
extern float valueC;
13 changes: 7 additions & 6 deletions 3code/src/calc_rc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@
#include "corrector.h"
#include "dac.h"

extern float Rre;
extern float Rim;
extern bool isSerial;
extern bool valueIsC;
extern float valueL;
extern float valueC;
complexf lastZx = 0;
bool lastZxFilled = false;

void OnCalculate()
{
Expand All @@ -35,6 +31,11 @@ void OnCalculate()
zI *= toVolts/gain_I;

complexf Zx = (zV/zI)*resistor;

lastZxFilled = true;
calculatedValues = true;
lastZx = Zx;

Zx = Corrector(Zx);

Rre = creal(Zx);
Expand Down
4 changes: 2 additions & 2 deletions 3code/src/corrector.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ void CorrectorLoadData()

if(cfound==NULL)
{
printD = 44;
//printD = 44;
coeff.period = 0;
return;
}

coeff = *cfound;
printD = 23;
//printD = 23;
}
35 changes: 20 additions & 15 deletions 3code/src/lcd_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ float Rim = 0;

bool isSerial = true;
bool valueIsC = true;
bool calculatedValues = false;
float valueL = 0;
float valueC = 0;

Expand Down Expand Up @@ -55,27 +56,31 @@ void LcdRepaint()
LcdGotoXYFont(8, 1);
LcdStr(FONT_1X, isSerial?"SER":"PAR");

printRX2(Rre, 2);
LcdGotoXYFont(12,2);
LcdStr(FONT_1X, "Rre");

if(printRim)
if(calculatedValues)
{
printRX2(Rim, 4);
LcdGotoXYFont(12,4);
LcdStr(FONT_1X, "Rim");
} else
{
if(valueIsC)
printRX2(Rre, 2);
LcdGotoXYFont(12,2);
LcdStr(FONT_1X, "Rre");

if(printRim)
{
printCX2(valueC, 4);
printRX2(Rim, 4);
LcdGotoXYFont(12,4);
LcdStr(FONT_1X, "C");
LcdStr(FONT_1X, "Rim");
} else
{
printLX2(valueL, 4);
LcdGotoXYFont(12,4);
LcdStr(FONT_1X, "L");
if(valueIsC)
{
printCX2(valueC, 4);
LcdGotoXYFont(12,4);
LcdStr(FONT_1X, "C");
} else
{
printLX2(valueL, 4);
LcdGotoXYFont(12,4);
LcdStr(FONT_1X, "L");
}
}
}

Expand Down
72 changes: 64 additions & 8 deletions 3code/src/process_measure.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ static STATES state = STATE_NOP;
#define gainValuesCount 8
uint8_t gainValues[gainValuesCount] = {1,2,4,5,8,10,16,32};


uint8_t resistorIdx;
uint8_t gainVoltageIdx;
uint8_t gainCurrentIdx;
Expand All @@ -36,6 +35,9 @@ uint8_t computeXCount;
uint8_t computeXIterator;
uint8_t predefinedResistorIdx;

bool bContinuousMode = false;
static bool debugRepaint = false;

extern int printD;

static AdcSummaryData sum_data;
Expand Down Expand Up @@ -81,6 +83,7 @@ float getResistorOm()

void ProcessStartComputeX(uint8_t count, uint8_t predefinedResistorIdx_)
{
//calculatedValues = false;
if(count==0)
count = 1;
computeXCount = count;
Expand Down Expand Up @@ -123,6 +126,11 @@ void ProcessData()

void OnStartGainAuto()
{
if(!debugRepaint)
{
LcdRepaint();
}

resistorIdx = 0;
gainVoltageIdx = 0;
gainCurrentIdx = 0;
Expand All @@ -143,15 +151,17 @@ void OnStartGainAuto()
}


printD = 123;
LcdRepaint();
if(debugRepaint)
{
printD = 123;
LcdRepaint();
}
}

void OnResistorIndex()
{
AdcSummaryChannel* asc = &g_data.ch_i;
int di = asc->adc_max - asc->adc_min;
printD = di;
if(di*10>goodDelta || resistorIdx>=3)
{
OnStartGainIndex(false);
Expand All @@ -162,7 +172,11 @@ void OnResistorIndex()
SetResistor(resistorIdx);
}

LcdRepaint();
if(debugRepaint)
{
printD = di;
LcdRepaint();
}
}

void OnStartGainIndex(bool wait)
Expand All @@ -184,7 +198,8 @@ void OnGainIndex()
int vmax = g_data.ch_v.adc_max;
int imin = g_data.ch_i.adc_min;
int imax = g_data.ch_i.adc_max;
printD = gainIndexIterator+100;
if(debugRepaint)
printD = gainIndexIterator+100;

if(!gainIndexStopV && vmax<goodMax && vmin>goodMin)
{
Expand Down Expand Up @@ -219,11 +234,13 @@ void OnGainIndex()
state = STATE_GAIN_INDEX_WAIT;
}

LcdRepaint();
if(debugRepaint)
LcdRepaint();
}

void OnMeasureStart()
{
LcdRepaint();
state = STATE_MEASURE_WAIT;
computeXIterator = 0;
}
Expand Down Expand Up @@ -264,10 +281,49 @@ void OnMeasure()

g_data = sum_data;

bool oldLastZxFilled = lastZxFilled;
complexf oldLastZx = lastZx;

OnCalculate();

LcdRepaint();

if(bContinuousMode)
{
bool startFast = false;
if(oldLastZxFilled)
{
float d = cabs(oldLastZx-lastZx)/cabs(lastZx);
if(d>1)
d = 1;
printD = d*99;
if(d<5e-2f)
{
int vmin = g_data.ch_v.adc_min;
int vmax = g_data.ch_v.adc_max;
int imin = g_data.ch_i.adc_min;
int imax = g_data.ch_i.adc_max;

printD += 1000;

if(vmax<goodMax && vmin>goodMin && imax<goodMax && imin>goodMin)
{
//Все хорошо, мтожно не пересчитывать коэффициэнты и не переставлять резистор
startFast = true;
}
}
}

if(startFast)
OnMeasureStart();
else
ProcessStartComputeX(computeXCount, predefinedResistorIdx);
}
else
{
state = STATE_NOP;
}

state = STATE_NOP;
}

void SendRVI()
Expand Down
4 changes: 4 additions & 0 deletions 3code/src/voltage.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "lcd_interface.h"

extern bool isSerial;
extern bool bContinuousMode;

void GetClockFrequency(void)
{
Expand Down Expand Up @@ -122,6 +123,9 @@ void USBCommandReceive(uint8_t* commandBuffer, uint16_t commandSize)
isSerial = commandBuffer[1]?true:false;
LcdRepaint();
break;
case 23://COMMAND_SET_CONTINUOUS_MODE
bContinuousMode = commandBuffer[1]?true:false;
break;
}

USBSend();
Expand Down
14 changes: 13 additions & 1 deletion script/usb_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
COMMAND_CORRECTOR_FLASH_CLEAR = 20
COMMAND_FLASH_CURRENT_DATA = 21
COMMAND_SET_SERIAL = 22
COMMAND_SET_CONTINUOUS_MODE = 23

LOW_PASS_PERIOD = 24000 #3 KHz

Expand Down Expand Up @@ -438,6 +439,16 @@ def setSerial(ser=True):
data = dread()
assert(data[0]==COMMAND_SET_SERIAL)

def setContinuousMode(m=True):
if m:
m = 1
else:
m = 0

dwrite([COMMAND_SET_CONTINUOUS_MODE, m])
data = dread()
assert(data[0]==COMMAND_SET_CONTINUOUS_MODE)


def adcRequestLastCompute():
dwrite([COMMAND_REQUEST_DATA]);
Expand Down Expand Up @@ -878,7 +889,7 @@ def main():

if True:
#period = periodByFreq(10)
period = HARDWARE_CORRECTOR_PERIODS[3]
period = HARDWARE_CORRECTOR_PERIODS[0]
#period = 384
gain_corrector = jplot.GainCorrector()
corrector = jplot.Corrector(gain_corrector)
Expand All @@ -887,6 +898,7 @@ def main():

#setCorrector(corrector, period)

setContinuousMode(True)
setSerial(False)
adcSynchro(period)

Expand Down

0 comments on commit 30ba37d

Please sign in to comment.