ADC Peak Value

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi to all,

   

             I took with 16 bit , 2000 samples per second, input to the adc is 2.04 v. initially it showing correct value of 69AE but after some time it is diaplaying B900, it is showing same value for any input after dispalying correct value after some time, i am not able to find where i went wrong. here i am attaching the Project.please let me know

   

Thanks

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Unfotunately the indentation of your source-file has got lost, so it is difficult to read.

   

What I found at first sight is: in the line containing

   

for (i = 0; i < ADC_Sample_Index; i++)    

   

the variable i is only an int8 (-128 to 127) while ADC_Sample_Index is declared as an int16 (-32768 to 32767). So the loop will not run as expected for ADC_Sample_Index greater 127.

   

Are you trying to find the maximum? That you can do easier by comparing the actual ADC-value against the current maximum. When ADC is greater, save the number of the measurement and adjust the current maximum.

   

 

   

Happy coding

   

Bob

View solution in original post

0 Likes
4 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Unfotunately the indentation of your source-file has got lost, so it is difficult to read.

   

What I found at first sight is: in the line containing

   

for (i = 0; i < ADC_Sample_Index; i++)    

   

the variable i is only an int8 (-128 to 127) while ADC_Sample_Index is declared as an int16 (-32768 to 32767). So the loop will not run as expected for ADC_Sample_Index greater 127.

   

Are you trying to find the maximum? That you can do easier by comparing the actual ADC-value against the current maximum. When ADC is greater, save the number of the measurement and adjust the current maximum.

   

 

   

Happy coding

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Hi, you had several inconsistancies, like declaring i as int8 rather than uint16 (its value

   

ranges to 2000, its used as an index hence always +), and others.

   

 

   

updated main.c attached

   

 

   

Regards, Dana.

Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Anotheer issue I just found is that after the first loop through 2000 samples the outermost while willo be executed again (wich is desired) all your values you initialized with the declaration now have not the original values you'd like to have them,

   

 

   

Bob

lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Looks like I missed the attachment.

   

 

   

Regards, Dana.