EmbDev.net

Forum: FPGA, VHDL & Verilog Index Input for Encoder Interface


von SparkyT (Guest)


Rate this post
0 useful
not useful
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

von Lothar M. (lkmiller) (Moderator)


Rate this post
0 useful
not useful
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
von SparkyT (Guest)


Rate this post
0 useful
not useful
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

von Lothar M. (lkmiller) (Moderator)


Rate this post
0 useful
not useful
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
von SparkyT (Guest)


Rate this post
0 useful
not useful
Thanks for the explanation. I ll just use a counter to catch the error 
ticks.

T

von SparkyT (Guest)


Attached files:

Rate this post
0 useful
not useful
FYI

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig