Hello
I asked you previously regarding calibratedMaximum[5] and calibratedMinimum[5] values.
I got minimum value in calibratedMaximum[5] and maximum in calibratedMinimum[5] .
I have simulated your code in simple format as belows.
Could you please explain to me why I am getting other way round.
I bought 3pi last week and going to try. First thing is I have to download gnu compiler and figure it out what to do. I will let you know asap.
Regards
Jagdish
/********************** code start from here*****************************************/
unsigned int max_sensor_values[5]; // storage for max & min sensor values
unsigned int min_sensor_values[5];
unsigned int calibratedMaximum[5];
unsigned int calibratedMinimum[5];
unsigned int sensor_values[5];
//simulated adc values
unsigned int code adc_values[10][5] = {
{ 200, 200, 900, 200, 200},
{ 200, 200, 400, 700, 200},
{ 200, 200, 200, 900, 200},
{ 200, 200, 200, 200, 900},
{ 200, 200, 200, 200, 1000},
{ 200, 220, 615, 915, 200},
{ 200, 200, 915, 200, 200},
{ 200, 905, 200, 200, 200},
{ 913, 200, 200, 200, 200},
{ 200, 200, 890, 200, 200}
};
/*********************************************************************************************************
Description: Reads the sensors 10 times and uses the results for calibration. The sensor values are not
returned; instead, the maximum and minimum values found over time are stored internally
and used for the readCalibrated() method.
**********************************************************************************************************/
//void calibrate_line_sensors(void)
void main(void)
{
int i;
int j;
static int r = 0;
unsigned int maxValue = 1023;
/* step 1 */
// emitter_on
// Initialize the max and min calibrated values to values that
// will cause the first reading to update them.
for(i=0;i<5;i++)
{
calibratedMaximum[i] = 0; /* RESET BUFFER */
}
for(i=0;i<5;i++)
{
calibratedMinimum[i] = maxValue; /* STORE MAX VALUE 1023 */
}
for(j=0;j<10;j++)
{
// IR_EMITTER = ON; /* switch emitter ON */
// read_adc(); /* read adc, values are stored in sensor_values[] */
// IR_EMITTER = OFF; /* switch emitter OFF */
// get simulated adc values
for(i=0;i<5;i++)
{
sensor_values[i] = adc_values[r][i]; /* get simulated adc values */
}
r++; // point to next row of adc values
for(i=0;i<5;i++)
{
// set the max we found THIS time
if(j == 0 || max_sensor_values[i] < sensor_values[i])
max_sensor_values[i] = sensor_values[i];
// set the min we found THIS time
if(j == 0 || min_sensor_values[i] > sensor_values[i])
min_sensor_values[i] = sensor_values[i];
}
}
// record the min and max calibration values
for(i=0;i<5;i++)
{
if(min_sensor_values[i] > (calibratedMaximum)[i])
{
(calibratedMaximum)[i] = min_sensor_values[i];
}
if(max_sensor_values[i] < (calibratedMinimum)[i])
{
(calibratedMinimum)[i] = max_sensor_values[i];
}
}
}
/*****************************end****************************************************/