Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Maximum and Minimum Value

Status
Not open for further replies.

unexpert

Newbie level 5
Joined
Aug 10, 2010
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,337
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.

Code:
                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 give me some help here.

Thanks
 

Hi
What the define of adc_result?
If it is an array, then this line:
adc_result = 256*ADRESH + ADRESL;
You assign an int to a pointer.
I think you may want like this:
*(adc_result+i) = 256*ADRESH + ADRESL;
 

adc_result is just an unsigned int here
 

Hi,

if(adc_result[k]<max)

Should this be:

if(adc_result[k] > max)

scanman
 

oh! yeah, I didn't notice that. Thanks :)
But, it still didn't solve my problem ):
 

Have you been able to verify any data being stored in the array adc_result ?
Would need to see your other code to help troubleshoot step by step.
 

oh..here are the rest of my codes:

Below is my main file
Code:
#include<p18f2620.h>
#include<delays.h>
#include<stdlib.h>
#include<adc.h>
#include<stdio.h>
#include "lcd.h"
#include "declare.h"

void main()
{
	OSCCON = 0b01110000;									// Use INTOSC 8MHz (Use internal 8MHz x 4 oscillator = 32MHz)
	OSCTUNE = 0b01000000;
	
	ADCON1 = 0b00001011;									// AN0, AN1 and AN3 as analog inputs
	ADCON2	= 0b10010100;	
	TRISA = 0b00001111;
	TRISB = 0b00000000;										// PORTB=>LCD_DATA, RB0=>LCD_E, RB1=>LCD_RS;
	PORTB = 0b00000000;

		Init_LCD();
		LCD_Intro();
		LCD_Intro2();
		LCD_Intro3();
		VoltBlank();
		
		while(1) 
		{
		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);
	
		}
}
 

min=0;
max=0;
while(1)
{
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
if(min > adc_result)
min=adc_result;

if(max < adc_result)
max=adc_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);

}
 

adc_result is defined as a singular data type (int) in one portion for the code, and then an array in another part of the code.

you should make up your mind as to what it is, or the compiler will complain.
 

Also I don't see any initialization for variable i
 

rajudp said:
min=0;
max=0;
while(1)
{
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
if(min > adc_result)
min=adc_result;

if(max < adc_result)
max=adc_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 tried editing your codes to this but all i got was 0 for minimum and some value for maximum..i dont know if it's correct though. at least it works, thanks!

Added after 27 seconds:

ddeenn said:
Also I don't see any initialization for variable i

I declared that under my header files
 

min=0xffff; // give a maximum value for min depending to the sizeof variable ie char,int etc
max=0;
while(1)
{
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
if(min > adc_result)
min=adc_result;

if(max < adc_result)
max=adc_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);

}

Added after 4 minutes:

what you are trying to read, if it is a halfwave with small capacitor again chances are for showing 0 as minume,

in this case the problem was with line min=0; since if(min > adc_result) always return false
 

i dont know if it's correct though.

this is a perfect example of programming without knowing what to program for.

you will never be successful by doing this.
 

millwood said:
i dont know if it's correct though.

this is a perfect example of programming without knowing what to program for.

you will never be successful by doing this.


hmm..i somewhat know but not really sure, ill have to check my wave from a oscillator
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top