Hot!comparator using to detect zero cross

Author
egemen
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2008/03/05 10:46:11
  • Location: 0
  • Status: offline
2009/02/20 14:26:47 (permalink)
0

comparator using to detect zero cross

"If I have a on-chip analog comparator, I can set the comparator internal reference to 0V (just select internal comparator VREF and turn off the VREF module). Then I can use a AC wave connected to the comparator input. using a series limiting resistor and 2 low-leakage current schottky diodes in antiparallel to limit the AC voltage to {-250mV..+250mV} ,I have a clean simetrical zero cross interrupt with less than a few microseconds of phase delay." I use 18458.Can u recommend a schottky diode or other solution.
Thanks.
 
 
#1

11 Replies Related Threads

    dchisholm
    Super Member
    • Total Posts : 3805
    • Reward points : 0
    • Joined: 2003/12/14 15:30:12
    • Location: St Louis Mo
    • Status: offline
    RE: comparator using to detect zero cross 2009/02/20 18:30:04 (permalink)
    0
    If everything is properly current limited I suppose most any small-signal Schottky like a BAS70 or BAT54 will do the job.  Make sure the comparator's common-mode range extends at least to the negative supply rail.

    Dale
    #2
    egemen
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2008/03/05 10:46:11
    • Location: 0
    • Status: offline
    RE: comparator using to detect zero cross 2009/02/20 22:47:26 (permalink)
    0
     I cannot use a negative supply.It is my restriction.I expect that if negative half of ac signal is limited around -0.3 volt, ı can detect zero cross passin from negative to positive level. 
    #3
    DSchabel
    Super Member
    • Total Posts : 1714
    • Reward points : 0
    • Joined: 2005/05/24 14:00:34
    • Location: Western NY State
    • Status: offline
    RE: comparator using to detect zero cross 2009/02/21 14:50:17 (permalink)
    0
    ORIGINAL: egemen

     I cannot use a negative supply.It is my restriction.I expect that if negative half of ac signal is limited around -0.3 volt, ı can detect zero cross passin from negative to positive level. 

    Won't be reliable. 
     
    The CM voltage is 0V, fine.  But there's an input offset voltage of up to 10mV, so to absolutely guarantee that this will work, you need to work at 10mV or higher.  IOW, if your referrence is 0V (not sure if this will work, either), in order for your comparator to guarantee to "turn off" you need to drive it with -10mV.  But the comparator may not "see" any voltage below 0V. 
     
    The solution is to sum a small voltage into your input signal. 
     
     

    Attached Image(s)

    #4
    P Lameijn
    Super Member
    • Total Posts : 1949
    • Reward points : 0
    • Joined: 2004/01/22 18:30:23
    • Location: The Netherlands
    • Status: offline
    RE: comparator using to detect zero cross 2009/02/21 16:48:31 (permalink)
    0
    You don't have to go to zero level. Just use capacitor and set VRef to approx. 1/2 Vcc. Wih the 2.5K resistor you can set sensitivity. (With 2.5K it's 5mV...)
    The 100K you can change according to the level of the AC voltage.

                                --------------
                                |
                           o----o VRef
                           |    |
                           o    |
                     2K5* .-.   |
                          | |   |
                          | |   |
        100nF    100k     '-'   |
                           o    |
          ||       ___     |    |
      o--o||-o---o|___|-o--o----o RA1 (comp)
     In   ||               |    |
                           o    |
                          .-.   |
                      1M  | |   |
                          | |   |
                          '-'   |
                           |    |
                           o    |   16F648A
                           |    |
                           o    |
                           |    |
                          ===   |------------
                          GND


    Regards,
    Peter
    #5
    Andy99
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2018/09/12 06:24:53
    • Location: 0
    • Status: offline
    Re: RE: comparator using to detect zero cross 2018/09/13 00:07:47 (permalink)
    0
    Hello everyone!
     
    I will reuse this thread, due to similar problem. I would like to use internal comparator for zero-cross detection on input signal ~24V@50Hz. PIC is running on 8MHz internal oscillator.
     
    I was trying to use external interrupt to detect this. But there was a really big delay between crossing and detection. 5ms, what is unacceptable for 1/50=20ms period. After that I have figured out, there should be something wrong. Missing Schmidt IC on pins. External interrupt couldn't detected this type of edge. So I have changed input signal to square for verification. After that delay was minimized to 4us, what is really good. When I compared it with previous one. I was thinking if there is no some better solution how to detect it.
     
    So, I have some open questions regarding to this problematic.
    1. Is it a good solution to use external interrupt on edge?
     - Use similar schematic like this  or with opto-isolator
    2. Or is it better to use comparator for zero-cross detection?
     - This is the reason, why I have re-used this thread. How I can connect it?
     - How should I set up registers for it? It will be used on 32-bit PIC with 3v3TTL. But for testing, I can use it, let say on PIC18F25k50.
     
    Many thanks for any advice :).
    #6
    P Lameijn
    Super Member
    • Total Posts : 1949
    • Reward points : 0
    • Joined: 2004/01/22 18:30:23
    • Location: The Netherlands
    • Status: offline
    Re: RE: comparator using to detect zero cross 2018/09/21 05:45:33 (permalink)
    0
    Hello Andy,
     
    Using optocoupler or not depends on the situation.
    If the AC to be tested is coupled to the DC ground then isolation isn't needed.
    Without optocoupler, you can send AC directly to compatator input (zener is for protection)
     
     

    Attached Image(s)


    Regards,
    Peter
    #7
    Andy99
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2018/09/12 06:24:53
    • Location: 0
    • Status: offline
    Re: RE: comparator using to detect zero cross 2018/09/21 06:09:54 (permalink)
    0
    P Lameijn
    Using optocoupler or not depends on the situation.
    If the AC to be tested is coupled to the DC ground then isolation isn't needed.

    First, thank for your response.
    I know about the non-isolation. I was thinking, what is better to use. Some transistor and check the square edge with external interrupt or not. Lets think if the comparator usage is better or not.
     
    How I can use/set the comparator?

    post edited by Andy99 - 2018/09/21 06:15:42

    Attached Image(s)

    #8
    P Lameijn
    Super Member
    • Total Posts : 1949
    • Reward points : 0
    • Joined: 2004/01/22 18:30:23
    • Location: The Netherlands
    • Status: offline
    Re: RE: comparator using to detect zero cross 2018/09/21 06:29:30 (permalink)
    0
    Set other comparator input to use DAC output. (CMxCON0.CxR = 1, CMxCON0.CxON = 1)
    Set CMxCON1.CxRSEL to 0
    Enable DAC (VREFCON1.DACEN = 1)

    Regards,
    Peter
    #9
    Andy99
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2018/09/12 06:24:53
    • Location: 0
    • Status: offline
    Re: RE: comparator using to detect zero cross 2018/09/21 06:52:42 (permalink)
    0
    P Lameijn
    Set other comparator input to use DAC output. (CMxCON0.CxR = 1, CMxCON0.CxON = 1)
    Set CMxCON1.CxRSEL to 0
    Enable DAC (VREFCON1.DACEN = 1)



    Ok fine, what about the HW connection? Do I need to some somehow connect the pin? I mean some connection to R divider over another resistor ('?' on my picture) ?
     
    Correct me please, if I am wrong.
    CMxCON0.CxR = 1 will connects CxVIN+ to CxVref internally
    CMxCON1.CxRSEL = 0 DAC routes to CxVref internally
    -------------------
    ? VREFCON1.DACOE = 0 to disconnect physically output pin
    ? VREFCON1.DACPSS = 1 use FVR BUF1 output as positive source
    ? VREFCON1.DACNSS = 0 use VSS as negative source
    ? VREFCON2.DACR = Which voltage value needs to be used?
    #10
    P Lameijn
    Super Member
    • Total Posts : 1949
    • Reward points : 0
    • Joined: 2004/01/22 18:30:23
    • Location: The Netherlands
    • Status: offline
    Re: RE: comparator using to detect zero cross 2018/09/21 07:17:04 (permalink)
    0
    The connection to DAC is internal, so the comparator '+' isn't connected externally.
    VREFCON1.DACOE, VREFCON1.DACPSS, VREFCON1.DACNSS Are default zero and stay that way
    VREFCON2.DACR bits are also default zero (DAC output = 0v) and stay that way

    Regards,
    Peter
    #11
    Andy99
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2018/09/12 06:24:53
    • Location: 0
    • Status: offline
    Re: RE: comparator using to detect zero cross 2018/09/23 09:48:13 (permalink)
    0
    I have modified my previously used testing project to use new changes. Tested only via simulator. After applying DAC changes, LED blinked only 4 times. Interrupt is never been called, so there should be something wrong/missing.
    #define LED LATAbits.LATA0

    void interrupt isr(void) {
       if (PIE2bits.C1IE && PIR2bits.C1IF) {
          LED ^= 0x1;
          PIR2bits.C1IF = 0x00;
       }
    }
     
    void main(void) {
       SetupClock();
       InitIO();

       // disable FIXED VOLTAGE REFERENCE
       VREFCON0bits.FVREN = 0x00;

       // set DAC to 0
       VREFCON2bits.DACR = 0x00;
       // enable DAC module
       VREFCON1bits.DACEN = 0x01;

       // enable comparator peripheral
       PMD1bits.CMP1MD = 0x00;
       // set CxOUT as internal
       CM1CON0bits.C1OE = 0x00;
       // set comparator reference to CxVREF
       CM1CON0bits.C1R = 0x01;
       // select C12IN1- channel
       CM1CON0bits.C1CH = 0x01;
       // router DAC to C1VREF
       CM2CON1bits.C1RSEL = 0x00;
       // clear interrupt  flag
       PIR2bits.C1IF = 0x01;
       // enabling interrupt
       PIE2bits.C1IE = 0x01;

       LED = 0x00;

       // only for test, blink LED
       for(uint8_t i=0;i<4;i++) {
          LED ^= 0x01;
          Delay100times(__delay_ms(10););
       }

       // enable global interrupt
       INTCONbits.GIE=0x01;
       // enable peripheral interrupt
       INTCONbits.PEIE=0x01;

       while (1) {
       }

       return;
    }

    post edited by Andy99 - 2018/09/23 09:50:05

    Attached Image(s)

    #12
    Jump to:
    © 2018 APG vNext Commercial Version 4.5