1. pasha

    Thread Starter Member

    Jan 18, 2009
    10
    0
    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
     
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    The maximum sampling rate?

    The maximum value/sample step?

    The highest sampled level of 20 independent samples?

    What language or compiler?
     
  3. pasha

    Thread Starter Member

    Jan 18, 2009
    10
    0
    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: Mar 17, 2009
  4. pasha

    Thread Starter Member

    Jan 18, 2009
    10
    0
    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: Mar 17, 2009
  5. russ_hensel

    Well-Known Member

    Jan 11, 2009
    818
    47
  6. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    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.
     
  7. pasha

    Thread Starter Member

    Jan 18, 2009
    10
    0
    thats right my friend.
    but how?(what would be the program?)
    cheers
     
  8. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    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".
     
  9. pasha

    Thread Starter Member

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

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    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.
     
  11. pasha

    Thread Starter Member

    Jan 18, 2009
    10
    0
    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)
     
  12. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    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.
     
  13. pasha

    Thread Starter Member

    Jan 18, 2009
    10
    0
    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.
     
  14. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    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!
     
  15. pasha

    Thread Starter Member

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

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    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.
     
Loading...