Go Down

Topic: Encoder loosing steps (Read 577 times) previous topic - next topic

MichaelBe

Hello,

I have the following setup:

- Encoder 512 Signals per revolution (2048 Edges, A+B)
- Vidor Encoder Programm (https://www.arduino.cc/en/Tutorial/VidorEncoder).
- Speed: abaout 600 rpm -> 20480 Hz signal rate


When I am using the normal programm the encoder status is only uptaded on the serial monitor about every half second. And even though the counter is refreshed when the count is eather +2048 or -2048 the value in the serial monitor can get higher. (example: 2155)

When I deleted the following coder, the serial monitor is updated way quicker and the value doesn't get anymore over 2048.

//#if 1
//
//  // Wait one second with interrupts disabled
//  noInterrupts();
//  // We can't call delay() since it uses interrupts, so use busy loops
//  for (int i = 0; i < F_CPU / 10; i++) {
//    asm ("nop");
//  }
//  interrupts();
//
//#else
//  //delay(1);
//#endif


But when the part is turning a couple hundret times my zero-point of the shaft is drifting away, which means that the encoder is skipping some signals.

Does anyone has experience with the Vidor and using an encoder?

Thank you :)

Mike





DarioPennisi

Hi,
Lucky enough it's not the fpga missing steps but rather the issue is that since API calls are a bit slow between the time you read and the time you write encoder is incrementing and result is that zero is not where it should be anymore. For example, you read 2040 and do nothing then at next round you read 2050 and reset to 0 and you just lost two steps.
If you want to avoid this you should rather avoid zeroing at runtime and eventually use modulo to check where you are.. basically you need a number between 0 and 4096 so if you use  value%4096 you will still have a number in that range without the need to reset

MichaelBe

Hello,

thank you very much for your advice. This works perfect :)

Do you know if there is any posibility to set outputs based on the encoder value in the FPGA?

For example:

if encoder value is 2022 then set output HIGH


Thank you :)


DarioPennisi

Hi Michael,
no, there is no such possibility right now but if you explain me how you plan to use it and if it's something more generally useful we can implement it.
thanks,

Dario

MichaelBe

Thank you for your reply.

I want to trigger a camera based on the encoder position.
It would be very nice to set outputs based on the position :)

Go Up