Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: Stepper_Matlab_Control SunTracker_BLE Stepper_Matlab_Control MemsMotorControl ... more
Fork of X_NUCLEO_IHM01A1 by
Motor Control Library
Introduction
Library to handle the X-NUCLEO-IHM01A1 Motor Control Expansion Board based on the the L6474 component.
Daisy-Chain Configuration
This board can be stacked up to three times so that the L6474 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
- NUCLEO boards have been tested with the default configuration provided by the HelloWorld_IHM01A1 example.
- LPCXpresso11U68 board has been tested with the following patch:
- to connect with a wire from the LPCX’s
D4pin to the IHM01A1’sD9pin; - to initialize the pwm PinName variable with
D4rather thanD9.
- to connect with a wire from the LPCX’s
- FRDM-K64F board has been tested with the following patch:
- to connect with a wire from the FRDM’s
D4pin to the IHM01A1’sD8pin; - to initialize the standby_reset PinName variable with
D4rather thanD8.
- to connect with a wire from the FRDM’s
Example Applications
- HelloWorld_IHM01A1
- HelloWorld_IHM01A1_2Motors
- MotorControl_IHM01A1
- MemsMotorControl
- MemsMotorControl_IHM01A1_IKS01A2
Diff: Components/l6474/l6474_class.h
- Revision:
- 18:2d6ab2b93685
- Parent:
- 17:35b9ca8c4bd6
- Child:
- 20:a8e81b65f0af
--- a/Components/l6474/l6474_class.h Mon Jan 04 15:54:07 2016 +0000
+++ b/Components/l6474/l6474_class.h Wed Jan 13 14:35:59 2016 +0000
@@ -98,7 +98,7 @@
L6474(PinName flag_irq, PinName standby_reset, PinName direction, PinName pwm, PinName ssel, DevSPI &spi) : StepperMotor(), flag_irq(flag_irq), standby_reset(standby_reset), direction(direction), pwm(pwm), ssel(ssel), dev_spi(spi)
{
/* Checking stackability. */
- if (!(numberOfDevices < MAX_NUMBER_OF_DEVICES))
+ if (!(number_of_devices < MAX_NUMBER_OF_DEVICES))
error("Instantiation of the L6474 component failed: it can be stacked up to %d times.\r\n", MAX_NUMBER_OF_DEVICES);
/* ACTION 4 ----------------------------------------------------------*
@@ -109,10 +109,10 @@
* measure = 0; *
* instance_id = number_of_instances++; *
*--------------------------------------------------------------------*/
- errorHandlerCallback = 0;
- deviceInstance = numberOfDevices++;
- memset(spiTxBursts, 0, L6474_CMD_ARG_MAX_NB_BYTES * MAX_NUMBER_OF_DEVICES * sizeof(uint8_t));
- memset(spiRxBursts, 0, L6474_CMD_ARG_MAX_NB_BYTES * MAX_NUMBER_OF_DEVICES * sizeof(uint8_t));
+ error_handler_callback = 0;
+ device_instance = number_of_devices++;
+ memset(spi_tx_bursts, 0, L6474_CMD_ARG_MAX_NB_BYTES * MAX_NUMBER_OF_DEVICES * sizeof(uint8_t));
+ memset(spi_rx_bursts, 0, L6474_CMD_ARG_MAX_NB_BYTES * MAX_NUMBER_OF_DEVICES * sizeof(uint8_t));
}
/**
@@ -150,7 +150,7 @@
*/
virtual int Init(void *init = NULL)
{
- return (int) L6474_Init((MOTOR_InitTypeDef *) init);
+ return (int) L6474_Init((L6474_InitTypeDef *) init);
}
/**
@@ -189,14 +189,14 @@
* + L6474_RESERVED_REG04
* + L6474_RESERVED_REG05
* + L6474_RESERVED_REG06
- * + L6474_TVAL
+ * + L6474_TVAL : value in mA
* + L6474_RESERVED_REG07
* + L6474_RESERVED_REG08
* + L6474_RESERVED_REG09
* + L6474_RESERVED_REG10
* + L6474_T_FAST
- * + L6474_TON_MIN
- * + L6474_TOFF_MIN
+ * + L6474_TON_MIN : value in us
+ * + L6474_TOFF_MIN : value in us
* + L6474_RESERVED_REG11
* + L6474_ADC_OUT
* + L6474_OCD_TH
@@ -209,9 +209,26 @@
* + L6474_RESERVED_REG14
* + L6474_INEXISTENT_REG
*/
- virtual unsigned int GetParameter(unsigned int parameter)
+ virtual float GetParameter(unsigned int parameter)
{
- return (unsigned int) L6474_CmdGetParam((L6474_Registers_t) parameter);
+ unsigned int register_value = (unsigned int) L6474_CmdGetParam((L6474_Registers_t) parameter);
+ float value;
+
+ switch ((L6474_Registers_t) parameter)
+ {
+ case L6474_TVAL:
+ value = L6474_Par_to_Tval_Current((float) register_value);
+ break;
+ case L6474_TON_MIN:
+ case L6474_TOFF_MIN:
+ value = L6474_Par_to_Tmin_Time((float) register_value);
+ break;
+ default:
+ value = (float) register_value;
+ break;
+ }
+
+ return value;
}
/**
@@ -309,14 +326,14 @@
* + L6474_RESERVED_REG04
* + L6474_RESERVED_REG05
* + L6474_RESERVED_REG06
- * + L6474_TVAL
+ * + L6474_TVAL : value in mA
* + L6474_RESERVED_REG07
* + L6474_RESERVED_REG08
* + L6474_RESERVED_REG09
* + L6474_RESERVED_REG10
* + L6474_T_FAST
- * + L6474_TON_MIN
- * + L6474_TOFF_MIN
+ * + L6474_TON_MIN : value in us
+ * + L6474_TOFF_MIN : value in us
* + L6474_RESERVED_REG11
* + L6474_ADC_OUT
* + L6474_OCD_TH
@@ -329,9 +346,25 @@
* + L6474_RESERVED_REG14
* + L6474_INEXISTENT_REG
*/
- virtual void SetParameter(unsigned int parameter, unsigned int value)
+ virtual void SetParameter(unsigned int parameter, float value)
{
- L6474_CmdSetParam((L6474_Registers_t) parameter, (unsigned int) value);
+ float register_value;
+
+ switch ((L6474_Registers_t) parameter)
+ {
+ case L6474_TVAL:
+ register_value = L6474_Tval_Current_to_Par(value);
+ break;
+ case L6474_TON_MIN:
+ case L6474_TOFF_MIN:
+ register_value = L6474_Tmin_Time_to_Par(value);
+ break;
+ default:
+ register_value = value;
+ break;
+ }
+
+ L6474_CmdSetParam((L6474_Registers_t) parameter, (unsigned int) register_value);
}
/**
@@ -621,7 +654,7 @@
*/
void AttachFlagIRQ(void (*fptr)(void))
{
- flag_irq.rise(fptr);
+ flag_irq.fall(fptr);
}
/**
@@ -665,7 +698,7 @@
* DrvStatusTypeDef COMPONENT_ComputeAverage(void); //(3) *
*------------------------------------------------------------------------*/
void L6474_AttachErrorHandler(void (*callback)(uint16_t error));
- DrvStatusTypeDef L6474_Init(MOTOR_InitTypeDef *init);
+ DrvStatusTypeDef L6474_Init(L6474_InitTypeDef *init);
DrvStatusTypeDef L6474_ReadID(uint8_t *id);
uint16_t L6474_GetAcceleration(void);
uint16_t L6474_GetCurrentSpeed(void);
@@ -706,12 +739,15 @@
void L6474_ErrorHandler(uint16_t error);
void L6474_SendCommand(uint8_t param);
void L6474_SetRegisterToPredefinedValues(void);
+ void L6474_SetRegisterToInitializationValues(L6474_InitTypeDef *init);
void L6474_WriteBytes(uint8_t *pByteToTransmit, uint8_t *pReceivedByte);
void L6474_SetDeviceParamsToPredefinedValues(void);
void L6474_StartMovement(void);
void L6474_StepClockHandler(void);
- uint8_t L6474_Tval_Current_to_Par(double Tval);
- uint8_t L6474_Tmin_Time_to_Par(double Tmin);
+ float L6474_Tval_Current_to_Par(float current_mA);
+ float L6474_Par_to_Tval_Current(float Tval);
+ float L6474_Tmin_Time_to_Par(float ton_min_us);
+ float L6474_Par_to_Tmin_Time(float Tmin);
/*** Component's I/O Methods ***/
@@ -860,7 +896,7 @@
*/
uint8_t L6474_SpiWriteBytes(uint8_t *pByteToTransmit, uint8_t *pReceivedByte)
{
- return (uint8_t) (ReadWrite(pReceivedByte, pByteToTransmit, numberOfDevices) == COMPONENT_OK ? 0 : 1);
+ return (uint8_t) (ReadWrite(pReceivedByte, pByteToTransmit, number_of_devices) == COMPONENT_OK ? 0 : 1);
}
@@ -929,21 +965,21 @@
* static int number_of_instances; *
*------------------------------------------------------------------------*/
/* Data. */
- void (*errorHandlerCallback)(uint16_t error);
- deviceParams_t devicePrm;
- uint8_t deviceInstance;
+ void (*error_handler_callback)(uint16_t error);
+ deviceParams_t device_prm;
+ uint8_t device_instance;
/* Static data. */
- static uint8_t numberOfDevices;
- static uint8_t spiTxBursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
- static uint8_t spiRxBursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
+ static uint8_t number_of_devices;
+ static uint8_t spi_tx_bursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
+ static uint8_t spi_rx_bursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
public:
/* Static data. */
- static bool spiPreemtionByIsr;
- static bool isrFlag;
+ static bool spi_preemtion_by_isr;
+ static bool isr_flag;
};
#endif // __L6474_CLASS_H

X-NUCLEO-IHM01A1 Stepper Motor Driver