Hello, I bought a small 5W LASER diode machine. I changed the STM32 original CPU and placed an Arduino Nano LASER CNC shield as my other similar machine has. This Lubandiy shield has optocouplers to completely isolate de power stages from the Arduino Nano module, even the ground signals are different. No schematics or manual were provided and couldn't find documentation in their website. Flashed GRBL 1.1f , and checked every signal coming from the Arduino to the Pololu stepper drivers. Pin D11 drives the IRF540 MOSFET for the PWM required for LASER beam modulation.
Everything is working fine except that the PWM output signal is inverted, low S command values lead to a high power beam and viceversa. The MOSFET optocoupler and related NPN transistor are inverting the signal making the shield unusable. Before I start cutting the board traces and installing an extra inverter in the middle of pin D11 and the optocoupler to invert the signal by hardware, I thought that the timer could be initialized to provide an inverted PWM.
The Atmel ATmega328P datasheet explains at 19.9.1 that COM1B1 and COM1B0 bits of the TC0 Control Register A set with "11", can produce this inverted output. The stepper_init() function found in stepper.c GRBL library module shows code that initializes the timer.
// Initialize and start the stepper motor subsystem
void stepper_init()
{
// Configure step and direction interface pins
STEP_DDR |= STEP_MASK;
STEPPERS_DISABLE_DDR |= 1<<STEPPERS_DISABLE_BIT;
DIRECTION_DDR |= DIRECTION_MASK;
// Configure Timer 1: Stepper Driver Interrupt
TCCR1B &= ~(1<<WGM13); // waveform generation = 0100 = CTC
TCCR1B |= (1<<WGM12);
TCCR1A &= ~((1<<WGM11) | (1<<WGM10));
TCCR1A &= ~((1<<COM1A1) | (1<<COM1A0) | (1<<COM1B1) | (1<<COM1B0)); // Disconnect OC1 output
// TCCR1B = (TCCR1B & ~((1<<CS12) | (1<<CS11))) | (1<<CS10); // Set in st_go_idle().
// TIMSK1 &= ~(1<<OCIE1A); // Set in st_go_idle().
// Configure Timer 0: Stepper Port Reset Interrupt
TIMSK0 &= ~((1<<OCIE0B) | (1<<OCIE0A) | (1<<TOIE0)); // Disconnect OC0 outputs and OVF interrupt.
TCCR0A = 0; // Normal operation
TCCR0B = 0; // Disable Timer0 until needed
TIMSK0 |= (1<<TOIE0); // Enable Timer0 overflow interrupt
#ifdef STEP_PULSE_DELAY
TIMSK0 |= (1<<OCIE0A); // Enable Timer0 Compare Match A interrupt
#endif
}
Attached: stepper.c and stepper.h files, Atmel daasheet, pictures of the shield and mentioned optocouplers.
Could somebody please help me change the code to obtain the PWM signal inverted correctly?
Thank you in advance
Roberto