Hello experts!
I want to implement failure detection for encoder reading on an
F28034. It should catch signal loss for channels A/B and index.
For now I can catch index failures but for A/B channels I got
stuck. Any help appreciated!
The idea was that on every counter over-or underflow there also should
be an index event. So I used this:
/* failure detetction */
if (0 < s16Sign)
{
/* forward, MAX -> 0 must trigger an index event */
/* logical XOR: !a != !b */
if ( !(EQep1Regs.QFLG.bit.IEL) != !(EQep1Regs.QFLG.bit.PCO))
{
/* increase error counter */
s16EncErrCnt++;
}
}
else
{
/* backward, 0 -> MAX must trigger an index event */
/* logical XOR: !a != !b */
if ( !(EQep1Regs.QFLG.bit.IEL) != !(EQep1Regs.QFLG.bit.PCU))
{
/* increase error counter */
s16EncErrCnt++;
}
}
/* clear event flags */
EQep1Regs.QCLR.bit.IEL = 1;
EQep1Regs.QCLR.bit.PCO = 1;
EQep1Regs.QCLR.bit.PCU = 1;
/* end failure detection */
Initialisation follows below.
If there is a loss for the index channel this works because there is
an over-or underflow without index event. But if one of A or B is
absent, it doesn't work. I understand from documentation that IEL is
only triggered if the same relative quadrature transition happens and
the problem is probably that if e.g. there is no channel A we don't
get an index event even if there is the correct index edge.
Is there a flag or another possibility to see if we got an index edge?
My initilisation:
/* QDECCTL defaults to:
QSRC_QUAD_MODE
SOEN_DISABLE
SPSEL_INDEX
XCR_X2
SWAP_DISABLE
IGATE_DISABLE
QAP_NO_EFFECT
QBP_NO_EFFECT
QIP_NO_EFFECT
QSP_NO_EFFECT
i.e. EQep1Regs.QDECCTL.all default completely correct
*/
EQep1Regs.QDECCTL.all = 0;
/* QEPCTL defaults to:
PCRM_INDEX
SEI_DISABLE
SWI_DISABLE
SEL_RISING
QCLM_POSCNT
WDE_DISABLE
*/
EQep1Regs.QEPCTL.all = QEP_EMULATION_FREE |
IEL_SOFTWARE |
IEI_RISING |
QPEN_ENABLE |
UTE_ENABLE;
/* QPOSCTL defaults to:
PCSHDW_DISABLE
PCLOAD_ZERO
PCPOL_HIGH
PCE_DISABLE
PCSPW = 0
i.e. EQep1Regs.QPOSCTL.all default completely correct
*/
EQep1Regs.QPOSCTL.all = 0;
/* QCAPCTL */
EQep1Regs.QCAPCTL.all = CEN_ENABLE | UPPS_X4 | CCPS_X64;
(I also tried IEL_RISING, there the loss detection would be
easier. But then the normal operation would be worse because my index
isn't synchronious to one channel and one edge would be wrong placed.)
Regards
Volker