Comparator - tracking the high low condition more robustly.


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Hi Henrik,

    Many thanks for the tips.

    I've had a look at the 16f690 datasheet, & you're completely right - it seems that bit 6 of the CM1CON0 register reflects the logic level output of comparator 1.

    Therefore I'm thinking something like this will work...

    Code:
    Comp1_Int:
    If CM1CON0.6 = 0 then above_threshold = 0             
    If CM1CON0.6 = 1 then above_threshold = 1  
    
    @ INT_RETURN
    ...that should keep my variable in total sync with the comparator1 output logic level?

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


    Did you find this post helpful? Yes | No

    Default

    Or simply Above_Threshold = CM1CON0.6 or you may not even need a "mirror" of the output, instead of using Above_Threshold in your main application simply use CM1CON0.6 directly.

    On the other hand, if all the interrupt is really doing is to "copy" the state of the comparator output then there's really no need to use the interrupt at all - simply read the comparator output directly in your code.

    If you want you can even create an alias, like:
    Above_Threshold VAR CM1CON0.6

    Now, when you use Above_Threshold in your program you are actually reading the comparator output.

    /Henrik.

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Thanks Henrik.

    the reason I'm using an interrupt, is that I eventually want things to kick in as soon as the comparator changes state....so I will now begin expanding the interrupt routine to include other stuff.

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