1 Reply Latest reply on May 3, 2018 9:46 AM by e.pratt_1639216

    AC Mains Zero Crossing detection and controlling LED using interrupt

    ameya_mahajan_2724956

      Hello,

       

      Currently I am doing a project on PSoC 4 CY8CKIT-042-BLE on CYBL11573-56LQXI.

       

      I am using AC Mains 250V, 50 Hz supply and feeding it to my Zero Cross Detector circuit. The ZCD detects the crossing after each cycle (that is, only when the wave crosses from Negative to Positive).

       

      I take the output of this circuit and feed it to the PSoC as an Interrupt.

       

      To sync and test the ZCD I am controlling an LED with varied power levels.

       

      Observations:

       

      1) In 1 second the counter value (no of times Interrupt Handler is executed) should be ideally near 50 for rising edge detection. But I am getting it as 100+

       

      2) This counter value is seen only when, the drive modes of the pin on which interrupt is connected is the following of all combinations:

       

            A) Open Drain, Drives High (Initial State Low)

            B) Open Drain, Drives Low (Initial State High)

            C) High Impedance Digital (Initial State High)

            D) High Impedance Digital (Initial State Low)

       

      And the counter remains 0 (no of times Interrupt handler is executed) on all the remaining drive modes permutation and combinations.

       

      3) When I remove the Male to Male Link (Used to get ZCD Intr on the pin) , the counter value in the 4 working modes mentioned goes Zero.

       

      4) When the male to male link on the PSoC pin is connected but removed from the other end, that is , from the ZCD detection ckt o/p, that is when the other end of the male to male link is in the air, the Counter value comes as 50 in the above mentioned 4 drive modes.

       

      Please see if you can provide any solution so that the the Interrupt runs 50 times in 1 second for 50 Hz AC Supply, and the LED gets controlled as desired.

       

      I am attaching my workspace.

       

      Thank you in advice.

        • 1. Re: AC Mains Zero Crossing detection and controlling LED using interrupt
          e.pratt_1639216

          1) You have the pin set for both edges for interrupting, if you want rising edge, then you will need to change it to rising edge for proper interrupt handling.

          2) You will want to set the pin drive mode to one of the High Impedance Digital States (The IDE doesn't prevent incompatible pin drive versus input modes).

          3) This would be working as expected.

          4) Floating input signals will be pretty random and useless, a floating input signal doesn't help with diagnostics.

           

          You forgot to set your circular counter cc to be volatile (since it is modified in an ISR)

          The LED will always be on from the code in the program, if you want the LED to follow the ZCD, then just set it high/low based on the pin setting to start with. It looks like you were wanting it to "update" the LEDs on/off timing based on a "Power" variable, so I will attempt to do that

           

          To have the LED dim/brighten, you will need to pulse the LED with either the counter in the ISR, or using a PWM to control it's brightness.

          I made changes to the project as I mentioned above, but I am not sure what you were wanting the LED to do. I would assume you can figure that out once the ISR is working properly however.