Hi

I have a problem with the values of analogRead, in a arduinoDue

I read 2 times the analog value of pin 6 but i get 2 different values, see code blow.

Debug values:
in row 372 curVal = 192
in row 385 curVal = 0

Any ideas?

``````float getCur(int _pinCTX)
{
int curVal;
boolean loop = true;

int pin = _pinCTX;

int timeperiod = 10;
int timeout = 80;
unsigned long start = 0;
int numberSamples = 0;
int sumI = 0;
int Id = 0;
float I = 0;

//Richtigen Momment appassen
start = millis();

while(loop == true)
{
//Sicherstellung nicht endlos in loop
if(millis()-start > timeout){
loop = false;
}

if((curVal < 50)){		//1. check ob Anfang oder Ende vom Sinus 2. Überhaupt gefunden
delayMicroseconds(10);

loop = false;		//check ob Anfang
}
}
}
``````

Hi, what have you got connected to pin 6 ? And what are you trying to accomplish.
A circuit diagram would help too.
Also use AUTO FORMAT on your sketch and re-post it thanks.
Tom.....

That's nice. And what, pray, might be connected to analog pin 6...?

i will measure the current, current is between 0-300Amps
it is not the whole code of the method, just the begin

circuit in attach

i measure on CT1 0.6V, CT1 goes to analogpin6 of the arduino.
On pin6 its a voltage signal
voltage of L1 is max 3,3, comes form OPamp

sokolov

Sorry, please show complete circuit, CT to opamp to arduino.
Are you measuring AC current and are you rectifying it to DC for the analog input.
You diagram does not make any sense with just labels, include components that you are using, you must have a diagram to work from to get this far.

Tom...

The value that you are measuring, changed between the first and the second time that you measured it