Interrupts PSoC Creator

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
nilo_4761906
Level 1
Level 1

Hello,

We have a problem with interrupts in PSoC Creator.
We have a Rotary Encoder (ec12e), which gives to staggered pulses when we rotate it. To see if it rotates clockwise or anti-clockwise, we want to read one of the signals just after they are not both low anymore, see the picture.

Skærmbillede 2020-10-02 141649.png

Therefore we have put in an NOR gate, which gives a high when both signals go low. We want a interrupt on the falling edge of the signal from the NOR-gate.
Unforturnately, we get three interrupts - which makes us think that the interrupt isn't on the falling edge, but is just random.

Do you have any suggestions as to how we can get an interrupt on the falling edge?Skærmbillede 2020-10-02 142324_1.png

Best regards Nikolaj

0 Likes
1 Solution
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Nikolaj,

You can use TCPWM component in Quadrature decoder mode readily available in PSoC Creator.

For this you just have to connect the Signal A and Signal B to the Phi_A and Phi_B pins of the Quadrature decoder component.

Please use this already available code example for your purpose:

https://www.cypress.com/documentation/code-examples/ce220799-psoc-6-mcu-direction-detection-using-qu...

If you are using PSoC 4 here is the link for code example:

https://www.cypress.com/documentation/code-examples/ce195354-psoc-4-quadrature-decoder

Hope this information helps !

Thanks

Ganesh

View solution in original post

5 Replies
Kenshow
Level 8
Level 8
Distributor - Marubun (Japan)
50 solutions authored 25 solutions authored 10 solutions authored

Hi Nikolaj,

In the figure you show, you can simply use the rising edge of Signal A as an interrupt.

Since this Rotary Encoder determines the direction of rotation by setting either signal to HIGH after two signals are LOW?

Can you check what the waveform looks like depending on the direction of rotation of the rotary?

Probably, I think that it is better to interrupt by the rising edge of the two signals at OR, then monitor the status of either signal A or B.

Regards,

Kenshow

VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi Nikolaj,

You can use TCPWM component in Quadrature decoder mode readily available in PSoC Creator.

For this you just have to connect the Signal A and Signal B to the Phi_A and Phi_B pins of the Quadrature decoder component.

Please use this already available code example for your purpose:

https://www.cypress.com/documentation/code-examples/ce220799-psoc-6-mcu-direction-detection-using-qu...

If you are using PSoC 4 here is the link for code example:

https://www.cypress.com/documentation/code-examples/ce195354-psoc-4-quadrature-decoder

Hope this information helps !

Thanks

Ganesh

odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Nikolai,

There is a custom community component for interfacing this type of encoders

Quad Decoder with Button Switch component for rotary shaft encoders

/odissey1

encoder_01b.png

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Nicolaj,

It appears from your original post that you are trying to avoid getting an interrupt when both inputs are LOW.

You've place a NOR gate (combinatorial logic) in front of the two quadrature signals to try to accomplish this.

Without seeing your circuit, this is my take on what is happening:

  • Combinatorial NOR logic IS NOT clocked.  This means that if one (or both inputs) change, the output of the NOR will reflect the new logic within about 10 to 20 nsec..
  • I know what you're thinking.  You only expect to have one input change at a time on rotational movement.  In the case of a rotary quad encoder you are right BUT you are not considering switch debounce.  Most quadrature encoders still use mechanical switches to toggle the A and the B outputs.   Switches are notorious for mechanical 'bouncing' the outputs   This means that for every switch A or B transition, you will see one or more switch transitions FROM THE SAME output!  This is most likely where you are getting
    we get three interrupts

There are ways to significantly address this.

  • Place a debounce circuit after the A and B input with as low a clocking frequency you can tolerate.  (For most applications a 100Hz should suffice.) This will significantly minimize the multiple switch transitions by synchronizing the output of the debounce circuit to filter out the unwanted extra transitiions.   In this case you should be able to keep the NOR AFTER the debounce circuit. 
    Based on the PSoC part you have chosen, this option will not be possible DIRECTLY.  This option requires a PSoC with UDB resources.
    I've looked again at your first post.  You are using a "Double-sync" for each input which is very good, however, the switch bouncing frequency will probably be much lower than the clocking frequency of the input (BUS_CLK) x2.
  • I believe the Quadrature Decoder has a input debounce built in.
  • Ignore the NOR gate and process each switch transition in SW.   You can still put a debounce circuit in the signal front-end (adviced) or you can perform a SW debounce.

To verify the 'bouncing' of the inputs and the resultant NOR output transitions, I recommend using a 3-input scope.  Monitor the A and B inputs and route the NOR output to a PSoC pin to see the results.

Len

Len
"Engineering is an Art. The Art of Compromise."

This is a good answer.... definitely use the quadrature decoder in the chip which was put there just for this application.

The multiple interrupts are caused by bounce.

For sure could use the glitch filter to debounce.

Could use software to debounce

Did Nilo use an external nor gate?  That could be done in the UDB as well.

But the best answer is just use the quadrature decoder.

Alan

0 Likes