update CV curve DPV curve SWV curve
This commit is contained in:
+121
-21
@@ -506,16 +506,20 @@ static void SimpleBLEPeripheral_performPeriodicTask() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SWVCurve(){
|
||||
static uint16_t counter;
|
||||
static uint16_t outputV;
|
||||
static uint16_t Volt;
|
||||
static bool direction_up;
|
||||
float VoltValue;
|
||||
|
||||
// reset origin volt at the begin
|
||||
if (DACreset){
|
||||
Volt = VoltOrigin;
|
||||
outputV = VoltOrigin;
|
||||
if (VoltOrigin < VoltFinal) direction_up = true;
|
||||
else direction_up = false;
|
||||
counter = 1;
|
||||
DACreset = false;
|
||||
}
|
||||
@@ -526,6 +530,7 @@ static void SWVCurve(){
|
||||
// output a certain volt
|
||||
outputV = Volt;
|
||||
if ( outputV >= 0xffff ) DAC_outputV(0xffff); //check overflow
|
||||
else if ( outputV <= 0x0000) DAC_outputV(0x0000); //check underflow
|
||||
else DAC_outputV(outputV);
|
||||
|
||||
|
||||
@@ -538,20 +543,27 @@ static void SWVCurve(){
|
||||
|
||||
|
||||
// check if we reach the final volt
|
||||
if ( outputV >= VoltFinal ) {
|
||||
if (( outputV >= VoltFinal && direction_up) || (outputV <= VoltFinal && !direction_up)) {
|
||||
PeriodicEvent = false;
|
||||
DAC_outputV(0x0000);
|
||||
DACreset = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// prepare the next output volt
|
||||
if( counter == PulseWidth) Volt = Volt + Amplitude;
|
||||
else if( counter == 2*PulseWidth ) Volt = Volt - (Amplitude - Step);
|
||||
else Volt = Volt;
|
||||
|
||||
if (direction_up) {
|
||||
if( counter == PulseWidth) Volt = Volt + Amplitude;
|
||||
else if( counter == 2*PulseWidth ) Volt = Volt - (Amplitude - Step);
|
||||
else Volt = Volt;
|
||||
}
|
||||
else {
|
||||
if( counter == PulseWidth) Volt = Volt - Amplitude;
|
||||
else if( counter == 2*PulseWidth ) Volt = Volt + (Amplitude - Step);
|
||||
else Volt = Volt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* working DPV curve
|
||||
static void DPVCurve(){
|
||||
static uint8_t ramp0;
|
||||
static uint8_t ramp1;
|
||||
@@ -582,6 +594,71 @@ static void DPVCurve(){
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
static void DPVCurve(){
|
||||
static uint8_t counter;
|
||||
static uint16_t Volt1;
|
||||
static uint16_t Volt2;
|
||||
static uint16_t outputV;
|
||||
static bool direction_up;
|
||||
float VoltValue;
|
||||
|
||||
// reset origin volt at the begin
|
||||
if (DACreset){
|
||||
|
||||
if ( VoltOrigin < VoltFinal ) direction_up = true;
|
||||
else direction_up = false;
|
||||
|
||||
Volt1 = VoltOrigin;
|
||||
if (direction_up) Volt2 = VoltOrigin + (uint16_t)(Amplitude);
|
||||
else Volt2 = VoltOrigin - (uint16_t)(Amplitude);
|
||||
|
||||
counter = 1;
|
||||
DACreset = false;
|
||||
}
|
||||
|
||||
if(counter == PulsePeriod) counter = 1;
|
||||
else counter ++;
|
||||
|
||||
// output a certain volt
|
||||
if( counter <= (PulsePeriod - PulseWidth)) outputV = Volt1;
|
||||
else outputV = Volt2;
|
||||
|
||||
DAC_outputV(outputV);
|
||||
|
||||
// record the output voltage
|
||||
int32_t Vout = 0;
|
||||
int16_t decode = outputV;
|
||||
VoltValue = decode * (-2.9780379) + 5920.324416;
|
||||
Vout = (int32_t) (VoltValue / 1);
|
||||
// VoltValue = (ramp1*16 + ramp0/16) * 3.05;
|
||||
|
||||
|
||||
// check if we reach the final volt
|
||||
if ( (( outputV >= VoltFinal) && direction_up ) || (( outputV <= VoltFinal) && !direction_up)) {
|
||||
PeriodicEvent = false;
|
||||
DACreset = true;
|
||||
return;
|
||||
}
|
||||
|
||||
//check overflow/underflow and prepare for next output
|
||||
if (direction_up) {
|
||||
if ( Volt1 + (uint16_t)(Step) < Volt1 ) Volt1 = 0xff;
|
||||
else Volt1 = Volt1 + (uint16_t)(Step);
|
||||
if ( Volt2 + (uint16_t)(Step) < Volt2 ) Volt2 = 0xff;
|
||||
else Volt2 = Volt2 + (uint16_t)(Step);
|
||||
}
|
||||
else {
|
||||
if ( Volt1 - (uint16_t)(Step) > Volt1 ) Volt1 = 0x00;
|
||||
else Volt1 = Volt1 - (uint16_t)(Step);
|
||||
if ( Volt2 - (uint16_t)(Step) > Volt2) Volt2 = 0x00;
|
||||
else Volt2 = Volt2 - (uint16_t)(Step);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -592,13 +669,20 @@ static void CVCurve(){
|
||||
static uint16_t outputV;
|
||||
static uint8_t counter;
|
||||
static bool direction_up;
|
||||
static bool current_direction_up;
|
||||
float VoltValue;
|
||||
|
||||
// reset origin volt at the begin
|
||||
if (DACreset){
|
||||
outputV = VoltOrigin;
|
||||
if (VoltFinal > VoltOrigin ) direction_up = true;
|
||||
else direction_up = false;
|
||||
if (VoltFinal > VoltOrigin ) {
|
||||
direction_up = true;
|
||||
current_direction_up = true;
|
||||
}
|
||||
else {
|
||||
direction_up = false;
|
||||
current_direction_up = false;
|
||||
}
|
||||
ramp0 = (uint8_t) (VoltOrigin & 0x00FF); //right byte
|
||||
ramp1 = (uint8_t) ((VoltOrigin>>8) & 0x00FF); //left byte
|
||||
DACreset = false;
|
||||
@@ -614,23 +698,39 @@ static void CVCurve(){
|
||||
Vout = (int32_t) (VoltValue / 1);
|
||||
// VoltValue = (ramp1*16 + ramp0/16) * 3.05;
|
||||
|
||||
|
||||
if (outputV >= VoltFinal) {
|
||||
direction_up = false; //problem occurs when origin == 0000 final == ffff!!!!!!
|
||||
if (direction_up) {
|
||||
if (outputV >= VoltFinal) {
|
||||
current_direction_up = false; //problem occurs when origin == 0000 final == ffff!!!!!!
|
||||
}
|
||||
else if (outputV <= VoltOrigin) {
|
||||
current_direction_up = true;
|
||||
if (INSTRUCTION.CycleNumber == 0) {
|
||||
PeriodicEvent = false; //periodic event end
|
||||
DACreset = true;
|
||||
return;
|
||||
}
|
||||
INSTRUCTION.CycleNumber--;
|
||||
}
|
||||
}
|
||||
else if (outputV <= VoltOrigin) {
|
||||
direction_up = true;
|
||||
if (INSTRUCTION.CycleNumber == 0) {
|
||||
PeriodicEvent = false; //periodic event end
|
||||
DAC_outputV(0x0000);
|
||||
DACreset = true;
|
||||
return;
|
||||
}
|
||||
INSTRUCTION.CycleNumber--;
|
||||
else {
|
||||
if (outputV <= VoltFinal) {
|
||||
current_direction_up = true; //problem occurs when origin == 0000 final == ffff!!!!!!
|
||||
}
|
||||
else if (outputV >= VoltOrigin) {
|
||||
current_direction_up = false;
|
||||
if (INSTRUCTION.CycleNumber == 0) {
|
||||
PeriodicEvent = false; //periodic event end
|
||||
DACreset = true;
|
||||
return;
|
||||
}
|
||||
INSTRUCTION.CycleNumber--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(direction_up) outputV = outputV + (uint16_t)(Step);
|
||||
if(current_direction_up) outputV = outputV + (uint16_t)(Step);
|
||||
else outputV = outputV - (uint16_t)(Step);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user