Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. #include <SPI.h> // include the SPI library:
  2. #include "L6470.h" // include the register and bit definitions
  3.  
  4. #define SLAVE_SELECT_PIN 10 // Wire this to the CSN pin
  5. #define MOSI 11 // Wire this to the SDI pin
  6. #define MISO 12 // Wire this to the SDO pin
  7. #define SCK 13 // Wire this to the CK pin
  8. #define dSPIN_RESET 7 // Wire this to the STBY line
  9. #define dSPIN_BUSYN 6 // Wire this to the BSYN line
  10.  
  11. #define STAT1 4 // Hooked to an LED on the test jig
  12. #define STAT2 5 // Hooked to an LED on the test jig
  13. #define SWITCH 8 // Hooked to the switch input and a
  14. // pB on the jig
  15.  
  16. float testSpeed = 25;
  17.  
  18. void setup()
  19. {
  20. // Standard serial port initialization for debugging.
  21. Serial.begin(9600);
  22.  
  23. // pin configurations for the test jig
  24. pinMode(STAT1, OUTPUT);
  25. pinMode(STAT2, OUTPUT);
  26. pinMode(SWITCH, INPUT);
  27. pinMode(5, INPUT);
  28. digitalWrite(STAT1, LOW);
  29. digitalWrite(STAT2, LOW);
  30.  
  31.  
  32. dSPIN_init();
  33.  
  34.  
  35. if (dSPIN_GetParam(dSPIN_CONFIG) == 0x2E88)
  36. digitalWrite(STAT1, HIGH);
  37.  
  38.  
  39. dSPIN_SetParam(dSPIN_STEP_MODE,
  40. !dSPIN_SYNC_EN |
  41. dSPIN_STEP_SEL_1_16 |
  42. dSPIN_SYNC_SEL_1);
  43.  
  44. // Configure the MAX_SPEED register- this is the maximum number
  45. // of (micro)steps per second allowed. You'll want to mess
  46. // around with your desired application to see how far you can
  47. // push it before the motor starts to slip. The ACTUAL
  48. // parameter passed to this function is in steps/tick;
  49. // MaxSpdCalc() will convert a number of steps/s into an
  50. // appropriate value for this function. Note that for any move
  51. // or goto type function where no speed is specified, this
  52. // value will be used.
  53. dSPIN_SetParam(dSPIN_MAX_SPEED, MaxSpdCalc(400));
  54.  
  55. dSPIN_SetParam(dSPIN_FS_SPD, FSCalc(50));
  56.  
  57.  
  58. dSPIN_SetParam(dSPIN_ACC, 0xfff);
  59.  
  60.  
  61. dSPIN_SetParam(dSPIN_OCD_TH, dSPIN_OCD_TH_6000mA);
  62.  
  63.  
  64. dSPIN_SetParam(dSPIN_CONFIG,
  65. dSPIN_CONFIG_PWM_DIV_1 |
  66. dSPIN_CONFIG_PWM_MUL_2 |
  67. dSPIN_CONFIG_SR_180V_us |
  68. dSPIN_CONFIG_OC_SD_DISABLE |
  69. dSPIN_CONFIG_VS_COMP_DISABLE |
  70. dSPIN_CONFIG_SW_HARD_STOP |
  71. dSPIN_CONFIG_INT_16MHZ);
  72.  
  73.  
  74. dSPIN_SetParam(dSPIN_KVAL_RUN, 0xFF);
  75.  
  76. // Calling GetStatus() clears the UVLO bit in the status
  77. // register, which is set by default on power-up. The driver
  78. // may not run without that bit cleared by this read operation.
  79. dSPIN_GetStatus();
  80.  
  81.  
  82. TCCR1A = 0; // No waveform generation stuff.
  83. TCCR1B = B00000110; // Clock on falling edge, T1 pin.
  84. TCNT1 = 0; // Clear the count.
  85. }
  86.  
  87. void loop()
  88. {
  89. dSPIN_Move(FWD, 25600);
  90. while (digitalRead(dSPIN_BUSYN) == LOW); // Until the movement completes, the
  91. // BUSYN pin will be low.
  92. dSPIN_SoftStop(); // Inserting a soft stop between
  93. // motions ensures that the driver
  94. // will execute the next motion with
  95. // the right speed.
  96. while (digitalRead(dSPIN_BUSYN) == LOW); // Wait for the soft stop to complete.
  97. Serial.println(TCNT1, DEC);
  98. while(1);
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement