I have an array with data from the adc, for this data I need to save 10 periods per second in the sd card, to detect the periods I use a zerocrossing function then I add one to a variable averytime it crosses zero( changes sings) and write a file, I have two problem, first is seting up the timer to send 10 periods of data every second. My second problem is that I just want to send those 10 period of data, have a break and continue sending the next 10 periods. this code works, my question is how can I implement the timing, How can I send 10 periods in 1 second?
void zeroCrossing(float* data, float* zerCross, int nx)
{
int i;
int a = 0;
bool sign1, sign2;
memset(zerCross, 0, nx * sizeof(float)); //copies the 0 to the first characters of the string
//pointed to, by argument
for (i = 0; i < nx - 1; i++) {
float b[16]; /* loop over data */
b[i] = data[i];
sign1 = getSign(data[i]);
sign2 = getSign(data[i + 1]);
if (sign1 != sign2) { /* set zero crossing location */
zerCross[i + 1] = 1;
a++;
// break ;
// continue;
if (a == 10) { // 10
break;
}
}
}
//cout << a<<endl;
}
/* get sign of number */
bool getSign(float data)
{
if (data > 0) /* positif data */
return (1);
else /* negatif data */
return (0);
}