Hello people!
with an adjustment to DAC (MCP4921) I have the following problem and hope for your help. sorry for my bad english!!!
The output is applied from a trans-impedance amplifier to a input of a differential amplifier. The second input of differential amplifier is a variable voltage -> by the DAC to my signal (see picture) is approximately equal to hold a minimum level because my generated signal varies physiologically.
I have to continually read and evaluate my minimum & maximum values from my signal graph.
As for my minimum to the DAC up or down depending on the fluctuations regulate equal to the minimum (eg, 0-10mV) to hold. (Sample and Hold)
If my DAC dat first time is set, it will keep the value at fluctuations it should increase from the previous value / minimize and not start again from zero.( because zu long)
Unfortunately, only inkremtiert to maimalen DAC value (4096) and not my desired minimum, regulate not go down
Someone an idea? Thank you very much in advance
my code:
#include <AH_MCP4921.h>
#include <SPI.h>int sensorValue = 0; // value
const int sensorPin = A0;
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value
int sensorM = 0; // minimum sensor value
int sensorMx = 0; // maximum sensor valueint i = 0; // zum DAC einstellen
AH_MCP4921 AnalogOutput1(51,52,53);// für SPI
void setup()
{
Serial.begin(9600);
AnalogOutput1.setValue(0); //DAC first zero
while ( sensorValue>=0) { // read value
sensorValue = analogRead(sensorPin);
if (sensorValue < sensorMin) {
sensorM = sensorValue; //find min value
}
if (sensorValue > sensorMax){ // find maximum value
sensorMx = sensorValue;
if(sensorValue>0) {
Serial.print("low = ");
Serial.println(sensorM); }if(sensorMx>0) {
Serial.print("high= ");
Serial.println(sensorMx); }
}
if (sensorM<10)
{i++; // DAC inkrement
AnalogOutput1.setValue(i);
}// DAC hold
if (sensorM<10){
i--; //DAC from prevoius go down
AnalogOutput1.setValue(i); //DAC hold
}}
}void loop()
{}