vibodha
Newbie level 6
- Joined
- Jun 3, 2013
- Messages
- 11
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,365
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 unsigned int Min_ADC_Value,value,Max_ADC_Value,ADC_Value,DOP; ///////////////////////////////////////////////// Finding Min and max Max_ADC_Value = ADC_Get_Sample(0); Min_ADC_Value = ADC_Get_Sample(0); while(j<145) { j++ ; ADC_Value=ADC_Get_Sample(0); if (Max_ADC_Value<ADC_Value) { Max_ADC_Value=ADC_Value; } else if(Min_ADC_Value>ADC_Value) { Min_ADC_Value=ADC_Value; } delay_ms(500); } //////////////////////////////////////////////////// DOP=Max_ADC_Value- Min_ADC_Value; // this value converted to char and display with Max_ADC_Value and Min_ADC_Value on LCD
Code C - [expand] 1 ADC_Value=Min_ADC_Value;
But in this case the while loop will be useless since the ADC_Value (and then its min and max) will never be refreshedYou must replace the row #8 at code above for the one presented bellow:
Code C - [expand] 1 ADC_Value=Min_ADC_Value;
+++
You must replace the row #8 at code above for the one presented bellow:
Code C - [expand] 1 ADC_Value=Min_ADC_Value;
+++
I think the pointer goes to next instruction after completing the ADC conversion.It could be you read the ADC before the conversion has finished.
Max_ADC_Value = 0;
Min_ADC_Value = 1023;
while(j<145)
{
j++ ;
ADC_Value=ADC_Get_Sample(0);
if (ADC_Value>Max_ADC_Value)
{
Max_ADC_Value=ADC_Value;
}
else
if(ADC_Value<Min_ADC_Value)
{
Min_ADC_Value=ADC_Value;
}
delay_ms(500);
}
Show the ADCONx settings.
ANSEL = 1; // Configure AN0 pin as analog
ANSELH = 0; //Configure other AN pins as digital I/O
hello,
Don't use read ADC to define min and max initial values.
Code:Max_ADC_Value = 0; Min_ADC_Value = 1023; while(j<145) { j++ ; ADC_Value=ADC_Get_Sample(0); if (ADC_Value>Max_ADC_Value) { Max_ADC_Value=ADC_Value; } else if(ADC_Value<Min_ADC_Value) { Min_ADC_Value=ADC_Value; } delay_ms(500); }
16F877 Test Min Max
Init LCD
Test Min Max ADC
ADC Max= . 961
ADC Min= . 573
Delta = 388
........
j=0;
ADC_Init();
Max_ADC_Value = 0;
Min_ADC_Value = 1023;
while(j<30)
{
j++ ;
ADC_Value=ADC_Get_Sample(0);
//WordToStr(ADC_Value,CRam1);
//Echo(); // on Terminal
if (ADC_Value>Max_ADC_Value)
{
Max_ADC_Value=ADC_Value;
}
else
if(ADC_Value<Min_ADC_Value)
{
Min_ADC_Value=ADC_Value;
}
Led_Verte_D0 =!Led_Verte_D0 ;
delay_ms(50);
}
Lcd_Cmd(_LCD_FIRST_ROW );
strcpy(CRam1,"ADC Max= .... ");
WordToStr(Max_ADC_Value,CRam1+10);
Echo();
Lcd_Cmd(_LCD_SECOND_ROW );
strcpy(CRam1,"ADC Min= .... ");
WordToStr(Min_ADC_Value,CRam1+10);
Lcd_Out_CP(CRam1);
Echo();
delay_ms(2500);
Lcd_Cmd(_LCD_FIRST_ROW );
strcpy(CRam1,"Delta = .... ");
DOP=Max_ADC_Value- Min_ADC_Value;
WordToStr(DOP,CRam1+10);
Lcd_Out_CP(CRam1);
Echo();
do
{}
while (1);
Just a stupid test to see if LCD is printing correctly: exchange the sequence in which the variables are sent to the LCD, i.e. if now you sent to LCD Max, Min and DOP, try sending DOP, Max and Min and see what happen.
I mean if you use an instruction equivalent to print("%d %d%d",Max,Min,DOP) try doing print("%d %d%d",DOP,Max,Min)
Where is ADC initialze ? like .... ADC_Init();
This following code works perfect.. on 16F877
result on terminal
Code:16F877 Test Min Max Init LCD Test Min Max ADC ADC Max= . 961 ADC Min= . 573 Delta = 388
Code:........ j=0; ADC_Init(); Max_ADC_Value = 0; Min_ADC_Value = 1023; while(j<30) { j++ ; ADC_Value=ADC_Get_Sample(0); //WordToStr(ADC_Value,CRam1); //Echo(); // on Terminal if (ADC_Value>Max_ADC_Value) { Max_ADC_Value=ADC_Value; } else if(ADC_Value<Min_ADC_Value) { Min_ADC_Value=ADC_Value; } Led_Verte_D0 =!Led_Verte_D0 ; delay_ms(50); } Lcd_Cmd(_LCD_FIRST_ROW ); strcpy(CRam1,"ADC Max= .... "); WordToStr(Max_ADC_Value,CRam1+10); Echo(); Lcd_Cmd(_LCD_SECOND_ROW ); strcpy(CRam1,"ADC Min= .... "); WordToStr(Min_ADC_Value,CRam1+10); Lcd_Out_CP(CRam1); Echo(); delay_ms(2500); Lcd_Cmd(_LCD_FIRST_ROW ); strcpy(CRam1,"Delta = .... "); DOP=Max_ADC_Value- Min_ADC_Value; WordToStr(DOP,CRam1+10); Lcd_Out_CP(CRam1); Echo(); do {} while (1);
Use ADC_Read(0) instead of ADC_Get_Sample(0) and see.
Just to debug, send all these values ( DOP / Max_ADC_Value / Min_ADC_Value ) to UART just before calculate subtraction.
It is not clear the time elapsed between acquisition and sending to debug.
+++
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?