Record, storage and compare analog signals


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Apr 2008
    Posts
    25

    Default Record, storage and compare analog signals

    Hi, all, please I need help
    I need record analog signal (10Bit) to PIC with length 60us, storage as reference (red line) and compare with next one incoming (blue line). My question is, how to sampling and storage reference signal and compare those signals? I want to use PIC18F2455.
    Look Fig1Name:  fig1.jpg
Views: 617
Size:  8.4 KB
    Thanks Kuba

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    Looking at the Data sheet of the chip 18F2455 and especially in the A/D Acquisition Requirements, it seems that you need a 2.45usec for every sample. Of course you need also a little time to transfer the AD value to an array and start AD again. Say for the sake of the discussion the the total time is 3usec.

    This leaves you with only 20 samples in the 60usec period.

    Is that OK with you?

    Ioannis

  3. #3
    Join Date
    Apr 2008
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    I think, 20 samples is enough.
    How can I obtain this 20 samples and storage as numbers for calculation?

    Thanks Kuba

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    The assumption of 2.45us was based on the fact that Vdd is 5Volts and the source impedance less than 2.5Kohm.

    What will be the clock of the your controller?

    Ioannis

  5. #5
    Join Date
    Apr 2008
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    I will use osc. 20MHz

    Kuba

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    Lets then suppose you have the analog input at AN0.

    Code:
    ADCON0=%00000001    ' Channel 0, ADC on
    ADCON1=%00001110    ' AN0 as analog,rest as digital
    ADCON2=%10010101    ' Right justify result and Fosc/16
    
    analog_res_array    VAR WORD[40]
    counter             VAR BYTE
    start_array         VAR BYTE     ' first element of the array to store samples
    stop_array          VAR BYTE     ' last element of the array to store samples
    
    start_array=0:stop_array=19      ' first group of 20 samples
    gosub adc_routine
    start_array=20:stop_array=39     ' second group of 20 samples
    gosub adc_routine
    
    ......
    
    adc_routine:
        for counter=start_array to stop_array
            high adcon0.1
            while adcon0.1:wend
            analog_res_array[counter]=adresh*256+adresl
        next counter
    return
    Now in the array you have 40 samples (two groups of 20) and you can compare them.

    Note that code is untested, but you get the idea.

    Ioannis
    Last edited by Ioannis; - 22nd April 2014 at 17:58.

  7. #7
    Join Date
    Apr 2008
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    Thanks for your help.

    Kuba

  8. #8
    Join Date
    Apr 2008
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    Hi,
    I have code for 10 Bit AD converter with array storage four samples.
    If I send results from array separately, I see all numbers of array results on LCD, (Example 1.)
    But If I send all results from array together, LCD show number 0. (Example 2.)
    My question is, what is wrong, how correct this code, how can I send all results from array to LCD?

    Thanks
    Kuba

    Example 1.
    Lcdout DEC array[0]," ", Dec array[1]," ", Dec array[2]," ", Dec array[3]

    Example 2.
    Lcdout DEC array[counter]



    This is my code:

    Define LCD_DREG PORTB
    Define LCD_DBIT 4
    Define LCD_RSREG PORTC
    Define LCD_RSBIT 4
    Define LCD_EREG PORTC
    Define LCD_EBIT 5

    ' Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 3 ' Set sampling time in uS

    TRISA = %11111111 ' Set PORTA to all input
    TRISB = %00000000 ' Set PORTB to all output
    TRISC = %00000000 ' Set PORTC to all output

    ADCON1 = %10000010 ' Set PORTA analog and right justify result

    Pause 500 ' Wait .5 second

    array Var Word [4]
    counter VAR Byte
    Start_array VAR Byte
    Stop_array VAR Byte

    Start_array =0 : Stop_array = 3

    adc_runtime:
    for counter = Start_array to Stop_array
    ADCIN 0, array[counter] ' Read channel 0 to array[counter]
    next counter
    Pause 100 ' Wait .1 second

    Lcdout $fe, 1 ' Clear LCD
    Lcdout DEC array[counter]


    Pause 100 ' Wait .1 second

    Goto adc_runtime ' Do it forever
    End

  9. #9
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    Use example 1 as example 2 will only display array[4] or you could do something like this

    adc_runtime:
    Lcdout $fe, 1 ' Clear LCD
    for counter = Start_array to Stop_array
    ADCIN 0, array[counter] ' Read channel 0 to array[counter]
    Lcdout DEC array[counter]," "
    next counter
    Pause 100 ' Wait .1 second

    Try it a see what happens

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    You try to display only one array element and especially the array[4] element that does not exist. You have defined from 0 to 3 (4 elements) and the variable counter after the end of the For-Next loop ends up with the value of 4.

    So you try to display an non-existence variable, that could have a random value.

    Steve has given you an example to display the variable within the loop and should work as you expect.

    Ioannis

  11. #11
    Join Date
    Apr 2008
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    Working, great

    Thanks EarlyBird2

    Kuba
    Last edited by Kuba230; - 9th May 2014 at 10:47.

  12. #12
    Join Date
    Apr 2008
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    Hi loannis,
    I tried your metod, it does not work.
    Method of EarlyBird2 really works, Im surprise.

    Thanks
    Kuba

  13. #13
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    Kuba,

    You are welcome.

    Steve

  14. #14
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    What method? I explained what Steve has given you as an example.

    Ioannis

  15. #15
    Join Date
    Apr 2008
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    Hi loannis,
    now I understand you explanation.
    Exist other method, how to send all array elements to LCD, after the completion loop, except my 1. Example?


    Thanks
    Kuba

    Sorry for my english

  16. #16
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    With arrays the STR modifier is used to send without FOR-NEXT loop.

    But in your case you need a second modifier and up to this moment this is not supported.

    This does work: STR my_array\16 ' sends the first 16 bytes of the array my_array

    This does not work: STR DEC my_array\16

    But I wish sometime in the next update/upgrade it will be supported!

    Ioannis
    Last edited by Ioannis; - 9th May 2014 at 13:24.

  17. #17
    Join Date
    Apr 2008
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Record, storage and compare analog signals

    Thanks loannis for your answer

    Kuba

Similar Threads

  1. how to record sound into eeprom
    By Mus.me in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 20th November 2009, 21:16
  2. How to read analog signals?
    By thm ov3rkill in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 8th March 2009, 05:00
  3. Using a PIC to record voice
    By weirdjim in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 24th December 2007, 20:21
  4. Replies: 6
    Last Post: - 20th August 2006, 22:00
  5. The best way to record non-volatile data
    By johnson in forum General
    Replies: 3
    Last Post: - 19th July 2004, 09:03

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts