Hello. I'm having a bit of trouble with my programming. I'm giving a signal to my board and it will detect and display the maximum and minimum point of the signal wave.
However, I'm not really sure if I wrote my codes correctly.
Also, I'm getting this error :
"operator requires a pointer and an integer as operands"

Here's a part of my codes.

ADCON0 = ADC_SINE;
      ADCON0bits.GO = 1;
      while (ADCON0bits.DONE);             //Terminates the A/D conversion when all the signal are converted
      adc_result = 256*ADRESH + ADRESL;      // Store the result

      min=adc_result[0];
      max=adc_result[0];
      for(j=0;j<i;j++)
      {
         if(adc_result[j]<min)
         {
            min=adc_result[j];
         }
      }
      for(k=0;k<i;k++)
      {
         if(adc_result[k]<max)
         {
            max=adc_result[k];
         }
      }

      CurPosLCD(0x10);
      Out_LCD(ROM_TYPE "MIN= ");
      Out_Dec_LCD(min);
      CurPosLCD(0x20);
      Out_LCD(ROM_TYPE "MAX= ");
      Out_Dec_LCD(max);      
      Delay_sec(1);

I hope someone could help me out here.

Thank You.

Note: I posted this exact post on a wrong section of the forum.

Recommended Answers

All 2 Replies

Two things:

1) Your logic for max is reversed. Use > max, not < max.

min=adc_result[0];
      max=adc_result[0];
      for(j=0;j<i;j++)
      {
         if(adc_result[j]<min)
         {
            min=adc_result[j];
         }
      }
      for(k=0;k<i;k++)
      {
         if(adc_result[k]<max)   //change the < to >
         {
            max=adc_result[k];
         }
      }

and

2) You only need one for loop for this, you can do two tests in
one for loop, no problem.

ADCON0 = ADC_SINE;
      ADCON0bits.GO = 1;
      while (ADCON0bits.DONE);             //Terminates the A/D conversion when all the signal are converted
      adc_result = 256*ADRESH + ADRESL;      // Store the result

      min=adc_result[0];
      max=adc_result[0];
      for(j=0;j<i;j++)
      {
         if(adc_result[j]<min)
         {
            min=adc_result[j];
         }
         if(adc_result[k]>max)
         {
            max=adc_result[k];
         }
      }
      CurPosLCD(0x10);
      Out_LCD(ROM_TYPE "MIN= ");
      Out_Dec_LCD(min);
      CurPosLCD(0x20);
      Out_LCD(ROM_TYPE "MAX= ");
      Out_Dec_LCD(max);      
      Delay_sec(1);

The rest of your code pertains to the board you're working with. You'll have
to refer to it's reference material for any other errors it's giving you. Line #4 looks dodgy, but I'm not familiar with your board.

Change the code in lines 14 and 16, above. Replace the k index, with the j, as below:

if(adc_result[j]>max)
         {
            max=adc_result[j];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.