POSIF : How to generate an event when the encoder moves past a defined position ?

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

cross mob
Not applicable
Hi everyone,

I am using a linear quadrature encoder and I need trigger an event when the position / count changes by a defined amount (for example a 0.5 mm increase in position).

Is there a hardware comparator feature in the POSIF ?

I would like the system should operate as follows...

1) Read linear encoder position / count
2) Add an offset to the position / count and store in a comparator register
3) When the linear encoder position exceeds the comparator register value, generate an event.

Any suggestions would be very much appreciated.

Thank you in advance.
Best regards
Aaron
0 Likes
4 Replies
User8819
Level 4
Level 4
Hi,

You cannot do it directly in POSIF. But use POSIF "clock" output in CCU4. There you can generate compare events you want.

rum
0 Likes
User6793
Level 4
Level 4
Here is a snippet to get you started.
It is based on the DAVE POSQE001 APP.
We use this feature to report an 'almost there' event and also as a motion detector.
Note that your shaft must be perfectly still when setting a new compare value, or else you risk losing counts.


void RotaryEncoder::setReportAngle(uint32_t hostIdentifier, uint32_t angleX100, rotReportDirs dirs) {
uint32_t position = angleX100;


if (false == m_invertReadings)
position = 36000 - position;

position *= m_GEAR_TICKS_PER_REVOLUTION;
position /= 36000;

m_angleReportHostIdentifier = hostIdentifier;

if (false == m_reportAngleEnabled) {
m_reportAngleEnabled = true;
// enable compare irqs
switch (dirs) {
case countingUp:
if (POSQE001_EnableEvent(posQeHandle_, POSQE001_POSITION_COUNTER, POSQE001_CCU_UP_COMPARE_MATCH) != (uint32_t)DAVEApp_SUCCESS)
panic(PANIC_USER, "Enable failed!\n");
break;
case countingDown:
if (POSQE001_EnableEvent(posQeHandle_, POSQE001_POSITION_COUNTER, POSQE001_CCU_DOWN_COMPARE_MATCH) != (uint32_t)DAVEApp_SUCCESS)
panic(PANIC_USER, "Enable failed!\n");
break;
case countingUporDown:
if (POSQE001_EnableEvent(posQeHandle_, POSQE001_POSITION_COUNTER, POSQE001_CCU_UP_COMPARE_MATCH) != (uint32_t)DAVEApp_SUCCESS)
panic(PANIC_USER, "Enable failed!\n");
if (POSQE001_EnableEvent(posQeHandle_, POSQE001_POSITION_COUNTER, POSQE001_CCU_DOWN_COMPARE_MATCH) != (uint32_t)DAVEApp_SUCCESS)
panic(PANIC_USER, "Enable failed!\n");
break;
default:
break;
}
}


// Request an immediate shadow Transfer.
posQeHandle_->CCUSliceConfigPtr[0]->SliceAddress->TCCLR = 1;
__DSB();
posQeHandle_->CCUSliceConfigPtr[0]->SliceAddress->CRS = position;
CCU40->GCSS = CCU4_GCSS_S1SE_Msk;
posQeHandle_->CCUSliceConfigPtr[0]->SliceAddress->TCSET = 1;


}
0 Likes
Not applicable
Thank you Rum !
0 Likes
Not applicable
Thank you very much OMR. Very helpful.
0 Likes