hi robert another question
i try use code that you told me
i got this code but i cant understand what is this mean
i want sine wave of currents and voltage but
in that code i dont know what this means
-------------------------------------
Sketch ID: RawSamplesTool_2chan.ino
>>free RAM = 7077
millis() now = 5040
recordingMayStartAt 10040
4
4
4
4
3
3
3
3
3
3
3
2
2
2
2
2
2
1
1
1
1
1
1
1
0
0
0
0
0
0
No of cycles recorded = 1
cycleCount 1502, samplesRecorded 13
| 1v. |
| 1v. |
| 1v. |
| 1v. |
| 1 v. |
| 1 v. |
| 1 v. |
min_V1 505, max_V1 506
min_I1 482, max_I1 497
Raw data from stored cycle: <Vsample>, <I1sample>, <I2sample>[cr]
13, <<< No of sample sets
506, 497, 505, 496, 505, 494, 505, 493, 505, 492, 505, 491, 505, 489, 505, 486, 505, 484, 505, 483, 505, 483, 505, 482, 505, 482
i used this code
#define POSITIVE 1
#define NEGATIVE 0
#define CYCLES_PER_SECOND 50
byte sensorPin_V1 = 15;
//byte sensorPin_V2 = 14;
//byte sensorPin_V3 = 13;
byte sensorPin_I1 = 1;
//byte sensorPin_I2 = 2;
//byte sensorPin_I3 = 3;
long cycleCount = 0;
int samplesRecorded = 0;
byte polarityNow;
boolean beyondStartUpPhase = false;
int lastSample_V1; // stored value from the previous loop (HP filter is for voltage samples only)
float lastFiltered_V1; // voltage values after HP-filtering to remove the DC offset
byte polarityOfLastSample_V1; // for zero-crossing detection
boolean recordingNow;
boolean recordingComplete;
byte cycleNumberBeingRecorded;
byte noOfCyclesToBeRecorded;
unsigned long recordingMayStartAt;
boolean firstLoop = true;
int settlingDelay = 5; // <<--- settling time (seconds) for HPF
char blankLine[82];
char newLine[82];
int storedSample_V1[100];
int storedSample_I1[100];
//int storedSample_I2[100];
void setup()
{
delay(5000); // allow time for the Serial Window to be opened
Serial.begin(9600);
Serial.println();
Serial.println("-------------------------------------");
Serial.println("Sketch ID: RawSamplesTool_2chan.ino");
Serial.println();
// initialise each character of the display line
blankLine[0] = '|';
blankLine[80] = '|';
for (int i = 1; i < 80; i++) {
blankLine[i] = ' '; }
blankLine[40] = '.';
Serial.print(">>free RAM = ");
Serial.println(freeRam()); // a useful value to keep an eye on
}
void loop() // each iteration of loop is for one set of measurements only
{
if(firstLoop)
{
unsigned long timeNow = millis();
Serial.print ("millis() now = ");
Serial.println (timeNow);
recordingMayStartAt = timeNow + (settlingDelay * 1000);
Serial.print ("recordingMayStartAt ");
Serial.println (recordingMayStartAt);
recordingNow = false;
firstLoop = false;
recordingComplete = false;
noOfCyclesToBeRecorded = 1; // more array space may be needed if this value is >1 !!!
cycleNumberBeingRecorded = 0;
samplesRecorded = 0;
}
int sample_V1 = analogRead(sensorPin_V1);
//int sample_V2 = analogRead(sensorPin_V2);
// int sample_V3 = analogRead(sensorPin_V3);
int sample_I1 = analogRead(sensorPin_I1);
// int sample_I2 = analogRead(sensorPin_I2);
// int sample_I3 = analogRead(sensorPin_I3);
float filtered_V1 = 0.996*(lastFiltered_V1 + sample_V1 - lastSample_V1);
byte polarityOfThisSample_V1;
if(filtered_V1 > 0)
{
polarityOfThisSample_V1 = POSITIVE;
if (polarityOfLastSample_V1 != POSITIVE)
{
// This is the start of a new mains cycle
cycleCount++;
if (recordingNow == true) {
if (cycleNumberBeingRecorded >= noOfCyclesToBeRecorded) {
Serial.print ("No of cycles recorded = ");
Serial.println (cycleNumberBeingRecorded);
dispatch_recorded_data(); }
else {
cycleNumberBeingRecorded++; } }
else
if((cycleCount % CYCLES_PER_SECOND) == 1) {
unsigned long timeNow = millis();
if (timeNow > recordingMayStartAt) {
recordingNow = true;
cycleNumberBeingRecorded++; }
else {
Serial.println((int)(recordingMayStartAt - timeNow) / 1000); } }
} // end of specific processing for first +ve reading in each mains cycle
} // end of specific processing of +ve cycles
else
{
polarityOfThisSample_V1 = NEGATIVE;
}
if (recordingNow == true)
{
storedSample_V1[samplesRecorded] = sample_V1;
storedSample_I1[samplesRecorded] = sample_I1;
// storedSample_I2[samplesRecorded] = sample_I2;
// storedSample_I3[samplesRecorded] = sample_I3;
samplesRecorded++;
}
polarityOfLastSample_V1 = polarityOfThisSample_V1;
lastSample_V1 = sample_V1;
lastFiltered_V1 = filtered_V1;
} // end of loop()
void dispatch_recorded_data()
{
// display raw samples via the Serial Monitor
// ------------------------------------------
Serial.print("cycleCount ");
Serial.print(cycleCount);
Serial.print(", samplesRecorded ");
Serial.println(samplesRecorded);
int V1, I1, I2, I3 ;
int min_V1 = 1023, min_I1 = 1023, min_I2 = 1023, min_I3 = 1023;
int max_V1 = 0, max_I1 = 0, max_I2 = 0, max_I3 = 0;
for (int index = 0; index < samplesRecorded; index++)
{
strcpy(newLine, blankLine);
V1 = storedSample_V1[index];
I1 = storedSample_I1[index];
// I2 = storedSample_I2[index];
// I3 = storedSample_I2[index];
if (V1 < min_V1){min_V1 = V1;}
if (V1 > max_V1){max_V1 = V1;}
if (I1 < min_I1){min_I1 = I1;}
if (I1 > max_I1){max_I1 = I1;}
// if (I2 < min_I2){min_I2 = I2;}
// if (I2 > max_I2){max_I2 = I2;}
// if (I3 < min_I3){min_I3 = I3;}
// if (I3 > max_I3){max_I3 = I3;}
newLine[map(V1, 0, 1023, 0, 80)] = 'v';
newLine[map(I1, 0, 1023, 0, 80)] = '1';
// newLine[map(I2, 0, 1023, 0, 80)] = '2';
// newLine[map(I3, 0, 1023, 0, 80)] = '3';
if ((index % 2) == 0) // change this to "% 1" for full resolution
{
Serial.println(newLine);
}
}
Serial.print("min_V1 "); Serial.print(min_V1);
Serial.print(", max_V1 "); Serial.println(max_V1);
Serial.print("min_I1 "); Serial.print(min_I1);
Serial.print(", max_I1 "); Serial.println(max_I1);
// Serial.print("min_I2 "); Serial.print(min_I2);
// Serial.print(", max_I2 "); Serial.println(max_I2);
// Serial.print("min_I3 "); Serial.print(min_I3);
// Serial.print(", max_I3 "); Serial.println(max_I3);
Serial.println();
// despatch raw samples via the Serial Monitor
// -------------------------------------------
Serial.println("Raw data from stored cycle: <Vsample>, <I1sample>, <I2sample>[cr]");
Serial.print(samplesRecorded);
Serial.println(", <<< No of sample sets");
for (int index = 0; index < samplesRecorded; index++)
{
Serial.print (storedSample_V1[index]);
Serial.print(", ");
Serial.print (storedSample_I1[index]);
Serial.print(", ");
// Serial.println (storedSample_I2[index]);
}
recordingNow = false;
firstLoop = true;
pause();
}
void pause()
{
byte done = false;
byte dummyByte;
while (done != true)
{
if (Serial.available() > 0)
{
dummyByte = Serial.read(); // to 'consume' the incoming byte
if (dummyByte == 'g') done++;
}
}
}
int freeRam () {
extern int __heap_start, *__brkval;
int v1;
return (int) &v1 - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}