Arduino Forum

Using Arduino => Motors, Mechanics, Power and CNC => Topic started by: geraffe on Sep 15, 2020, 06:14 am

Title: Arduino Uno CNC shield (software PWM) ???
Post by: geraffe on Sep 15, 2020, 06:14 am
Hi Forum,

I just got a new Uno CNC Shield from PROTONEER. When I checked the datasheet for this board, I found out they use digital pin 2, 3, 4 (Please see attachment) as a4988 driver step input. But according to the pinout of UNO, only pin 3 (OC2B) can generate timer PWM (Please see attachment).

So I was wondering: if I want to use this shield to build a robot arm,  Does it mean I have to use "delay" (software) function to generate PWM instead of using timer (hardware)? 

I'm really confused right now and hope someone can give me some guidance.

Any help is truly appreciated!!

G



Title: Re: Arduino Uno CNC shield (software PWM) ???
Post by: Robin2 on Sep 15, 2020, 09:07 am
You don't need PWM with a stepper motor driver. PWM is normally used to control the speed of a DC motor or the brightness of an LED.

...R
Title: Re: Arduino Uno CNC shield (software PWM) ???
Post by: ballscrewbob on Sep 15, 2020, 02:05 pm
In addition to Robin.

PWM is also used to control a LASER if you use one with your CNC.

It's pin usage depends on which version of GRBL you would have installed.

Bob.

Title: Re: Arduino Uno CNC shield (software PWM) ???
Post by: geraffe on Sep 15, 2020, 06:59 pm
Thanks for the help

Sorry for the misleading. let me make my question more straightforward.

On the CNC shield, the "step" pin of X axis is connected to the UNO pin 2 ,which cannot generate hardware PWM. So based on my knowledge, we have to use the "delay" function to generate the  software PWM to tell the a4988 driver how many steps and how fast we want the motor go.


I cannot find the reason for that. Does it mean this shield can only work with software PWM?? or if not, how can I edit my code to control 3 motors together?

Thanks 
Title: Re: Arduino Uno CNC shield (software PWM) ???
Post by: geraffe on Sep 15, 2020, 07:13 pm
You don't need PWM with a stepper motor driver. PWM is normally used to control the speed of a DC motor or the brightness of an LED.

...R
'

Hi Robin,

I forgot to mention my step motor driver. The driver I used is A4988, which need 2 signals from the MCU. One is the "direction" (digital high CW, digital low CCW), the other is "step". The "step" pin need a PWM signal to tell the driver board how many steps and how fast we want the motor go. So I do need a PWM signal for A4988 driver.

My question is, if the "step" pin of X axis in this CNC shield is connected to UNO pin 2, which cannot generate hardware PWM signal, does it mean I have to use software PWM ("delay" function) to drive the motor? if yes, then how can I drive 3 motors at the same time?

Thanks~

G
Title: Re: Arduino Uno CNC shield (software PWM) ???
Post by: CrossRoads on Sep 15, 2020, 07:46 pm
Simple - Don't use delay.  Use millis() or micros() to determine when you want the next edge to occur for each motor.

Here's an extreme example, using micros() and arrays, to create 13 tones with a '1284P - when a button is pressed, a tone is played. I used a '1284P as it has 32 IO, and I wanted 13 buttons and 13 tones.
https://forum.arduino.cc/index.php?topic=179761.0 (https://forum.arduino.cc/index.php?topic=179761.0)


Instead of waiting for a button press, do that under software control. And make the frequency whatever you want, mine are mathematically calculated to be close to piano notes, and sounded very in tune with my wife's piano.
Title: Re: Arduino Uno CNC shield (software PWM) ???
Post by: Robin2 on Sep 15, 2020, 08:32 pm
My question is, if the "step" pin of X axis in this CNC shield is connected to UNO pin 2, which cannot generate hardware PWM signal, does it mean I have to use software PWM ("delay" function) to drive the motor? if yes, then how can I drive 3 motors at the same time?
Like I said earlier there is no need for PWM with a stepper motor. Have a look at this Simple Stepper Code (http://forum.arduino.cc/index.php?topic=277692.0) - especially the second example. It will work with any Arduino I/O pins.

Note that PWM varies the duty cycle of the pulses whereas the speed of a stepper motor is controlled by changing the frequency of the pulses - the number of millisecs (or microsecs) between steps.

...R