AMIS30543 library
README.md
1 # AMIS-30543 library for Arduino
2 
3 Version: 1.1.0<br/>
4 Release date: 2015 May 26<br/>
5 [www.pololu.com](https://www.pololu.com/)
6 
7 ## Summary
8 
9 This is a C++ library for the Arduino IDE that helps interface with an [AMIS-30543 micro-stepping stepper motor driver](https://www.pololu.com/product/2970). It uses the [Arduino SPI](http://www.arduino.cc/en/Reference/SPI) library to communicate with the SPI interface (CS, DO, DI, and CLK) of the AMIS-30543.
10 
11 ## Supported platforms
12 
13 This library is designed to work with the Arduino IDE versions 1.6.x or later and will probably not work with older versions. For instance, it does not work with version 1.0.6. This library supports any Arduino-compatible board, including the [Pololu A-Star 32U4 controllers](https://www.pololu.com/category/149/a-star-programmable-controllers).
14 
15 ## Getting started
16 
17 ### Hardware
18 
19 An [AMIS-30543 carrier](https://www.pololu.com/product/2970) can be purchased from Pololu's website. Before continuing, careful reading of the [product page](https://www.pololu.com/product/2970) as well as the AMIS-30543 datasheet is recommended.
20 
21 You will need to connect your motor, motor power, and IOREF as described on the product page. You should also make the following connections between the Arduino and the driver:
22 
23  Arduino pin 2 - driver DIR
24  Arduino pin 3 - driver STEP
25  Arduino pin 4 - driver CS
26  Arduino SCK - driver CLK
27  Arduino MOSI - driver DI
28  Arduino MISO - driver DO
29  Arduino GND - driver GND
30 
31 The DO pin is only needed if you want to read information back from the stepper driver. Since the direction of the motor can be changed using the SPI interface, the DIR pin is also optional and not used in every example.
32 
33 The SPI pins (MOSI, MISO, and SCK) on Arduino-compatible boards are sometimes not labeled. You should refer to the documentation for your particular board to find the locations of these pins.
34 
35 On the [Arduino Uno](https://www.pololu.com/product/2191), [Arduino Leonardo](https://www.pololu.com/product/2192), and the [A-Star 32U4 controllers](https://www.pololu.com/category/149/a-star-programmable-controllers), the SPI pins (SCK, MOSI, and MISO) can be found on the 6-pin ISP header.
36 The [Arduino Uno](https://www.pololu.com/product/2191) has additional access points for the SPI pins: pin 11 is MOSI, pin 12 is MISO, and pin 13 is SCK.
37 
38 ### Software
39 
40 If you are using version 1.6.2 or later of the [Arduino software (IDE)](http://www.arduino.cc/en/Main/Software), you can use the Library Manager to install this library:
41 
42 1. In the Arduino IDE, open the "Sketch" menu, select "Include Library", then "Manage Libraries...".
43 2. Search for "AMIS30543".
44 3. Click the AMIS30543 entry in the list.
45 4. Click "Install".
46 
47 If this does not work, you can manually install the library:
48 
49 1. Download the [latest release archive from GitHub](https://github.com/pololu/amis-30543-arduino/releases) and decompress it.
50 2. Rename the folder "amis-30543-arduino-xxxx" to "AMIS30543".
51 3. Drag the "AMIS30543" folder into the "libraries" directory inside your Arduino sketchbook directory. You can view your sketchbook location by opening the "File" menu and selecting "Preferences" in the Arduino IDE. If there is not already a "libraries" folder in that location, you should make the folder yourself.
52 4. After installing the library, restart the Arduino IDE.
53 
54 ## Examples
55 
56 Several example sketches are available that show how to use the library. You can
57 access them from the Arduino IDE by opening the "File" menu, selecting
58 "Examples", and then selecting "AMIS30543". If you cannot find these
59 examples, the library was probably installed incorrectly and you should retry
60 the installation instructions above.
61 
62 ## Documentation
63 
64 For complete documentation of this library, including many features that were
65 not mentioned here, see
66 [the amis-30543-arduino documentation](https://pololu.github.io/amis-30543-arduino/). If you are already on that page, see the AMIS30543 class reference.
67 
68 ## Handling interruptions in stepper motor power
69 
70 If the power supply to the AMIS-30543 drops too low, then the driver will turn off and the motor will stop moving. After power is restored, all of the device's configuration registers will have their default values. This means that the motor outputs will be off and the motor will not turn, even after power is restored.
71 
72 It is possible to detect this situation using the `verifySettings()` function and/or recover from it using the `applySettings()` function.
73 
74 The `verifySettings()` function reads all of the configuration registers from the driver and verifies that they match the previously-specified settings. If `verifySettings()` returns false, then it means that the settings on the driver do not match the cached setting in the `AMIS30543` object, or the device is powered off, or the SPI connections between the microcontroller and the AMIS-30543 are incorrect. If your SPI connections are correct and the `AMIS30543` object is on the part of your system that might modify the registers on the driver, then the most likely causes for `verifySettings()` returning false would be that the driver is not powered or it lost power at some point in the past.
75 
76 The `applySettings()` function writes all of the cached settings to the driver. If the power to the driver is interrupted and then restored, calling `applySettings()` can restore the desired settings to the device and allow it to run again.
77 
78 The functions `sleep()`, `sleepStop()`, `setSlaGainDefault()`, `setSlaGainHalf()`, `setSlaTransparencyOff()`, `setSlaTransparencyOn()`, `disableDriver()`, and `enableDriver()` each modify bits in CR2, a register that also contains the bit that enables the motor driver outputs (MOTEN). To help avoid operating the motor at incorrect settings, each of these functions includes a call to `applySettings()`. When you call any of these functions, your system will automatically recover from earlier interruptions in the stepper motor power. These functions might also make it hard for you to detect power interruptions by calling `verifySettings()`, because they might automatically fix the settings before `verifySettings()` gets called.
79 
80 The AutoRecover example that comes with this library shows how to use `verifySettings()` to detect power loss and use `applySettings()` to recover from it.
81 
82 ## Detecting an open coil
83 
84 **WARNING:** Disconnecting a stepper motor coil while the motor is operating can cause damage to the stepper motor driver or other parts of your system. If you want to test that open coil detection is working, we recommend removing the connection while the stepper motor driver is not powered.
85 
86 The AMIS-30543 has the ability to detect when current cannot flow through one of your stepper motor coils. This is called an open coil, and it usually is caused by incorrect or incomplete connections between the stepper motor and the driver. It can also be caused by setting a current limit that is too high to be reached with your choice of stepper motor and power supply.
87 
88 The `readNonLatchedStatusFlags()` function reads the non-latched status flags from the device, including the OPENX and OPENY bits which indicate than an open coil condition has been detected. The AutoRecover example that comes with this library shows how to use that function.
89 
90 An open coil condition is only detected after a motor output PWM signal has been at a 100% duty cycle for 200 milliseconds. Therefore, to detect an open coil, you will need to step the motor sufficiently slowly or you will need to pause the motor's movement for at least 200 ms occasionally. When you pause, you should be sure to pause at a step position where the desired currents in both coils are non-zero. Also, after detecting an open coil, you should avoid stepping the motor until the problem is resolved and the status flags change back to 0. Taking steps during an open coil condition will usually cause the driver to stop detecting the open coil condition and clear the OPENX and OPENY bits.
91 
92 ## Version history
93 
94 * 1.1.0 (2015 May 26): Added an example that uses the [AccelStepper](http://www.airspayce.com/mikem/arduino/AccelStepper/) library. Moved the DIR and STEP pins in the examples to pins 2 and 3.
95 * 1.0.0 (2015 May 21): Original release.