I am looking for a software solution or interface to transform the two phases planned for a stepper motor to a DC motor with encoder feedback. The encoder feedback would serve to calibrate the DC motor to the number of steps originally intended for the PAP motor.
Some industrial CNC have this connection option in PAP or DC motor with encoder.
Its not that major to get something working. You need two ISRs, one for reading the quadrature from
the encoder - I'd recommend using pin change interrupts for that as you can have one handler triggered
from a change of either A or B inputs. That ISR maintains the actual position variable
A single normal interrupt channel can count the step pulses from GRBL (as well as the direction)
and set the set-point variable.
The in loop() you run a PID to take the difference of the two values and derivce a control output
(direction and magnitude) for the motor controller.
Due to the speed of pulses it is probably worth using direct port manipulation in the ISRs so
each runs in a dozen microseconds or less.
I am reassured about the feasibility of my project.
I took as base the Grbl of Denvi / candle in v1.0.9.
Perhaps you know a better software?
I now have to perform an opto coupling to the "interrupt" inputs of my second Arduino to pick up the PAP pulses and enter them in a comparator to prepare the PID + - 10 Volts set point.
Have a good day.
MarkT:
What +/- 10V? Is this some external motor with analog bipolar control input?
In fact, I think using an H bridge to operate the motor of each axis. So I do not need to create a + - 10 Volts setpoint.
The project is as follows:
a Uno for processing G-Code to Grbl.
the PWM-Uno will send its pulses to an Arduino-Mega interrupt input.
The PWM of each of the 3 axes will be created by the Mega and the Grbl by a Uno.
A second possibility:
Do you think it would be possible to add the Grbl processing in the Mega without risk of calculation error?
In this case, I would have only one Arduino.
The problem of recovering the Grbl / PWM for the PID addition would then arise ...
Do you think it would be possible to add the Grbl processing in the Mega without risk of calculation error?
In this case, I would have only one Arduino.
No, I think you'll run out of CPU time handling interrupts for several fast quadrature encoders. Besides the
Mega only has pin change interrupts on a small subset of its pins, whereas the Uno has them on every pin.
Consider a Pro Mini(*) per motor/motor-driver, then once you have some sort of working code your entire
system is going to starting doing something - trying to hack GRBL to handle loads of interrupts and
PID loops just sounds like something that will present many difficult issues. Keep the same modularity
as already works for steppers - you can then even drive steppers and servomotors together.
Just to be clear, Grbl's job is to convert text-based gcode into step/direction pulses to stepper drivers. Servostrap/Repstrap's job is to take step/direction pulses from grbl to control the position of a DC motor. To do what you're asking to do there's no need to modify the code of either firmware.
Each piece of firmware is written to be extremely efficient since the respective tasks are incredibly time-sensitive. Like MarkT said, you can't hope to combine both Grbl's and Servostrap's job onto a single microcontroller.
Chagrin:
Just to be clear, Grbl's job is to convert text-based gcode into step/direction pulses to stepper drivers. Servostrap/Repstrap's job is to take step/direction pulses from grbl to control the position of a DC motor. To do what you're asking to do there's no need to modify the code of either firmware.
Each piece of firmware is written to be extremely efficient since the respective tasks are incredibly time-sensitive. Like MarkT said, you can't hope to combine both Grbl's and Servostrap's job onto a single microcontroller.
I understand very well what you are saying, and I thank you for your information.
My project, a bit "crazy" may be to operate DC motors with encoder, replacing step motors; always on the basis of a Grbl (rather programmed for step by step seems it).
So I intend to work from the PWM output of a Uno that will provide the trajectory pulses to an input of a Mega.
The latter will drive by PID each of the 3 DC motors.