![Quote](images/misc/quote_icon.png)
Originally Posted by
microlatina
Thank you hfjbuis for you reply.
The solution you kindly offer is useful to switch the order of the spindle enable pin with the direction pin.
What I need is to invert the PWM signal, meaning that every time it is '1', it should change to '0' and viceversa.
This produces that LASER power gets inverted (or spindle speeds). Higher S command values will produce lower LASER powers (or spindle speeds) and viceversa.
I finally found the solution and it is working for me.
A change in the initialization of the timer that generates the PWM signal for a spindle motor with variable speed.
I added the following to the original cpu_map.h file in the Arduino GRBL library. Attached is the modified file.
At the top of the file I added a definition for 2 new bits COM2A0 and COM2A1 that the timer needs to be set in order to invert the output of the PWM signal:
#define INVERTPWM 1
If the inverting of the PWM signal is no needed (original GRBL) this line must be commented
Then, the code inside the SPINDLE_TCCRA_INIT_MASK can be altered as follows with a conditional compilation section:
#ifdef INVERTPWM
#define SPINDLE_TCCRA_INIT_MASK ((1<<COM2A0) | (1<<COM2A1)| (1<<WGM20) | (1<<WGM21)) // PWM INVERTED mode COM2A0 and COM2A1 bits are also set
#else
#define SPINDLE_TCCRA_INIT_MASK ((1<<WGM20) | (1<<WGM21)) // Configures fast PWM mode - NORMAL ORIGINAL GRBL
#endif
The COM2A0 and COM2A1 bits located in the TCCR2A register need to be set as part of the initialization to invert the output signal.
This will alter the functionality of the spindle_init() function inside the spindle_control.c module to correctly set the PWM timer for my needs.
In a hardware inverted configuration as in the shield I bought this is now working. Some other lines of code may need further change, but by now this is working fine as in any of my other little machines.
Problem solved.