what is wrong am i doing in this code?


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Jan 2012
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: what is wrong am i doing in this code?

    thanx in advance Henrik. now i want to continue to output constant duty ratio when the comparator input are equal, is it possible to output that constant duty cycle which make input equal to Vref?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: what is wrong am i doing in this code?

    Hi,
    Not sure I understand exactly what you mean. A comparator will only tell you if its positive input is EITHER above or below its negative input. There is no way to tell if the two inputs are "equal". What you COULD possibly do is to use both comparators and create a window comparator which will tell you if the input is below, within or above the window/thresholds.

    Or use the ADC...

    /Henrik.

  3. #3
    Join Date
    Jan 2012
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: what is wrong am i doing in this code?

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    Not sure I understand exactly what you mean. A comparator will only tell you if its positive input is EITHER above or below its negative input. There is no way to tell if the two inputs are "equal". What you COULD possibly do is to use both comparators and create a window comparator which will tell you if the input is below, within or above the window/thresholds.

    Or use the ADC...
    /Henrik.
    up to now i dont need to continue to work with the comparator module because it fail to do as i want
    i want to use adc but have already read the adcin command but how to use adc to compare the two inputs in the pic i stop there,
    can you give me any sample code on that issue?

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: what is wrong am i doing in this code?

    Code:
    Feedback  VAR WORD
    Reference VAR WORD
    
    DeadBand  CON 2         ' +/-, set to 0 if no deadband is needed.
    
    Main:
        ADCIN 0, Feedback       ' Get feedback voltage from Channel 0
        ADCIN 1, Reference      ' Get reference voltage from Channel 1
    
        ' Now compare the feedback voltage to the reference voltage and include the deadband.
    
        IF Feedback > (Reference + Deadband) THEN   ' Feedback is higher than reference
            ' Do whatever is needed here.
        ENDIF
    
        If Feedback < (Reference - Deadband) THEN    ' Feedback is lower than reference
          ' Do whatever is needed here.
        ENDIF
    Goto Main

  5. #5
    Join Date
    Jan 2012
    Posts
    24


    Did you find this post helpful? Yes | No

    Default Re: what is wrong am i doing in this code?

    thaks in advance, am taking a time to concentrate with it and when i meet any difficult i will came back to you

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