The Shop > Electronics & IC Programing
EasyPIC-6 Development Board by MikroElectronica - Take"2"
matnewsholme:
cheers Chris
finally got round to mounting stepper on x-axis on my X3 as first stage of cnc conversion. initially just want to use it as powerfeed so arduino linked to stepper driver seems way to go. want to use a pot for speed selection so modifying one of sample arduino sketchs as a quick and dirt proof of concept. If I feel brave I might try and convert your code across to arduino (not sure how it handles interrupts yet - more reading needed :scratch:)
Mat
kwackers:
Hi Mat,
I'm part way through doing something similar to what you suggest, but sadly it's a 'stalled' project due to a complete lack of time at the moment...
If it's any help this code sets up two lots of interrupts, a mpg (int on pin change) and a timer. Here's the code for them both.
Steve.
--- Code: ---
const int MPGALine = 20;
const int MPGBLine = 21;
int AState = 0; // mpg vars
int BState = 0;
// timer interrupt handler
ISR(TIMER2_OVF_vect)
{
// some code
}
void setup()
{
// init timer interrupts
// timer2 settings: Prescaler / 256, WGM mode 0
TCCR2A = 0;
TCCR2B = 1 << CS22 | 1 << CS21;
// timer2 Overflow Interrupt Enable
TIMSK2 = 1 << TOIE2;
// reset timer
TCNT2 = 0;
// setup the MPG interrupts
pinMode(MPGALine, INPUT); // int 3
attachInterrupt(3, mpgAChange, CHANGE);
pinMode(MPGBLine, INPUT); // int 2
attachInterrupt(2, mpgBChange, CHANGE);
}
//-----------------
// mpg interrupt handler
void mpgAChange()
{
AState = digitalRead(MPGALine);
if (AState != BState)
CurrentPosition += MPGMultiplier;
else
CurrentPosition -= MPGMultiplier;
}
void mpgBChange()
{
BState = digitalRead(MPGBLine);
if (BState == AState)
CurrentPosition += MPGMultiplier;
else
CurrentPosition -= MPGMultiplier;
}
--- End code ---
dickda1:
If using an Easydriver or Pololu stepper driver or even a simple H-bridge be careful to watch the current draw. A small/medium stepper motor like an M23 is right at the upper limit for these popular microprocessor-powered drivers - even with a good heat sink and a fan.
I built a stepper motor controlled laser for a DAVID 3D laserscanner. The duty cycle was low so that the driver could cool down.
-Dick
matnewsholme:
Kwackers
cheers for the interrupt code. will give it a try when I get that far.
dickda1
not going to drive stepper directly from arduino board. using arduino to generate step/direction signals for a proper stepper driver.
Mat
dickda1:
Mathewsholme,
I didn't state it well. The arduino board can't usually source enough current to drive anything but a very small stepper. That includes the plugin motor driver boards.
Keep us informed as your project progress. I am interested.
Dick
Navigation
[0] Message Index
[*] Previous page
Go to full version