L6470 Arduino code help


hello,
i'm using l6470 stepper driver run motor. i'm running example code given sparkfun. understand code written motor move , forth, mine run in 1 direction continuously. please me figure out wrong. part of code given below. (i've hooked 4,6,10,11,12,13 , gnd pins of arduino , not leds or switches). how modify coding motor run specific number of steps , stop?
thank !!!

code: [select]
//dspin_main.ino - contains setup() , loop() functions.

float testspeed = 10;

void setup()
{
 // standard serial port initialization debugging.
 serial.begin(9600);
 
 // pin configurations test jig
 pinmode(stat1, output);
 pinmode(stat2, output);
 pinmode(switch, input);
 digitalwrite(stat1, low);
 digitalwrite(stat2, low);
 
 // dspin_init() implemented in dspin_support.ino file. includes
 //  all necessary port setup , spi setup allow arduino to
 //  control dspin chip , relies entirely upon pin redefinitions
 //  in dspin_example.ino
 dspin_init();
 
 // first things first: let's check communications. config register should
 //  power 0x2e88, can use check communications.
 //  on test jig, causes led light up.
 if (dspin_getparam(dspin_config) == 0x2e88) digitalwrite(stat1, high);
 .
 
 // first, let's set step mode register:
 //   - dspin_sync_en controls whether busy/sync pin reflects step
 //     frequency or busy status of chip. want busy
 //     status.
 //   - dspin_step_sel_x microstepping rate- we'll go full step.
 //   - dspin_sync_sel_x ratio of (micro)steps toggles on the
 //     busy/sync pin (when pin used sync). make 1:1, despite
 //     not using pin.
 dspin_setparam(dspin_step_mode, !dspin_sync_en | dspin_step_sel_1_32 | dspin_sync_sel_1);

 dspin_setparam(dspin_max_speed, maxspdcalc(200));

 dspin_setparam(dspin_fs_spd, fscalc(400));

 dspin_setparam(dspin_acc, 0xfff);
 // configure overcurrent detection threshold. constants defined
 //  in dspin_example.ino file.
 dspin_setparam(dspin_ocd_th, dspin_ocd_th_6000ma);
 // set config register follows:
 //  pwm frequency divisor = 1
 //  pwm frequency multiplier = 2 (62.5khz pwm frequency)
 //  slew rate 290v/us
 //  do not shut down bridges on overcurrent
 //  disable motor voltage compensation
 //  hard stop on switch low
 //  16mhz internal oscillator, nothing on output
 dspin_setparam(dspin_config,
                  dspin_config_pwm_div_1 | dspin_config_pwm_mul_2 | dspin_config_sr_290v_us
                | dspin_config_oc_sd_disable | dspin_config_vs_comp_disable
                | dspin_config_sw_hard_stop | dspin_config_int_16mhz);

 dspin_setparam(dspin_kval_run, 0x3f);

 dspin_getstatus();
}

// test jig behavior- rotate 1 full revolution forward, 1 full revolution
//  backwards, tick forwards until hard stop button pressed.
void loop()
{
 // 200 steps 1 revolution on 1.8 deg/step motor.
 dspin_run(fwd, spdcalc(400));
 while(1);
 while (digitalread(dspin_busyn) == low);  // until movement completes, the
                                           //  busyn pin low.
 dspin_softstop();                         // inserting soft stop between
                                           //  motions ensures driver
                                           //  will execute next motion with
                                           //  the right speed.
 while (digitalread(dspin_busyn) == low);  // wait soft stop complete.
 delay(500);                               // pause. not necessary proper operation.
 dspin_move(rev, 200);                     // again, backwards.
 while (digitalread(dspin_busyn) == low);
 dspin_softstop();
 while (digitalread(dspin_busyn) == low);
 delay(500);
 dspin_run(fwd, spdcalc(testspeed));       // we'll test hard stop switch...
 while (digitalread(switch) == high);      // dspin stop on own; is
                                           //  so arduino knows button has been
                                           //  pressed.
 while (digitalread(dspin_busyn) == low);
 delay(50);
 // check see if motor has stopped. if so, light second
 //  led , wait forever, until board removed , test jig reset.
 if (dspin_getparam(dspin_speed) == 0) digitalwrite(stat2, high);
 while(1);
}




Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > L6470 Arduino code help


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62