Remora - ethernet NVEM / EC300 / EC500 cnc board

  • tuxcnc
  • Away
  • Premium Member
  • Premium Member
More
19 Jun 2025 16:08 - 19 Jun 2025 16:29 #330518 by tuxcnc
I can't drive EC500 spindle encoder to work.
(The counter works properly, but index not. I can use encoder's index output as ordinary I/O, but this not satisfied me due to delays)
I suspect, this never will work, because the used code is wrong way.
I'm developing similar project (but only spindle support) on STM32F103, and my code seems works properly.
Here you are most important fragments:
[code]//********************************************************
This is a fragment of code from other project
Not for copy/paste, only for explanation
//********************************************************

// EC500 side
// fb. prefix means variables will send from EC500 to hal component

struct fbPacket {
    float raw_encoder;
    float encoder_latched;
} fb = { 0.0, 0.0 };

fb.raw_encoder = encoder.getCount();
void index_ISR1() {        // interrupt handler
  fb.encoder_latched  = encoder.getCount();
}

//********************************************************

// Hal component side
// fb. prefix means variables received from EC500
// index_ena is i/o hal pin for connect to spindle.0.index_enable
// pos_scale is hal input pin
// period is LinuxCNC global variable
// pos and vel are hal output pins
// Not need anything else for synchronising spindle

float old_pos;
float latched_enc;
float encoder_latched_old;
float delta_pos;
float delta_time;
struct FB {
    float raw_encoder;
    float encoder_latched;
} fb = { 0.0, 0.0 };

            if  ((encoder_latched_old != fb.encoder_latched) && (index_ena)) {
            latched_enc = fb.encoder_latched;
        old_pos = (fb.raw_encoder - latched_enc);
            index_ena = false;
            }
            encoder_latched_old = fb.encoder_latched;

   pos = (fb.raw_encoder - latched_enc) / pos_scale;
   delta_pos = pos - old_pos;
   old_pos = pos;
   delta_time = period * 1e-9;
   vel = delta_pos / delta_time;
   
//******************************************************** 
[/code]
 
Last edit: 19 Jun 2025 16:29 by tuxcnc. Reason: edit the code

Please Log in or Create an account to join the conversation.

  • scotta
  • scotta's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
19 Jun 2025 20:35 #330531 by scotta
Hi, which module have you been trying to use? The software Encoder module or the QDC module? Both support the index pulse detection and encoder count latching so LinuxCNC can acquire the index position count.

Please Log in or Create an account to join the conversation.

  • tuxcnc
  • Away
  • Premium Member
  • Premium Member
More
19 Jun 2025 22:48 #330537 by tuxcnc

Hi, which module have you been trying to use? The software Encoder module or the QDC module? Both support the index pulse detection and encoder count latching so LinuxCNC can acquire the index position count.
 

Hi.
QDC.
The encoder_raw code is good and there are only hardware problems (optocouplers and RC filters cut the bandwith).
But this is very bad idea to send encoder's index pulse by ethernet.
Let's make calculations.
3000 rpm and 1 ms base_thread is 18 degrees accuracy - not acceptable.
The solution is send not index, but raw_count lathed at encoder's index edge interrupt routine.
There is in your code, line 321 in qdc.cpp file:
this->indexCount = ENC_GetPositionValue(this->encBase);
But there is no indexCount hal pin...
In the fact, we don't need receive index pulse at component side, because change of indexCount means index was betwen last and present data transmision.
So we can update indexCount at every encoder's index edge, but use them only if hal index_enable pin is true. (look at my code).

I tried use raw_count and index pins connected to PRUencoder module. Sometimes it works, mostly not.
But even if it works, PRUencoder resets position to zero at received index, not at real index.
In my code, position is reset not to zero, but to
pos = (fb.raw_encoder - latched_enc) / pos_scale;
(raw_encoder may be not equal latched_enc)
So there is no delay.
In this case I not need PRUencoder, because I move pos and vel calculations to my component. 

Please Log in or Create an account to join the conversation.

Time to create page: 0.130 seconds
Powered by Kunena Forum