pic16f873a

Thread Starter

pasha

Joined Jan 18, 2009
10
hi
i need to find the maximum number in 20 samples that read from an adc.
how to write the program to do this?
please help me!!!!!
many thanks
 

thatoneguy

Joined Feb 19, 2009
6,359
The maximum sampling rate?

The maximum value/sample step?

The highest sampled level of 20 independent samples?

What language or compiler?
 

Thread Starter

pasha

Joined Jan 18, 2009
10
in MPLAB
output of current sensor:vout=2.5 +/- 0.01785ip,ip=current
over the 10ms(1 cycle),I could take sample every 0.5ms,which means 20 sample.then I need to find the maximum value between them as peak value,then subtract it from 2.5 and divide it by 1.414 to get rms.
furthermore introduce scaling factor,divide the abov number by 0.0178
at last multiply it by 220V. so it would be power!
I have to design a power meter.
my current sensor is LTSR25-NP
I really need help ,please. if any body know how to write these program,please respond!!!!
 
Last edited:

Thread Starter

pasha

Joined Jan 18, 2009
10
after all i will send it on lcd,which ia have the program.
also i have the circuit for all stuff,just this programin!!!!!!!!!!!
 
Last edited:

mik3

Joined Feb 4, 2008
4,843
Read the current value and compare it with the previous value. If its greater keep the current value, if it is less keep the previous value.
 

beenthere

Joined Apr 20, 2004
15,819
Set up a timer to indicate the passage of .5 uS. Command an A to D conversion at that time. Store the reading and compare it to the last one in.

The interesting part about this is that if you synchronize with the AC waveform crossing zero, you can always do a conversion at the same portion of the waveform, so the reading will stabilize.

Google "zero crossing circuit".
 

Thread Starter

pasha

Joined Jan 18, 2009
10
thanks all
I wonder if anyone could write this program here?(finding maximum)PLEASE
 
Last edited:

thatoneguy

Joined Feb 19, 2009
6,359
I have posted ADC routine in C in a few other threads which would compile in C18 or HiTech C. It would simply be a matter of adding another float variable and a loop to do the math.

An assembly code listing for even a full LCD Interface program is too big to fit in a single post.
 

Thread Starter

pasha

Joined Jan 18, 2009
10
i just need a program to find the maximum,in MPLAB.
i know the other sections.
i wonder i anybody could write it,please.(just finding maximum)
 

beenthere

Joined Apr 20, 2004
15,819
If you are having problems, post up your code and perhaps we can help find the error.

Since the maximum value is larger than the others, it should not be hard to do the coding.
 

Thread Starter

pasha

Joined Jan 18, 2009
10
brother,if I have known the codes,then I would write them!
Iam afraid,I do not know the codes to find the maximum number.
if you,or any other friends know how to write the program to find the largest number in 20 samples,then please,please write it here.
I know it is easy,but Iam not good at programing at all,so forgive me.
 

thatoneguy

Joined Feb 19, 2009
6,359
I personally like to help people that want to learn.

If I were to write the code, and it didn't work correctly, which is quite possible, as I do not know any details, not even which PIC, have a schematic, etc. It is assumed that I should "fix" whatever isn't right.

That sounds like "work". Blech!
 

Thread Starter

pasha

Joined Jan 18, 2009
10
if you could write it, do it,otherwise stop patronizing..and preaching....
I personally hate these type of person....
 

thatoneguy

Joined Feb 19, 2009
6,359
I'm simply stated what I am willing to do and am not willing to do to help. Do you get mad at strangers if you ask for money and they say no? In other words, I'm not "patronizing or preaching".

What you want done isn't difficult, and the assembly instructions are in the datasheet with whichever PIC you have, as well as many app notes from Microchip, including sample applications, a couple of which already do 80% of what you need done. http://www.microchip.com

There are many individuals willing to write code for you, here is one place to check: http://www.getafreelancer.com/ Your project would be in the under $30 category.
 
Top