The analog-to-digital code makes use of the files ‘adc.h’ and ‘adc.c’ found in this BDMICRO sample code. These 2 files shall be included in the project and be part of the compilation.
//...
#include "adc.h"
//...
#define PI 3.14159265
#define DEG_TO_RAD ((double)(PI/180.0))
#define RAD_TO_DEG ((double) (180.0/PI))
double awa_measured;
// Wind vane calibration data
double wcx[2];
double wcy[2];
double xc;
double yc;
double wcx[2];
double wcy[2];
double xc;
double yc;
uint16_t green, blue;
int main(void)
{
// ...
xc = 741.2638;
yc = 744.6921;
wcx[0] = 1.002073;
wcx[1] = -0.006924865;
wcy[0] = -0.006924865;
wcy[1] = 1.023132;
/* initialize A/D Converter */
adc_init();
for(;;)
{
// begin a new cycle
// ...
green = adc_readn(0, 10); /* sample channel #0 10 times, take average */
blue = adc_readn(1, 10); /* sample channel #1 10 times, take average */
double dgreen = ((double)green) - xc;
double dblue = ((double)blue) - yc;
double xmap = wcx[0] * dgreen + wcx[1] * dblue;
double ymap = wcy[0] * dgreen + wcy[1] * dblue;
awa_measured = atan2(ymap, xmap) * RAD_TO_DEG;
// ...
green = adc_readn(0, 10); /* sample channel #0 10 times, take average */
blue = adc_readn(1, 10); /* sample channel #1 10 times, take average */
double dgreen = ((double)green) - xc;
double dblue = ((double)blue) - yc;
double xmap = wcx[0] * dgreen + wcx[1] * dblue;
double ymap = wcy[0] * dgreen + wcy[1] * dblue;
awa_measured = atan2(ymap, xmap) * RAD_TO_DEG;
// ...
// Wait for timer signal to begin a new cycle
// ...
}
}
}
}
























