Can't move motors on CNC v3 shield with custom code
hi, writting own cnc stepper-motor firmware , freezed on point unable move steppers. created simple program flashing led worked (pin 2-gnd: half brigthness, , 8-gnd: full brightness), plugged in cnc shield, nothing happened. on init, set 'enable' pin high (pin 8 / portb0), set 'direction x' high (pin 5 / portd5) , start toggling 'step x' (pin 2 / portd2) every tick. wrote 2 programs, both working fine led, don't work stepper motor shield.
this 1 non-arduino:
and 1 written in arduino:
of course, tested shield latest grbl , worked ok, stepper moving. need turn pin on, don't know one. thanks
this 1 non-arduino:
code: [select]
#include <avr/interrupt.h>
#include <avr/io.h>
#include <stdint.h>
int main() {
// timer enable
// enable internal transistors higher current
//ddrd = (1<<2) | (1<<5);
//ddrb = (1<<0);
portb = (1 << 0); //pin 8 high
portd = (1<<5); // x dir 1
portd = portd & ~(1 << 2); //x step 0
//uint8_t saved_state = sreg;
//cli();
ocr2a = 127;
tccr2b = (1 << cs21); //prescaller 8
tccr2a = (1 << wgm21); //ctc, top=ocra
timsk2 = (1 << ocie2a); // global interrupts enabled
//sreg = saved_state; //reneable interrupts
sei();
//infinite loop, stepping
while(1) {}
__builtin_unreachable();
}
//called every 64 us
char bef = 0;
isr(timer2_compa_vect) {
portd = portd & ~(1 << 2) | ((bef = !bef) << 2);
}
and 1 written in arduino:
code: [select]
// testing stepper motor pololu a4988 driver board or equivalent
// on uno onboard led flash each step
// version uses delay() manage timing
byte directionpin = 5;
byte steppin = 2;
int pulsewidthmicros = 20; // microseconds
int mcrsteps = 250; // delay between steps
void setup() {
serial.begin(115200);
serial.println("starting steppertest");
pinmode(directionpin, output);
pinmode(steppin, output);
pinmode(8, output); //enable pin
delay(3000);
digitalwrite(8, high); // enable
digitalwrite(directionpin, high);
int n = 0;
while(1) {
serial.print((n++&1)?"_":"-");
digitalwrite(steppin, high);
delaymicroseconds(pulsewidthmicros); // not needed
digitalwrite(steppin, low);
delaymicroseconds(mcrsteps);
}
}
void loop() {
}
of course, tested shield latest grbl , worked ok, stepper moving. need turn pin on, don't know one. thanks
lol, enable must low.
Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > Can't move motors on CNC v3 shield with custom code
arduino
Comments
Post a Comment