L6470 use library

Dependents:   CatPot_Main_ver1 CatPot_Main_F

Committer:
ryuna
Date:
Sat Dec 27 07:32:25 2014 +0000
Revision:
2:63e59749ff49
Parent:
1:e89f842fbeda
???????????????????busy_flag???????

Who changed what in which revision?

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