Академический Документы
Профессиональный Документы
Культура Документы
workshop
living
food
play
outside
Table of Contents
Arduino Hardware PWM for stepper motor drives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
http://www.instructables.com/id/Arduino-Hardware-PWM-for-stepper-motor-drives/
http://www.instructables.com/id/Arduino-Hardware-PWM-for-stepper-motor-drives/
Image Notes
1. Motor
2. Servo Controller
3. Potentiometer
http://www.instructables.com/id/Arduino-Hardware-PWM-for-stepper-motor-drives/
Image Notes
1. Stepper motor
2. Stepper motor driver
3. Pulse and Direction inputs
There is one major drawback to this method of control over stepper motors. A stepper motor uses open loop control to determine where it is, this is done by counting the
number of steps the motor has made in any given direction. When using the hardware module to generate the PWM like this, nothing is actually counting the steps. This
method of control is only really suitable when there is another feedback mechanism. In my case the Z axis travels to the end switches and stops when it gets there. I don't
care how many steps it takes to do that.
I have another project in development that will use this same control method, in that system the user will provide the feedback and will stop the motor when it is in the
correct position. This method is not really suitable for controlling the laser cutter as it traces out a design so I will move on to look at the next thing, expect more ibles in
the future.
Image Notes
1. Arduino Pro mini
http://www.instructables.com/id/Arduino-Hardware-PWM-for-stepper-motor-drives/
Related Instructables
2 axis
automated
crane by
sharkdanger
Dot Matrix
Printer from a
CD/DVD Reader
with Arduino by
Robson Couto
Arduino stepper
motor and
servos shield AW GCSE
Board by
AntMan232
Arduino based
Etch A Sketch
Laser Cutter. by
msraynsford
Motorized
camera slider
controled by
Android phone
by hesamh
3W 4'x4'
Arduino Laser
Cutter/Engraver
by FamousMods
Advertisements
Comments
4 comments
Add Comment
Joe_M says:
racataca says:
?
I need to convert 2 PWM inputs (RC signal) and turn it into 2 analog outputs 5VDC. (0v-to 5 Vdc).
.
stratos13pao says:
Orngrimm says:
Recently i had to make a much faster PWM for a project but still preserve the capability of 1%-steps in the duty.
In fact, i had to reach FULL speed --> 16MHz clock of the Arduino --> 160kHz frequency with 1% stepping of dutycycle.
A lot of forums and boards said: No dice. That wont work, too fast.
I fiddled around a bit and got it finally working as intended.
The important parts are those setting of Timer1 and registers to it:
// The definitions of the PWM. Borders, initial dutys and such stuff
int duty1 = 80;// The desired dutycycle #1 initialisation.
int duty2 = 1;// The desired dutycycle #2. Lets make 1% // Not needed... // Also here: 0..49 = 50 steps
int PWM_maximal = 100; // 100% is the TOP limit
int PWM_minimal = 0; // 0% is the lower limit. However 0% is a tad > than 0. In fact, 0% == 60ns high (1 clockcycle). ATM no
way around this. Sorry.
int PWMfreq = 160; // kHz of the PWM
int period = 16000 / PWMfreq; // How many clockticks shall = one period? (16000kHz Quarz / desired PWMfreq in kHz)
// Set the Pins to output. Pins 13-2 are PWM-capable on my Arduino mega (Atmega1280)
pinMode(11, OUTPUT);
// pinMode(12, OUTPUT); // enable this if yu want to use the second PWM!
// Init timer1
// STOP & clear
TCCR1B = TCCR1A = B00000000; // Clear TCCR1A (for a known start) andTCCR1B (to stop timer1 clock for register updates)
// Define the pins and theyr behaviour / linking
TCCR1A = TCCR1A | B10000000; // Clear OC1A on match, set OC1A at BOTTOM (Non-Inverting-Mode) --> Pin11
// TCCR1A = TCCR1A | B00100000; // Clear OC1B on match, set OC1B at BOTTOM (Non-Inverting-Mode) --> Pin12 // Enable this to get a
second PWM on Pin 12! His duty is set by OCR1B further below in this setup
// Waveform Generation Mode: I want WGM12-WGM10 set to binary 110 --> Fast PWM, Top = ICR1 , Immediate update of OCR1A
TCCR1A = TCCR1A | B00000010; // WGM11 = 1 & WGM10 = 0
TCCR1B = TCCR1B | B00001000; // WGM12 = 1
// Define TOP and the Compare
ICR1 = period;// ICR1 = TOP --> FastPWM with TOP = ICR1: Counts 0 to ICR1: --> drive PWM period
TCNT1 = duty1 - 1;// force immediate OCR1x compare on next tick
http://www.instructables.com/id/Arduino-Hardware-PWM-for-stepper-motor-drives/
// Set the prescaler and an unknown (to me) bit which seems important
TCCR1B = TCCR1B | B00000001;// last 3 bits = B001 --> prescaler = 1
TCCR1B = TCCR1B | B00010000;// Seems to be a read-only-bit? why set it? dont know. was this way online...
// Without it, PWM-Duty HIGH is OK, but LOW is WAY too long... 30.4us instead of 4.6us.
http://www.instructables.com/id/Arduino-Hardware-PWM-for-stepper-motor-drives/