Hi, based on the example bellow http://www.lothar-miller.de/s9y/categories/46-Encoder i need to use the INDEX input of the encoder, sometimes. From what i understand, when needed, the INDEX pulse should clear the position counter. Is it as simple as this? double register INDEX input

dr_INDEX <= dr_INDEX(0) & INDEX when rising_edge(CLK); |

Have an Enable input, and

-- index allow to clear count if ENA then if dr_INDEX = "01" then p <= 0; end if; end if; |

T

SparkyT wrote: > Is it as simple as this? You're on the right way... I would also check wether the counter value is (nearby) 0 at that point. Because when not, then you have lost counts in the previous round. That may be a reason to raise an ERROR flag.

:
Edited by Moderator

Thanks for reply. A bit more education required. :) Nearby zero(0) means what exactly? I am getting confused with the signed integer.

-- 32-bit signed integer range: -2147483647 to +2147483647 ENC_POS <= std_logic_vector(to_signed(p,32)); |

check when p is nearby 0? (p > X or p < -X, where X is 10? 100? 1000?) check at the edges? (-2147483647 to +2147483647) i was thinking like

-- index allow to clear count -- 32-bit signed integer range: -2147483647 to +2147483647 if ENA then if dr_INDEX = "01" then if p > 1000 or p < -1000 then EQEP_ERR <= '1'; p <= 0; else EQEP_ERR <= '0'; p <= 0; end if; end if; end if; |

T

SparkyT wrote: > Nearby zero(0) means what exactly? That depends on what you would allow for an deviation. Usually it must be 0. > check at the edges? (-2147483647 to +2147483647) You will not be able to buy an encoder with somewhat 500000000 lines per revolution. So you will never ever reach the limit of an integer number. > check when p is nearby 0? (p > X or p < -X, where X is 10? 100? 1000?) Because my code does a quadruple evaluation all of the 4 edges in one "step" are counted. Usually the index pulse is 1 step wide, so at either "end" of the index pulse the counters value is up to 3 or down to -3. So I would raise the error flag when the counter >3 or <-3 at the "begin" (=rising edge) of the index pulse.

if ENA then if dr_INDEX = "01" then p <= 0; EQEP_ERR <= '0'; if p>3 or p<-3 then EQEP_ERR <= '1'; end if; end if; end if; |

:
Edited by Moderator

Thanks for the explanation. I ll just use a counter to catch the error ticks. T