Software ADC Comparator?


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Hope this doesn't make anyones head explode!

    just to make sure the problem i need to solve is clear, i will explain what i want yet again.
    I will not be monitoring a sine wave, the signal will not vary that often actually and will never go negative in relation to ground. but for the sake of an example, I will use sinewave.

    Say that there is a sine wave, the frequency of which does not matter, that is 2 Vp-p.
    This Sine wave is "floating" with its zero point at 2 volts above ground, making the lowest peak 1 volt, and the highest peak 3 volts. then we'll say my threshold is set at 1.5V.
    When the sine wave reaches 1.5V above the 1 volt line (not ground!), it triggers a response from my circuit, or flashes the LED once, and then waits.
    Where the sine wave is "floating" (again, floating, not peaking) doesn't matter, it will be anywhere between 0 and 5 volts and is out of my control, it is an independent circuit.
    The PIC circuit only needs to trigger when there is a positive going change in voltage that exceeds a threshold that i will need to have control of. so therefore, the threshold has to follow the 1 volt ( or 2V or whatever!) line automatically, while i can vary the threshold level, it will always be in reference to the 1 volt line! not ground. please see my example.bmp
    (and yes i know that if my threshold is 1.5 volts, and the signal zero reference exceeds 3.5, the threshold will be out of range, and that is fine because 1.5V is only an example.)
    Attached Images Attached Images  

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default

    Ryan

    Now, I understand what you're trying to do. However, reading the adc like this hardly gives you anything worthwhile.

    Code:
    ADCIN 2, voltLevBf ' sample voltage on ADC 2
    PAUSEUS 12
    ADCIN 4, threshHold ' get threshold from pot set up as volt. divider on ADC 4
    PAUSEUS 12
    ADCIN 2, voltLevAf ' sample voltage on ADC 2 again, to check for difference
    PAUSEUS 12
    Why? The difference between the 2 samples on ADC 2 is just around 25uS. Is this what you really want??

    On reading closely, I think you need to do this
    Code:
    'Find the minimum value
    MinAdc var word         'I'm assuming the ADC to be 10bit or more
    CurrAdc var word
    Threshold var word
    DelayVal  var word
    
    while 1                                     ' loop forever
        ADCIN 2, CurrAdc                    ' current ADC reading
        ADCIN 4, Threshold                 ' threshold setting
        ADCIN 5, DelayVal                   ' delay setting
        if CurrAdc > MinAdc + Threshold then
               High Output
               pause DelayVal
               Low Output
               if CurrAdc <> MinAdc then  ' check if the current ADC value < Min ADC
                 MinAdc = CurrAdc          ' and correct the MinADC value
               endif
        endif
    wend
    Does this do what you want?
    Jerson

  3. #3
    Join Date
    Sep 2006
    Location
    Indiana, USA
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Thanks

    I don't know yet, i'll have to give that code a shot, one thing i did figure out tho is that my justification was wrong, i should have had it set to right justify, and I should have saw that earlier! I used serout to spit out the ADC values and now everything looks like it should, but i'll have to do further testing.

    Thanks again!

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. Comparator circuit thoughts....
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th October 2009, 06:04
  3. Software Stack
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th December 2007, 10:04
  4. ADC value with 2 decimals on an LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2005, 15:54
  5. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55

Members who have read this thread : 0

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