• AVR Freaks

Hot!dsPIC33EP512MU810 : Internal Comparator problem..

Author
TS9
Super Member
  • Total Posts : 879
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
2020/08/01 02:21:31 (permalink)
0

dsPIC33EP512MU810 : Internal Comparator problem..

Hi,
 
I am using dsPIC33EP512MU810 PIM with Explore Board and  trying to use Internal Comparator of dsPIC33EP to Detect Zero Crossing .
I am feeding signal as below:
C2IN2-      10ms Full Wave rectified  waveform  +2.5V (Apporx.) .
C2IN1+     Ground Internal
 
As per below Code .

// Comparator 83 Number C2IN1+ for Comparator
// RPOR15bits.RP127R  =  25  ;     // RG15 (CM3OUT ) Pin 1
void Comparator2Enable()
{
// STEP : 1
// C2IN1+
// Comparator Enable
CM2CONbits.CON = 1 ;

// STEP : 2
// CCH<1:0>:Comparator Channel Select bits
// 00 = VIN- input of comparator connects to CxIN2-
// Channel Select Page 442
CM2CONbits.CCH = 0b00 ;
// STEP : 3 Page 442
// CREF:Comparator Reference Select bit internal CVREFIN voltage
// VRef Select
CM2CONbits.CREF = 1 ;
// STEP : 4
// CVROE:Comparator Voltage Reference Output Enable bit
// Page 448
CVRCONbits.CVREN = 1 ;

// Page 448 Datasheet
// IVref= 2.20
CVRCONbits.BGSEL = 0x11;

// Comparator event did not occur
// Page 441
CM2CONbits.CEVT = 1 ;
// Trigger/Event/InterruptPolarity Select bits Disable
// Page 441
// CM2CONbits.EVPOL = 0b01 ;
// Comparator Output Polarity Select bit
CM2CONbits.CPOL = 0 ;

// Comparator output is present on the C2OUT pin COE
// *************Sunrise
CM2CONbits.COE = 1 ;
// 0 = CVREFIN is generated by the resistor network
_VREFSEL = 0 ;
// CVRSS: Comparator Voltage Reference Source Selection bit
// Comparator voltage reference source, CVRSRC = AVDD – AVSS
_CVRSS = 0 ;

_CVROE = 0 ;
// Comparator Interrupt
// _CMIE = 1 ;
// _CMIF = 0 ;
}

 
But I could not get proper ZCD . Please Check attachments on DSO.
 
--
TS9
 
 

Attached Image(s)

#1

10 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28011
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: dsPIC33EP512MU810 : Internal Comparator problem.. 2020/08/01 16:22:36 (permalink)
    0
    TS9
    But I could not get proper ZCD . Please Check attachments on DSO.

    What does this mean?
    What would you regard as a "proper" ZCD?
    It is always best to actually explain what you expected, and how that compares to what you observed.
    Don't expect it to be obvious just from some uncommented DSO traces.
     
    I would be very dubious about using ground as the reference. Most comparators require the signal to go below your reference to switch, but the PIC's opamp is not designed to handle anything below ground.
     
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    davea
    Super Member
    • Total Posts : 278
    • Reward points : 0
    • Joined: 2016/01/28 13:12:13
    • Location: Tampa Bay FL USA
    • Status: offline
    Re: dsPIC33EP512MU810 : Internal Comparator problem.. 2020/08/01 20:39:42 (permalink)
    4 (1)
    it looks like it working just fine...
    did you expect something different ?
    50Hz not 100Hz
     
    #3
    TS9
    Super Member
    • Total Posts : 879
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP512MU810 : Internal Comparator problem.. 2020/08/01 22:04:42 (permalink)
    0
    Hi,
     
    Thanks Both of you.. 
     
    Can I expect square wave output with dsPIC33EP Comparator as attachment ?
    But Rising and falling Edges of square should be w.r.t zero value of full wave rectified wave ?
     
    --
     TS9
    post edited by TS9 - 2020/08/01 22:05:43

    Attached Image(s)

    #4
    ric
    Super Member
    • Total Posts : 28011
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: dsPIC33EP512MU810 : Internal Comparator problem.. 2020/08/01 22:51:58 (permalink)
    0
    To do that, you would need a non-rectified signal, scaled and shifted to fit within 0 to Vdd, and set your comparator threshold to the shifted "zero" level.
    or, you could divide that existing signal by two, but that appears to be triggering a little before your real zero.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    TS9
    Super Member
    • Total Posts : 879
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP512MU810 : Internal Comparator problem.. 2020/08/01 23:21:51 (permalink)
    0
    Hi, 
     
    I have Sin wave 0 to 3.0V as attachment..But I think this could damage MCU or comparator's pin ..
    Is this I have to fed that ..??
     
    --
    TS9
     

    Attached Image(s)

    #6
    ric
    Super Member
    • Total Posts : 28011
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: dsPIC33EP512MU810 : Internal Comparator problem.. 2020/08/01 23:51:14 (permalink)
    4 (1)
    The indicated value is 3V RMS.
    Where is the zero voltage?
    What is the actual minimum and maximum peak voltage of that waveform? That is what really matters.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    TS9
    Super Member
    • Total Posts : 879
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP512MU810 : Internal Comparator problem.. 2020/08/02 00:28:20 (permalink)
    0
    Hi,
     
     
    I have changed resistor divider . Now peak to peak down to 1.44V ..
     
    "Where is the zero voltage?"
    -Means?
     
    Can I fed this to dsPIC33EP Comparator Input Pin..
     
    --
    TS9
    post edited by TS9 - 2020/08/02 00:29:53

    Attached Image(s)

    #8
    ric
    Super Member
    • Total Posts : 28011
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: dsPIC33EP512MU810 : Internal Comparator problem.. 2020/08/02 00:42:22 (permalink)
    5 (1)
    You're not listening.
    Peak to peak voltage, and RMS voltage are not the most important thing.
    The actual lowest voltage at the PIC pin must not be below 0V.
    The actual highest voltage at the PIC pin must not be above Vdd.
     

    "Where is the zero voltage?"
    -Means?

    That means for this to work, you must shift the whole voltage waveform up so the bottom of the signal does not go below 0V. That means your "zero crossing" is now at some positive voltage.
    THAT is what I meant by "where is the zero voiltage?"
    There is no vertical scale on your scope plot.
     
     
    post edited by ric - 2020/08/02 00:43:29

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    TS9
    Super Member
    • Total Posts : 879
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: dsPIC33EP512MU810 : Internal Comparator problem.. 2020/08/02 00:52:43 (permalink)
    2 (1)
    Thanks ..
     
    I think .. It's better to use  external "sin to square wave converter" with opamp and fed that's output to
    External Interrupt or Input Change Interrupt rather to design  rather than external circuit "to shift the whole voltage waveform up so the bottom of the signal does not go below 0V"
     
    Any ways Thanks for your concern..
     
    --
    TS9
    #10
    davea
    Super Member
    • Total Posts : 278
    • Reward points : 0
    • Joined: 2016/01/28 13:12:13
    • Location: Tampa Bay FL USA
    • Status: offline
    Re: dsPIC33EP512MU810 : Internal Comparator problem.. 2020/08/02 16:12:04 (permalink)
    0
    TS9
    I think .. It's better to use  external "sin to square wave converter" with opamp 

    I think you will find it one the same (with "extra" external opamp )
     
     
    post edited by davea - 2020/08/02 16:55:56

    Attached Image(s)

    #11
    Jump to:
    © 2020 APG vNext Commercial Version 4.5