I'm trying to trigger an interrupt any time an encoder position changes, and it looks like the
enc_config_t.positionMatchMode =
kENC_POSMATCHOnReadingAnyPositionCounter inititialization setting should cause the interrupt to trigger, but it does nothing. I confirmed in ENC_Init that setting positionMatchMode sets the
ENC_CTRL2_OUTCTL_MASK, but it doesn't change the behaviour, I only get an interrupt when the position is equal to position compare.
Is this a hardware bug? Can someone with this board check?
/* Initialize the ENC module. */
enc_config_t mEncConfigStruct;
ENC_GetDefaultConfig(&mEncConfigStruct);
mEncConfigStruct.positionMatchMode = kENC_POSMATCHOnReadingAnyPositionCounter;
ENC_Init(ENC1, &mEncConfigStruct);
ENC_DoSoftwareLoadInitialPositionValue(ENC1); /* Update the position counter with initial value. */
NVIC_SetPriority(ENC1_IRQn, MAX_INTERRUPT_PRIORITY);
EnableIRQ(ENC1_IRQn);
ENC_EnableInterrupts(ENC1, kENC_PositionCompareInerruptEnable);c
The POSMATCH signal is the same one triggering the CMPIE (COMPARE MATCH) interrupt, right?
Is there any simple way to trigger an interrupt when the position changes? This seems like an obvious feature. I'm going to try wiring the POSMATCH signal in to a GPIO but that seems like an unnecessary workaround.
1. The POSMATCH signal is the same one triggering the CMPIE (COMPARE MATCH) interrupt, right?
No, POSMATCH signal is the position match output, it own't triggering CMPIE.
But when the compare matches the COMP, the compare interrupt request flag is set, then the POSMATCH output is asserted, please note, not the POSMATCH output trigger the CMPIE.
2. Is there any simple way to trigger an interrupt when the position changes?
You can check the GPIO interrupt code in the SDK, as you know the POSMATCH will output the signal.
Wish it helps you!
If you still have questions about it, please kindly let me know.
Have a great day,
Kerry
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Okay, thanks. Having to use two extra GPIO pins just to send/receive posmatch to trigger an interrupt makes it basically useless to me, I just wrote my own simple driver using an interrupt on the encoder phase a.
Thanks
Ben
Were you able workaround your issue and get an interrupt fired whenever the position changes?
POSMATCH can be connected to other SoC resources, just as the reference manual described:
If you don't want to use the external GPIO, maybe you can consider to use the POSMATCH output to tigger the timer channel, then use the timer interrupt, you can set the timer is very small.
Have a great day,
Kerry
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
That’s exactly the same route I ended up taking. A custom encoder library based on GPIO and interrupts... I didn’t use the ENC module at all because it didn’t have this interrupt capability.
Hi BENJAMIN OLAYINKA ,
RT1050 chip ENC module can support the following interrupt:
So, when you use the posmatch, do you want to get the compare match interrupt?
When you posmatch happens, do you check the CTRL[CMPIRQ], is it set or not?
Have a great day,
Kerry
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Any updates on this? I asked a similar question awhile ago: https://community.nxp.com/thread/503445 but I didn't know this OUTCTL option could allow interrupts on any position change.
I ended up abandoning the ENC peripheral and writing my own encoder library using GPIO and interrupts so I could generate interrupts whenever the encoder position changes, but I would love to go back to using the ENC.
Hi Jack King,
What's your detail problem?
I find you didn't follow up your own post.
As I know, OUTCTL can't trigger the ENC interrupt directly. As you know, the ENC just have these interrupt:
But I didn't find the OUTCTL triggered interrupt, so my thought is the same as you, can use OUTCTL associate with the GPIO input interrupt.
Have a great day,
Kerry
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hi Kerry,
I get the CMPIRQ interrupt when POS is equal to POSCOMPARE (initialized as -1 in the default settings).
In the data sheet and in the source, it looks like setting the OUTCTL bit should change the POSMATCH function so that it fires ANY TIME a position register is read. I want an interrupt to fire any time the position changes, but setting OUTCTL isn't making that happen. Basically, the OUTCTL bit seems to do nothing.
Is there a simpler way to get an interrupt any time the encoder position changes?
Even you modify the OUTCTL to 1, but this bit can't fire the interrupt directly, it just can make POSMATCH pulses when the UPOS, LPOS, REV, or POSD registers are read.
Just as the interrupt list for ENC which I give you, it doesn't have the PSMATCH pulse interrupt.
But, if you want the PSMATCH pulse to trigger the interrupt, I think you can connect this signal to another external interrupt, then when the PSMATCH pulse happens, then that interrupt happens, take use the PSMATCH to trigger another gpio interrupt, but you need to connect your PSMATCH to the related gpio input pin.
You can try it.
If you still have questions about it, please kindly let me know.
Have a great day,
Kerry
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
I just tried it as well, and I didn't ever see the interrupt generated.
I do get the interrupt, but only when POS = POSCOMPARE, which is initialized to -1 in the default settings. I would like to get an interrupt any time the position changes.
void ENC_GetDefaultConfig(enc_config_t *config)
{
...
//changing positionMatchMode should set OUTCTL and fire an interrupt any time position changes.. but it doesn't
config->positionMatchMode = kENC_POSMATCHOnPositionCounterEqualToComapreValue;
config->positionCompareValue = 0xFFFFFFFFU;
}