Expansion SW library to control high power stepper motor(s) using IHM03A1 expansion board(s) with Powerstep01 driver.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: IHM03A1_ExampleFor1Motor HelloWorld_IHM03A1 IHM03A1_ExampleFor3Motors KYPHOS_Stepper_Motor_Control
Fork of X_NUCLEO_IHM03A1 by
Motor Control Library
Library to handle the X-NUCLEO-IHM03A1 Motor Control Expansion Board based on the Powerstep01 component.
It features the:
- read and write of Powerstep01 registers
- Nucleo and expansion board configuration (GPIOs, PWMs, IRQs, etc.)
- Powerstep01 application commands handling
- FLAG and BUSY interrupt handling (alarm reporting)
- Daisy chain handling
The API allows to easily:
- perform various positioning, moves and stops
- get/set or monitor the motor positions
- set home position and mark another position
- get/set minimum and maximum speed
- get current speed
- get/set acceleration and deceleration
- get/set the step mode (up to 1/128)
- get/set the control method
- get/set parameters for voltage mode driving
- get/set parameters for current mode driving
- get/set parameters for gate driving
- configure various protections such as overcurrent detection
- enable/disable alarms
- handle step-clock
- get system status
Daisy-Chain Configuration
The IHM03A1 board can be stacked up to three times so that the Powerstep01 components will be connected in daisy-chain configuration. For this purpose, some resistors must be correctly connected on the boards as depicted here below:
Platform compatibility
Compatible platforms have been tested with the default configuration provided by the HelloWorld_IHM03A1 example.
Revision 7:9d772e2a9dbe, committed 2017-07-14
- Comitter:
- Davidroid
- Date:
- Fri Jul 14 12:51:38 2017 +0000
- Parent:
- 6:7af3838de91a
- Commit message:
- Aligning to ARM mbed coding style.
Changed in this revision
--- a/Components/PowerStep01/PowerStep01.cpp Mon May 08 15:41:45 2017 +0000 +++ b/Components/PowerStep01/PowerStep01.cpp Fri Jul 14 12:51:38 2017 +0000 @@ -1478,55 +1478,83 @@ { case POWERSTEP01_EL_POS: if ((value > (POWERSTEP01_ELPOS_STEP_MASK|POWERSTEP01_ELPOS_MICROSTEP_MASK))|| - ((value!=0)&&(value < (1<<(7-(POWERSTEP01_STEP_MODE_STEP_SEL&Powerstep01_CmdGetParam(POWERSTEP01_STEP_MODE))))))) result = FALSE; - else registerValue = ((uint32_t) value)&(POWERSTEP01_ELPOS_STEP_MASK|POWERSTEP01_ELPOS_MICROSTEP_MASK); + ((value!=0)&&(value < (1<<(7-(POWERSTEP01_STEP_MODE_STEP_SEL&Powerstep01_CmdGetParam(POWERSTEP01_STEP_MODE))))))) { + result = FALSE; + } else { + registerValue = ((uint32_t) value)&(POWERSTEP01_ELPOS_STEP_MASK|POWERSTEP01_ELPOS_MICROSTEP_MASK); + } break; case POWERSTEP01_ABS_POS: case POWERSTEP01_MARK: if (value < 0) { value=-value; - if (((uint32_t)value)<=(POWERSTEP01_MAX_POSITION+1)) - registerValue = (POWERSTEP01_ABS_POS_VALUE_MASK+1-(uint32_t)value)&POWERSTEP01_ABS_POS_VALUE_MASK; - else result = FALSE; + if (((uint32_t)value)<=(POWERSTEP01_MAX_POSITION+1)) { + registerValue = (POWERSTEP01_ABS_POS_VALUE_MASK+1-(uint32_t)value)&POWERSTEP01_ABS_POS_VALUE_MASK; + } else { + result = FALSE; + } } else { - if (((uint32_t)value)<=POWERSTEP01_MAX_POSITION) - registerValue = ((uint32_t) value)&POWERSTEP01_ABS_POS_VALUE_MASK; - else result = FALSE; + if (((uint32_t)value)<=POWERSTEP01_MAX_POSITION) { + registerValue = ((uint32_t) value)&POWERSTEP01_ABS_POS_VALUE_MASK; + } else { + result = FALSE; + } } break; case POWERSTEP01_ACC: case POWERSTEP01_DEC: - if (value > POWERSTEP01_ACC_DEC_MAX_VALUE) result = FALSE; - else registerValue = acc_dec_steps_s2_to_reg_val(value); + if (value > POWERSTEP01_ACC_DEC_MAX_VALUE) { + result = FALSE; + } else { + registerValue = acc_dec_steps_s2_to_reg_val(value); + } break; case POWERSTEP01_MAX_SPEED: - if (value > POWERSTEP01_MAX_SPEED_MAX_VALUE) result = FALSE; - else registerValue = max_spd_steps_s_to_reg_val(value); + if (value > POWERSTEP01_MAX_SPEED_MAX_VALUE) { + result = FALSE; + } else { + registerValue = max_spd_steps_s_to_reg_val(value); + } break; case POWERSTEP01_MIN_SPEED: - if (value > POWERSTEP01_MIN_SPEED_MAX_VALUE) result = FALSE; - else registerValue = (POWERSTEP01_LSPD_OPT&Powerstep01_CmdGetParam(param))|min_spd_steps_s_to_reg_val(value); + if (value > POWERSTEP01_MIN_SPEED_MAX_VALUE) { + result = FALSE; + } else { + registerValue = (POWERSTEP01_LSPD_OPT&Powerstep01_CmdGetParam(param))|min_spd_steps_s_to_reg_val(value); + } break; case POWERSTEP01_FS_SPD: - if (value > POWERSTEP01_FS_SPD_MAX_VALUE) result = FALSE; - else registerValue = (POWERSTEP01_BOOST_MODE&Powerstep01_CmdGetParam(param))|fs_spd_steps_s_to_reg_val(value); + if (value > POWERSTEP01_FS_SPD_MAX_VALUE) { + result = FALSE; + } else { + registerValue = (POWERSTEP01_BOOST_MODE&Powerstep01_CmdGetParam(param))|fs_spd_steps_s_to_reg_val(value); + } break; case POWERSTEP01_INT_SPD: - if (value > POWERSTEP01_INT_SPD_MAX_VALUE) result = FALSE; - else registerValue = int_spd_steps_s_to_reg_val(value); + if (value > POWERSTEP01_INT_SPD_MAX_VALUE) { + result = FALSE; + } else { + registerValue = int_spd_steps_s_to_reg_val(value); + } break; case POWERSTEP01_K_THERM: if ((value < POWERSTEP01_K_THERM_MIN_VALUE)|| - (value > POWERSTEP01_K_THERM_MAX_VALUE)) result = FALSE; - else registerValue = k_therm_comp_to_reg_val(value); + (value > POWERSTEP01_K_THERM_MAX_VALUE)) { + result = FALSE; + } else { + registerValue = k_therm_comp_to_reg_val(value); + } break; case POWERSTEP01_OCD_TH: case POWERSTEP01_STALL_TH: - if (value > POWERSTEP01_STALL_OCD_TH_MAX_VALUE) result = FALSE; - else registerValue = stall_ocd_th_to_reg_val(value); + if (value > POWERSTEP01_STALL_OCD_TH_MAX_VALUE) { + result = FALSE; + } else { + registerValue = stall_ocd_th_to_reg_val(value); + } break; case POWERSTEP01_KVAL_HOLD: //POWERSTEP01_TVAL_HOLD case POWERSTEP01_KVAL_RUN: //POWERSTEP01_TVAL_RUN @@ -1534,13 +1562,19 @@ case POWERSTEP01_KVAL_DEC: //POWERSTEP01_TVAL_DEC if (voltageMode==FALSE) { - if (value > POWERSTEP01_TVAL_MAX_VALUE) result = FALSE; - else registerValue = t_val_ref_voltage_to_reg_val(value); + if (value > POWERSTEP01_TVAL_MAX_VALUE) { + result = FALSE; + } else { + registerValue = t_val_ref_voltage_to_reg_val(value); + } } else { - if (value > POWERSTEP01_KVAL_MAX_VALUE) result = FALSE; - else registerValue = k_val_perc_to_reg_val(value); + if (value > POWERSTEP01_KVAL_MAX_VALUE) { + result = FALSE; + } else { + registerValue = k_val_perc_to_reg_val(value); + } } break; case POWERSTEP01_ST_SLP: @@ -1553,13 +1587,19 @@ case POWERSTEP01_FN_SLP_DEC: //POWERSTEP01_TOFF_MIN if (voltageMode==FALSE) { - if (value>POWERSTEP01_TOFF_TON_MIN_MAX_VALUE) result = FALSE; - else registerValue = t_min_time_to_reg_val(value); + if (value>POWERSTEP01_TOFF_TON_MIN_MAX_VALUE) { + result = FALSE; + } else { + registerValue = t_min_time_to_reg_val(value); + } } else { - if (value > POWERSTEP01_SLP_MAX_VALUE) result = FALSE; - else registerValue = bemf_slope_perc_to_reg_val(value); + if (value > POWERSTEP01_SLP_MAX_VALUE) { + result = FALSE; + } else { + registerValue = bemf_slope_perc_to_reg_val(value); + } } break; default:
--- a/Components/PowerStep01/PowerStep01.h Mon May 08 15:41:45 2017 +0000 +++ b/Components/PowerStep01/PowerStep01.h Fri Jul 14 12:51:38 2017 +0000 @@ -87,8 +87,9 @@ PowerStep01(PinName flag_irq, PinName busy_irq, PinName standby_reset, PinName pwm, PinName ssel, DevSPI &spi) : StepperMotor(), flag_irq(flag_irq), busy_irq(busy_irq), standby_reset(standby_reset), pwm(pwm), ssel(ssel), dev_spi(spi) { /* Checking stackability. */ - if (!(numberOfDevices < MAX_NUMBER_OF_DEVICES)) + if (!(numberOfDevices < MAX_NUMBER_OF_DEVICES)) { error("Instantiation of the PowerStep01 component failed: it can be stacked up to %d times.\r\n", MAX_NUMBER_OF_DEVICES); + } /* ACTION 4 ----------------------------------------------------------* * Initialize here the component's member variables, one variable per * @@ -466,8 +467,11 @@ */ virtual int check_busy_hw(void) { - if (busy_irq!=0) return 0x01; - else return 0x00; + if (busy_irq!=0) { + return 0x01; + } else { + return 0x00; + } } /** @@ -478,8 +482,11 @@ */ virtual unsigned int check_status_hw(void) { - if (flag_irq!=0) return 0x01; - else return 0x00; + if (flag_irq!=0) { + return 0x01; + } else { + return 0x00; + } } /** @@ -1290,10 +1297,11 @@ */ int round(float f) { - if (f >= 0) + if (f >= 0) { return (int) f + (f - (int) f < 0.5f ? 0 : 1); - else + } else { return (int) f - (f - (int) f < -0.5f ? 1 : 0); + } } /*** Component's I/O Methods ***/ @@ -1306,8 +1314,9 @@ */ status_t Read(uint8_t* pBuffer, uint16_t NumBytesToRead) { - if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0) + if (dev_spi.spi_read(pBuffer, ssel, NumBytesToRead) != 0) { return COMPONENT_ERROR; + } return COMPONENT_OK; } @@ -1319,8 +1328,9 @@ */ status_t Write(uint8_t* pBuffer, uint16_t NumBytesToWrite) { - if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0) + if (dev_spi.spi_write(pBuffer, ssel, NumBytesToWrite) != 0) { return COMPONENT_ERROR; + } return COMPONENT_OK; } @@ -1333,8 +1343,9 @@ */ status_t ReadWrite(uint8_t* pBufferToRead, uint8_t* pBufferToWrite, uint16_t NumBytes) { - if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0) + if (dev_spi.spi_read_write(pBufferToRead, pBufferToWrite, ssel, NumBytes) != 0) { return COMPONENT_ERROR; + } return COMPONENT_OK; }
--- a/ST_INTERFACES.lib Mon May 08 15:41:45 2017 +0000 +++ b/ST_INTERFACES.lib Fri Jul 14 12:51:38 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#8f70f7159316 +https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#d3c9b33b992c
--- a/X_NUCLEO_COMMON.lib Mon May 08 15:41:45 2017 +0000 +++ b/X_NUCLEO_COMMON.lib Fri Jul 14 12:51:38 2017 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#12be3dfc15fd +http://developer.mbed.org/teams/ST/code/X_NUCLEO_COMMON/#0dbcdb8dab03