• AVR Freaks

Hot!External pulse edge detecction

Author
vibhu
Starting Member
  • Total Posts : 86
  • Reward points : 0
  • Joined: 2019/02/25 05:37:34
  • Location: 0
  • Status: offline
2019/07/17 06:22:10 (permalink)
0

External pulse edge detecction

Hi Guys,
 
I have a Zero cross detection IC which is generating a  clock pulse every 20ms.
It is connected to RA7 of the PIC32mz1024EFE100.
 
I wanted to trigger a relay at the rising edge of the clock pulse.
 

int init()
{
    if(PLIB_PORTS_ExistsChannelChangeNoticeMethod(PORTS_ID_0) == true)
{
    if(PLIB_PORTS_ExistsChangeNoticeEdgeControl(PORTS_ID_0) == true)
{
    PLIB_PORTS_ChannelChangeNoticeMethodSelect(PORTS_ID_0,PORT_CHANNEL_A,PORTS_CHANGE_NOTICE_METHOD_EDGE_DETECT);
    PLIB_PORTS_ChannelChangeNoticeEdgeEnable(PORTS_ID_0,PORT_CHANNEL_A,0x0080,0x0000);
 }
else
   return;
}
else
return;
}
 
In main:
 
if(PLIB_PORTS_PinChangeNoticeEdgeHasOccurred(PORTS_ID_0,PORT_CHANNEL_A,PORTS_BIT_POS_7))
{
LATBbits.LATB8 = 1;
}
 

 
I am able to trigger the relay but it is not triggering at every rising edge. It is triggering randomly.
Is the way I am using wrong ? Is there any other method t check and trigger ?
Should I add anything else ?
 
Regards,
Vibhu.
#1

11 Replies Related Threads

    vibhu
    Starting Member
    • Total Posts : 86
    • Reward points : 0
    • Joined: 2019/02/25 05:37:34
    • Location: 0
    • Status: offline
    Re: External pulse edge detecction 2019/07/17 21:38:38 (permalink)
    0
    Guys please help !
     
    #2
    vibhu
    Starting Member
    • Total Posts : 86
    • Reward points : 0
    • Joined: 2019/02/25 05:37:34
    • Location: 0
    • Status: offline
    Re: External pulse edge detecction 2019/07/17 23:39:43 (permalink)
    0
    Should it be in interrupt pin to use these functions or can we use it in normal GPIO pins ?
    #3
    MisterHemi
    Senior Member
    • Total Posts : 137
    • Reward points : 0
    • Joined: 2017/11/02 12:24:21
    • Location: Commerce, CA USA
    • Status: offline
    Re: External pulse edge detecction 2019/07/18 05:15:23 (permalink)
    0
    I haven't used it yet but I suppose "interrupt on change" would be what you'd want to use.
     
    However i'm concerned about the random triggers, have you looked at the input signal?
    Maybe it's not a clean signal (similar to a debounce problem) or the voltage thresholds aren't correct.
     
    Have you taken a look at the input signal with an oscilloscope?

    My configuration:
    MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS High Sierra (10.14.5) and MPLAB X IDE v5.20
     
    Curiosity PIC32MZ EF, PIC24F Curiosity, XPRESS EVAL BOARD (PIC16F18855), SAMA5D3 Xplained and various custom boards.
    #4
    vibhu
    Starting Member
    • Total Posts : 86
    • Reward points : 0
    • Joined: 2019/02/25 05:37:34
    • Location: 0
    • Status: offline
    Re: External pulse edge detecction 2019/07/18 21:43:06 (permalink)
    0
    Hi,
     
    I have attached the image of the zero cross pulse. The pulse width is ~30us. The yellow wave is the zero cross wave.

    Attached Image(s)

    #5
    vibhu
    Starting Member
    • Total Posts : 86
    • Reward points : 0
    • Joined: 2019/02/25 05:37:34
    • Location: 0
    • Status: offline
    Re: External pulse edge detecction 2019/07/18 21:50:22 (permalink)
    0
    I have even changed the code according to the Input change notification given in the data sheet (attached screenshot).
     

     
    /* INTERRUPT SETTING */
    CNPUAbits.CNPUA6 = 1;
    CNCONAbits.ON = 1;
    CNCONAbits.EDGEDETECT = 1;
    CNENAbits.CNIEA6 = 1;
    CNNEAbits.CNNEA6 = 0;
    INTCONSET = _INTCON_MVEC_MASK;
    __builtin_enable_interrupts();
    /* INTERRUPT SETTING */

     

    void __ISR(_CHANGE_NOTICE_A_VECTOR, ipl1AUTO) _IntHandlerChangeNotification_PortA(void)
    {
    LATDbits.LATD1 = 1;
    delay_ms(220);
    LATDbits.LATD1 = 0;
    delay_ms(5000);
    LATFbits.LATF2 = 1;
    delay_ms(220);
    LATFbits.LATF2 = 0;
    delay_ms(220);
    PLIB_INT_SourceFlagClear(INT_ID_0,INT_SOURCE_CHANGE_NOTICE_A);
    }

     
    But this code is also not working. The relay is triggering randomly and not at the zero cross. The zero cross pulse comes for every 20ms.

    Attached Image(s)

    #6
    vibhu
    Starting Member
    • Total Posts : 86
    • Reward points : 0
    • Joined: 2019/02/25 05:37:34
    • Location: 0
    • Status: offline
    Re: External pulse edge detecction 2019/07/22 01:10:34 (permalink)
    0
    Any other method to detect the rising and falling edge? Should I enable any other option?
    #7
    oliverb
    Super Member
    • Total Posts : 204
    • Reward points : 0
    • Joined: 2009/02/16 13:12:38
    • Location: 0
    • Status: offline
    Re: External pulse edge detecction 2019/07/22 01:45:54 (permalink)
    0
    Purely for diagnostic purposes could you try rapidly copying the input state to an output pin so you can plot it directly?
     
    #8
    vibhu
    Starting Member
    • Total Posts : 86
    • Reward points : 0
    • Joined: 2019/02/25 05:37:34
    • Location: 0
    • Status: offline
    Re: External pulse edge detecction 2019/07/22 06:08:02 (permalink)
    0
    Hi Oliver,
    I didn't understand what you want me to do. Can you please explain?
    #9
    ric
    Super Member
    • Total Posts : 23185
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: External pulse edge detecction 2019/07/22 13:23:09 (permalink)
    0
    He meant to add some code in a tight loop, reading the state of the input pin, and copying it to an output pin so you can observe it.
     

    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!
    #10
    vibhu
    Starting Member
    • Total Posts : 86
    • Reward points : 0
    • Joined: 2019/02/25 05:37:34
    • Location: 0
    • Status: offline
    Re: External pulse edge detecction 2019/07/26 00:16:34 (permalink)
    0
    Hi ric , oliverb,
     
    You mean using PORT to read the state of the zero cross detection pin and using LAT to write it to any output pin ?
    you want me to check whether both are same ?
     
     
    #11
    ric
    Super Member
    • Total Posts : 23185
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: External pulse edge detecction 2019/07/26 00:45:07 (permalink)
    0
    Yes.

    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!
    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5