• AVR Freaks

Hot!PIC16F1769 Possible to use Comparator on Two Input Voltages?

Author
acharnley
Super Member
  • Total Posts : 270
  • Reward points : 0
  • Joined: 2016/05/01 06:51:28
  • Location: 0
  • Status: offline
2019/04/15 06:48:41 (permalink)
0

PIC16F1769 Possible to use Comparator on Two Input Voltages?

I need to compare two voltage's supplied to two pins (say between 0 and 1023) to see which is higher. The comparators allow both to be compared to DAC values but not each other.

Is there a way to do it without an external comparator?



Attached Image(s)

#1

16 Replies Related Threads

    jack@kksound
    code tags!
    • Total Posts : 3183
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/15 08:29:30 (permalink)
    0
    The comparators have independent selection for the +input and the -input. You can select from 4 different pins for the -input and 2 pins for the +input. That should allow you to compare the two voltages if they are presented to the proper pins. See REGISTER 19-3: CMxNSEL: COMPARATOR Cx NEGATIVE CHANNEL SELECT REGISTER and REGISTER 19-4: CMxPSEL: COMPARATOR Cx POSITIVE CHANNEL SELECT REGISTER 1 in the datasheet.
    #2
    acharnley
    Super Member
    • Total Posts : 270
    • Reward points : 0
    • Joined: 2016/05/01 06:51:28
    • Location: 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/15 09:50:34 (permalink)
    0
    OK I see where I went wrong. I need to use all four comparators and three dac's, with one comparator doing the aforementioned double input check.

    This means I need to tie a positive input from one comparator with the negative input on another. May be best explained with a mapping;

    1. DAC and Store
    2. Store and DC
    3. DAC and DC
    4. DAC and LFET (ignore)

    Where the first value loads into positive, second into negative. Which means Store is on CMP1 negative and CMP1 positive.

    Reckon there'll be any issue with presenting the same input to two different comparators?
    #3
    cobusve
    Super Member
    • Total Posts : 482
    • Reward points : 0
    • Joined: 2012/04/02 16:15:40
    • Location: Chandler
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/15 10:01:46 (permalink)
    0
    I am not really clear on what you are trying to do. What I can tell you is that the comparitors work exactly the same as external comparators would, so you should have no problem.
     
    There are overlapping pin assignments available and it is no problem using the overlaps, the pin definitions overlap specifically in order for you to do this.

    Also take a look at https://www.microforum.cc/ - a great resource for information on PIC and AVR microcontrollers and embedded programming in general. You can also post questions to the experts there.
    #4
    acharnley
    Super Member
    • Total Posts : 270
    • Reward points : 0
    • Joined: 2016/05/01 06:51:28
    • Location: 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/15 10:18:14 (permalink)
    0
    I take it the inputs are rail-to-rail? I need them to get close to GND.

    My "issue" is the DAC's are only available on the CMP positive, which means I have to have the same input going to two pins. That wouldn't be a problem however I'm out of CXIN- pins unless I use RA0/1 which are CLK/DAT lines (and I don't want to do that).

    I wish Microchip made PIC's with more comparators.
     
     
    #5
    coffee critic
    Super Member
    • Total Posts : 354
    • Reward points : 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/15 10:33:33 (permalink)
    0
    The comparators are rail to rail but the offset increases as you get closer to the rail. 
     
    The 16F1779 has 8 comparators if more are needed.     

    n_*$
    #6
    acharnley
    Super Member
    • Total Posts : 270
    • Reward points : 0
    • Joined: 2016/05/01 06:51:28
    • Location: 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/15 11:27:48 (permalink)
    0
    What do you mean by the offset? Hoping to get close to 0.1v.

    I've managed with the 1769, just (no pins remaining). I'm not using the chips main features (for switch mode supplies) so it's a bit of a waste and would have preferred an SMT etc, but can live with it. 
    #7
    coffee critic
    Super Member
    • Total Posts : 354
    • Reward points : 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/15 13:47:47 (permalink)
    0
    Table 36-19 Parameter CM01.  Note this is specified at Vdd/2.  The Max number will get larger than 5mV as you approach either rail. Look at the figures on page 530 for more detail.

    n_*$
    #8
    Aussie Susan
    Super Member
    • Total Posts : 3541
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/15 19:51:55 (permalink)
    0
    I must admit that I am confused as to what you are wanting to do with the comparator.
    In Post #1, you said that you wanted to know which voltage was higher - connect one voltage to (say) C1IN0+ and the other to (say) C1IN0-. With the suggested pins you don;t even need to set the CMxPSEL and CMxNSEL registers as the POR default is to use those inputs.
    Where do the DACs come in?
    Of course you have all of the other considerations the others have pointed out to you.
    Susan
    #9
    acharnley
    Super Member
    • Total Posts : 270
    • Reward points : 0
    • Joined: 2016/05/01 06:51:28
    • Location: 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/17 00:39:59 (permalink)
    0
    Hi Susan,

    I have three channels to compare with DAC values and two of these channels must be compared with one another.

    So 3x DAC and 4x comparator. DAC's can only go to the negative input and pins to the positive input.

    So 3x CXIN- and 1x CXINX+ inputs required.

    Where one of those negative pins has the same input as the positive pin.

    Regards,

    Andrew
    #10
    acharnley
    Super Member
    • Total Posts : 270
    • Reward points : 0
    • Joined: 2016/05/01 06:51:28
    • Location: 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/17 00:41:08 (permalink)
    0
    coffee critic
    Table 36-19 Parameter CM01.  Note this is specified at Vdd/2.  The Max number will get larger than 5mV as you approach either rail. Look at the figures on page 530 for more detail.



    Which datasheet are you using? It doesn't tally with PIC16F176X and I couldn't find the comparator values by searching mine. Could you drop some keywords and I'll retry?

    Andrew
    #11
    coffee critic
    Super Member
    • Total Posts : 354
    • Reward points : 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/17 10:23:51 (permalink)
    0
    DS40001775D-page 504

    n_*$
    #12
    acharnley
    Super Member
    • Total Posts : 270
    • Reward points : 0
    • Joined: 2016/05/01 06:51:28
    • Location: 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/18 06:37:19 (permalink)
    0
    Thanks, I missed it.

    I'm attempting to apply to this Microchip example where they've attached the inverting to ground. If the non-inverting goes positive that's a logic high, but if it's also pulled to ground how will it be guaranteed a logic low? My experience with comparators is to have an offset voltage (so Vss is for example 0.1V via a DAC) to allow the non-inverting to swing above and below?
     
    Is this where the input offset plays a part?
    post edited by acharnley - 2019/04/18 06:38:44

    Attached Image(s)

    #13
    coffee critic
    Super Member
    • Total Posts : 354
    • Reward points : 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/18 10:20:15 (permalink)
    0
    I agree.  Offset can be either positive or negative.  In this cast the +input would need to be get at least 25mV below ground to insure a switch based on the graphs. 

    n_*$
    #14
    acharnley
    Super Member
    • Total Posts : 270
    • Reward points : 0
    • Joined: 2016/05/01 06:51:28
    • Location: 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/18 10:52:12 (permalink)
    0
    That's what I thought, so the document is factually incorrect.
     
    How did you reach 25mV? If it's +/- 5mV that's a 10mV maximum delta?

    Cheers! Andrew
    post edited by acharnley - 2019/04/18 11:13:12
    #15
    coffee critic
    Super Member
    • Total Posts : 354
    • Reward points : 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/04/18 14:32:47 (permalink)
    0
    I think the 2 FETs connected to Vin should be P channel not N.  Can someone else verify? 

    n_*$
    #16
    stevenpostma
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2012/11/09 09:22:01
    • Location: 0
    • Status: offline
    Re: PIC16F1769 Possible to use Comparator on Two Input Voltages? 2019/05/21 08:31:02 (permalink)
    0
    Use the dedicated comparator pins as shown in the PIN ALLOCATION TABLES on page 5 of the datasheet:
    pins RA0 / C1IN0+  and   RA1  / C1IN0- 
    clear CM1PSEL register --> CxVP connects to CxIN0+ pin
    clear CM1NSEL register --> CxVN connects to CxIN0- pin
    Steven
    #17
    Jump to:
    © 2019 APG vNext Commercial Version 4.5