
L6470を使用した秋月のステッピングモータードライバをうごかすライブラリとプログラム,なおもともとあるやつをぱくった上で機能を追加している
Dependencies: mbed
L6470_lib/L6470.h@0:298e718ad4cb, 2014-11-11 (annotated)
- Committer:
- ryuna
- Date:
- Tue Nov 11 09:11:47 2014 +0000
- Revision:
- 0:298e718ad4cb
??????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ryuna | 0:298e718ad4cb | 1 | |
ryuna | 0:298e718ad4cb | 2 | #ifndef L6470_STEP_H |
ryuna | 0:298e718ad4cb | 3 | #define L6470_STEP_H |
ryuna | 0:298e718ad4cb | 4 | |
ryuna | 0:298e718ad4cb | 5 | //Brid. respected |
ryuna | 0:298e718ad4cb | 6 | #include "mbed.h" |
ryuna | 0:298e718ad4cb | 7 | |
ryuna | 0:298e718ad4cb | 8 | //config name.reset data; |
ryuna | 0:298e718ad4cb | 9 | //first init config data. |
ryuna | 0:298e718ad4cb | 10 | #define INI_ABS_POS 0 |
ryuna | 0:298e718ad4cb | 11 | #define INI_EL_POS 0 |
ryuna | 0:298e718ad4cb | 12 | #define INI_MARK 180 |
ryuna | 0:298e718ad4cb | 13 | #define INI_SPEED 0 |
ryuna | 0:298e718ad4cb | 14 | #define INI_ACC 0x8A//8A//0010 |
ryuna | 0:298e718ad4cb | 15 | #define INI_DEC 0x8A |
ryuna | 0:298e718ad4cb | 16 | #define INI_MAX_SPEED 0x20 |
ryuna | 0:298e718ad4cb | 17 | #define INI_MIN_SPEED 0 |
ryuna | 0:298e718ad4cb | 18 | #define INI_FS_SPD 0x27 |
ryuna | 0:298e718ad4cb | 19 | #define INI_KVAL_HOLD 0x3F |
ryuna | 0:298e718ad4cb | 20 | #define INI_KVAL_RUN 0xFF |
ryuna | 0:298e718ad4cb | 21 | #define INI_KVAL_ACC 0x70 |
ryuna | 0:298e718ad4cb | 22 | #define INI_KVAL_DEC 0x70 |
ryuna | 0:298e718ad4cb | 23 | #define INI_INT_SPD 0x408 |
ryuna | 0:298e718ad4cb | 24 | #define INI_ST_SLP 0x19 |
ryuna | 0:298e718ad4cb | 25 | #define INI_FN_SLP_ACC 0x29 |
ryuna | 0:298e718ad4cb | 26 | #define INI_FN_SLP_DEC 0x29 |
ryuna | 0:298e718ad4cb | 27 | #define INI_K_THERM 0 |
ryuna | 0:298e718ad4cb | 28 | // INI_ADC_OUT read only desu. |
ryuna | 0:298e718ad4cb | 29 | #define INI_OCD_TH 0xF0 |
ryuna | 0:298e718ad4cb | 30 | #define INI_STALL_TH 0x7F |
ryuna | 0:298e718ad4cb | 31 | #define INI_STEP_MODE 0x70 |
ryuna | 0:298e718ad4cb | 32 | #define INI_ALARM_EN 0xFF |
ryuna | 0:298e718ad4cb | 33 | #define INI_CONFIG 0x2E88 |
ryuna | 0:298e718ad4cb | 34 | // INI_STATUS read only desu. |
ryuna | 0:298e718ad4cb | 35 | |
ryuna | 0:298e718ad4cb | 36 | |
ryuna | 0:298e718ad4cb | 37 | |
ryuna | 0:298e718ad4cb | 38 | |
ryuna | 0:298e718ad4cb | 39 | //レジスタのアドレス |
ryuna | 0:298e718ad4cb | 40 | // name length<<8 + address |
ryuna | 0:298e718ad4cb | 41 | #define ABS_POS ((22<<8)+0x01) |
ryuna | 0:298e718ad4cb | 42 | #define EL_POS ((9<<8)+0x02) |
ryuna | 0:298e718ad4cb | 43 | #define MARK ((22<<8)+0x03) |
ryuna | 0:298e718ad4cb | 44 | #define SPEED ((20<<8)+0x04) |
ryuna | 0:298e718ad4cb | 45 | #define ACC ((12<<8)+0x05) |
ryuna | 0:298e718ad4cb | 46 | #define DEC ((12<<8)+0x06) |
ryuna | 0:298e718ad4cb | 47 | #define MAX_SPEED ((10<<8)+0x07) |
ryuna | 0:298e718ad4cb | 48 | #define MIN_SPEED ((13<<8)+0x08) |
ryuna | 0:298e718ad4cb | 49 | #define FS_SPD ((10<<8)+0x15) |
ryuna | 0:298e718ad4cb | 50 | #define KVAL_HOLD ((8<<8)+0x09) |
ryuna | 0:298e718ad4cb | 51 | #define KVAL_RUN ((8<<8)+0x0A) |
ryuna | 0:298e718ad4cb | 52 | #define KVAL_ACC ((8<<8)+0x0B) |
ryuna | 0:298e718ad4cb | 53 | #define KVAL_DEC ((8<<8)+0x0C) |
ryuna | 0:298e718ad4cb | 54 | #define INT_SPD ((14<<8)+0x0D) |
ryuna | 0:298e718ad4cb | 55 | #define ST_SLP ((8<<8)+0x0E) |
ryuna | 0:298e718ad4cb | 56 | #define FN_SLP_ACC ((8<<8)+0x0F) |
ryuna | 0:298e718ad4cb | 57 | #define FN_SLP_DEC ((8<<8)+0x10) |
ryuna | 0:298e718ad4cb | 58 | #define K_THERM ((4<<8)+0x11) |
ryuna | 0:298e718ad4cb | 59 | #define ADC_OUT ((5<<8)+0x12) |
ryuna | 0:298e718ad4cb | 60 | #define OCD_TH ((4<<8)+0x13) |
ryuna | 0:298e718ad4cb | 61 | #define STALL_TH ((7<<8)+0x14) |
ryuna | 0:298e718ad4cb | 62 | #define STEP_MODE ((8<<8)+0x16) |
ryuna | 0:298e718ad4cb | 63 | #define ALARM_EN ((8<<8)+0x17) |
ryuna | 0:298e718ad4cb | 64 | #define CONFIG ((16<<8)+0x18) |
ryuna | 0:298e718ad4cb | 65 | #define STATUS ((16<<8)+0x19) |
ryuna | 0:298e718ad4cb | 66 | |
ryuna | 0:298e718ad4cb | 67 | class L6470{ |
ryuna | 0:298e718ad4cb | 68 | |
ryuna | 0:298e718ad4cb | 69 | public: |
ryuna | 0:298e718ad4cb | 70 | |
ryuna | 0:298e718ad4cb | 71 | /** |
ryuna | 0:298e718ad4cb | 72 | * |
ryuna | 0:298e718ad4cb | 73 | * @param mosi SPI mosi pin |
ryuna | 0:298e718ad4cb | 74 | * @param miso SPI miso pin |
ryuna | 0:298e718ad4cb | 75 | * @param sck SPI sck pin |
ryuna | 0:298e718ad4cb | 76 | * @param _cs #cs pin |
ryuna | 0:298e718ad4cb | 77 | * |
ryuna | 0:298e718ad4cb | 78 | */ |
ryuna | 0:298e718ad4cb | 79 | |
ryuna | 0:298e718ad4cb | 80 | L6470(PinName mosi, PinName miso, PinName sck, PinName cs, PinName busy); |
ryuna | 0:298e718ad4cb | 81 | |
ryuna | 0:298e718ad4cb | 82 | void send(uint8_t temp); |
ryuna | 0:298e718ad4cb | 83 | uint8_t send_r(uint8_t temp); |
ryuna | 0:298e718ad4cb | 84 | void send_bytes(uint8_t temp[], int i); |
ryuna | 0:298e718ad4cb | 85 | void send_bytes_r(uint8_t temp[], int i); |
ryuna | 0:298e718ad4cb | 86 | void NOP(); |
ryuna | 0:298e718ad4cb | 87 | void SetParam(int param, int value); |
ryuna | 0:298e718ad4cb | 88 | int GetParam(int param); |
ryuna | 0:298e718ad4cb | 89 | void Run(bool dir, int speed); |
ryuna | 0:298e718ad4cb | 90 | void StepClock(bool dir); |
ryuna | 0:298e718ad4cb | 91 | void Move(bool dir,int n_step );//n_step--22bit |
ryuna | 0:298e718ad4cb | 92 | void GoTo(int abs_pos); |
ryuna | 0:298e718ad4cb | 93 | void GoTo_dir(bool dir, int abs_pos); |
ryuna | 0:298e718ad4cb | 94 | void GoUntill(bool act, bool dir, int speed); |
ryuna | 0:298e718ad4cb | 95 | void ReleseSW(bool act,bool dir); |
ryuna | 0:298e718ad4cb | 96 | void GoHome(); |
ryuna | 0:298e718ad4cb | 97 | void GoMark(); |
ryuna | 0:298e718ad4cb | 98 | void ResetPos(); |
ryuna | 0:298e718ad4cb | 99 | void ResetDevice(); |
ryuna | 0:298e718ad4cb | 100 | void SoftStop(); |
ryuna | 0:298e718ad4cb | 101 | void HardStop(); |
ryuna | 0:298e718ad4cb | 102 | void SoftHiz(); |
ryuna | 0:298e718ad4cb | 103 | void HardHiz(); |
ryuna | 0:298e718ad4cb | 104 | void Resets(); |
ryuna | 0:298e718ad4cb | 105 | void BusyWait(unsigned int time); |
ryuna | 0:298e718ad4cb | 106 | void Step(int dosu); |
ryuna | 0:298e718ad4cb | 107 | |
ryuna | 0:298e718ad4cb | 108 | |
ryuna | 0:298e718ad4cb | 109 | |
ryuna | 0:298e718ad4cb | 110 | protected: |
ryuna | 0:298e718ad4cb | 111 | |
ryuna | 0:298e718ad4cb | 112 | SPI m_spi; |
ryuna | 0:298e718ad4cb | 113 | DigitalOut m_cs; |
ryuna | 0:298e718ad4cb | 114 | DigitalIn m_busy; |
ryuna | 0:298e718ad4cb | 115 | |
ryuna | 0:298e718ad4cb | 116 | |
ryuna | 0:298e718ad4cb | 117 | |
ryuna | 0:298e718ad4cb | 118 | }; |
ryuna | 0:298e718ad4cb | 119 | #endif |
ryuna | 0:298e718ad4cb | 120 | |
ryuna | 0:298e718ad4cb | 121 | |
ryuna | 0:298e718ad4cb | 122 | |
ryuna | 0:298e718ad4cb | 123 | |
ryuna | 0:298e718ad4cb | 124 | |
ryuna | 0:298e718ad4cb | 125 | |
ryuna | 0:298e718ad4cb | 126 | |
ryuna | 0:298e718ad4cb | 127 | |
ryuna | 0:298e718ad4cb | 128 | |
ryuna | 0:298e718ad4cb | 129 | |
ryuna | 0:298e718ad4cb | 130 | |
ryuna | 0:298e718ad4cb | 131 | |
ryuna | 0:298e718ad4cb | 132 | |
ryuna | 0:298e718ad4cb | 133 | |
ryuna | 0:298e718ad4cb | 134 |