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:
[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]