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.
Fork of X_NUCLEO_IHM01A1 by
Revision 18:2d6ab2b93685, committed 2016-01-13
- Comitter:
- Davidroid
- Date:
- Wed Jan 13 14:35:59 2016 +0000
- Parent:
- 17:35b9ca8c4bd6
- Child:
- 19:5f0b00a1e38d
- Commit message:
- + Initialization structure added.; + StepperMotor's GetParameters()/SetParameters() methods updated to handle floating-point numbers.; + L6474's GetParameters()/SetParameters() methods updated to re-format parameters.;
Changed in this revision
--- a/Components/Common/motor.h Mon Jan 04 15:54:07 2016 +0000
+++ b/Components/Common/motor.h Wed Jan 13 14:35:59 2016 +0000
@@ -193,18 +193,6 @@
* @}
*/
-/** @defgroup Motor_Driver_Initialization_Structure
- * @{
- */
-/// Motor driver initialization structure definition
-typedef struct
-{
- int placeholder;
-} MOTOR_InitTypeDef;
-/**
- * @}
- */
-
/** @defgroup Motor_Driver_Structure
* @{
*/
@@ -216,9 +204,9 @@
* Declare here component's generic functions. *
* *
* Example: *
- * DrvStatusTypeDef (*Init)(void *handle, INTERFACE_InitTypeDef *init); *
+ * DrvStatusTypeDef (*Init)(void *handle, void *init); *
*------------------------------------------------------------------------*/
- DrvStatusTypeDef (*Init)(void *handle, MOTOR_InitTypeDef *init);
+ DrvStatusTypeDef (*Init)(void *handle, void *init);
DrvStatusTypeDef (*ReadID)(void *handle, uint8_t *id);
/* Interrupts */
--- a/Components/Interfaces/StepperMotor_class.h Mon Jan 04 15:54:07 2016 +0000
+++ b/Components/Interfaces/StepperMotor_class.h Wed Jan 13 14:35:59 2016 +0000
@@ -76,7 +76,7 @@
* @param parameter The parameter's identifier (or its register address).
* @retval The parameter's value.
*/
- virtual unsigned int GetParameter(unsigned int parameter) = 0;
+ //virtual unsigned int GetParameter(unsigned int parameter) = 0;
/**
* @brief Getting the position.
@@ -140,7 +140,7 @@
* @param value The parameter's value.
* @retval None.
*/
- virtual void SetParameter(unsigned int parameter, unsigned int value) = 0;
+ //virtual void SetParameter(unsigned int parameter, unsigned int value) = 0;
/**
* @brief Setting the current position to be the home position.
--- a/Components/l6474/l6474.h Mon Jan 04 15:54:07 2016 +0000
+++ b/Components/l6474/l6474.h Wed Jan 13 14:35:59 2016 +0000
@@ -435,6 +435,70 @@
* @}
*/
+/** @defgroup Motor_Driver_Initialization_Structure
+ * @{
+ */
+/// Motor driver initialization structure definition
+typedef struct
+{
+ /* Acceleration rate in step/s2. Range: (0..+inf). */
+ int acceleration_step_s2;
+
+ /* Deceleration rate in step/s2. Range: (0..+inf). */
+ int deceleration_step_s2;
+
+ /* Maximum speed in step/s. Range: (30..10000]. */
+ int maximum_speed_step_s;
+
+ /* Minimum speed in step/s. Range: [30..10000). */
+ int minimum_speed_step_s;
+
+ /* Torque regulation current in mA. Range: 31.25mA to 4000mA. */
+ float torque_regulation_current_mA;
+
+ /* Overcurrent threshold (OCD_TH register). */
+ L6474_OCD_TH_t overcurrent_threshold;
+
+ /* Overcurrent shutwdown (OC_SD field of CONFIG register). */
+ L6474_CONFIG_OC_SD_t overcurrent_shutwdown;
+
+ /* Torque regulation method (EN_TQREG field of CONFIG register). */
+ L6474_CONFIG_EN_TQREG_t torque_regulation_method;
+
+ /* Step selection (STEP_SEL field of STEP_MODE register). */
+ L6474_STEP_SEL_t step_selection;
+
+ /* Sync selection (SYNC_SEL field of STEP_MODE register). */
+ L6474_SYNC_SEL_t sync_selection;
+
+ /* Fall time value (T_FAST field of T_FAST register). Range: 2us to 32us. */
+ L6474_FAST_STEP_t fall_time;
+
+ /* Maximum fast decay time (T_OFF field of T_FAST register). Range: 2us to 32us. */
+ L6474_TOFF_FAST_t maximum_fast_decay_time;
+
+ /* Minimum ON time in us (TON_MIN register). Range: 0.5us to 64us. */
+ float minimum_ON_time_us;
+
+ /* Minimum OFF time in us (TOFF_MIN register). Range: 0.5us to 64us. */
+ float minimum_OFF_time_us;
+
+ /* Target Swicthing Period (field TOFF of CONFIG register). */
+ L6474_CONFIG_TOFF_t target_swicthing_period;
+
+ /* Slew rate (POW_SR field of CONFIG register). */
+ L6474_CONFIG_POW_SR_t slew_rate;
+
+ /* Clock setting (OSC_CLK_SEL field of CONFIG register). */
+ L6474_CONFIG_OSC_MGMT_t clock;
+
+ /* Alarm (ALARM_EN register). */
+ int alarm;
+} L6474_InitTypeDef;
+/**
+ * @}
+ */
+
/**
* @brief L6474 driver data structure definition
*/
@@ -448,11 +512,14 @@
bool isrFlag; // = FALSE;
/// L6474 Device Paramaters structure
deviceParams_t devicePrm; //[MAX_NUMBER_OF_DEVICES];
- uint8_t numberOfDevices;
- uint8_t deviceInstance;
+ uint8_t number_of_devices;
+ uint8_t device_instance;
uint8_t spiTxBursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
uint8_t spiRxBursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
} L6474_DrvDataTypeDef;
+/**
+ * @}
+ */
/* Exported functions --------------------------------------------------------*/
--- a/Components/l6474/l6474_class.cpp Mon Jan 04 15:54:07 2016 +0000
+++ b/Components/l6474/l6474_class.cpp Wed Jan 13 14:35:59 2016 +0000
@@ -76,15 +76,15 @@
/* Variables ----------------------------------------------------------------*/
/* Number of devices. */
-uint8_t L6474::numberOfDevices = 0;
+uint8_t L6474::number_of_devices = 0;
/* ISR flags used to restart an interrupted SPI transfer when an error is reported. */
-bool L6474::spiPreemtionByIsr = FALSE;
-bool L6474::isrFlag = FALSE;
+bool L6474::spi_preemtion_by_isr = FALSE;
+bool L6474::isr_flag = FALSE;
/* SPI Transmission for Daisy-Chain Configuration. */
-uint8_t L6474::spiTxBursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
-uint8_t L6474::spiRxBursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
+uint8_t L6474::spi_tx_bursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
+uint8_t L6474::spi_rx_bursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
/* Methods -------------------------------------------------------------------*/
@@ -99,14 +99,15 @@
**********************************************************/
void L6474::L6474_AttachErrorHandler(void (*callback)(uint16_t error))
{
- errorHandlerCallback = (void (*)(uint16_t error)) callback;
+ error_handler_callback = (void (*)(uint16_t error)) callback;
}
/**********************************************************
* @brief Starts the L6474 library
- * @retval COMPONENT_OK in case of success
+ * @param init Initialization structure.
+ * @retval COMPONENT_OK in case of success.
**********************************************************/
-DrvStatusTypeDef L6474::L6474_Init(MOTOR_InitTypeDef *L6474_Init)
+DrvStatusTypeDef L6474::L6474_Init(L6474_InitTypeDef *init)
{
/* Initialise the PWMs used for the Step clocks ----------------------------*/
L6474_PwmInit();
@@ -119,9 +120,16 @@
/* Let a delay after reset */
L6474_Delay(1);
- /* Set all registers and context variables to the predefined values from l6474_target_config.h */
+ /* Set device parameters to the predefined values from "l6474_target_config.h". */
L6474_SetDeviceParamsToPredefinedValues();
+ if (init == NULL)
+ /* Set device registers to the predefined values from "l6474_target_config.h". */
+ L6474_SetRegisterToPredefinedValues();
+ else
+ /* Set device registers to the passed initialization values. */
+ L6474_SetRegisterToInitializationValues(init);
+
/* Disable L6474 powerstage */
L6474_CmdDisable();
@@ -134,11 +142,11 @@
/**********************************************************
* @brief Read id
* @param id pointer to the identifier to be read.
- * @retval COMPONENT_OK in case of success
+ * @retval COMPONENT_OK in case of success.
**********************************************************/
DrvStatusTypeDef L6474::L6474_ReadID(uint8_t *id)
{
- *id = deviceInstance;
+ *id = device_instance;
return COMPONENT_OK;
}
@@ -149,7 +157,7 @@
**********************************************************/
uint16_t L6474::L6474_GetAcceleration(void)
{
- return (devicePrm.acceleration);
+ return (device_prm.acceleration);
}
/**********************************************************
@@ -158,7 +166,7 @@
**********************************************************/
uint16_t L6474::L6474_GetCurrentSpeed(void)
{
- return devicePrm.speed;
+ return device_prm.speed;
}
/**********************************************************
@@ -167,7 +175,7 @@
**********************************************************/
uint16_t L6474::L6474_GetDeceleration(void)
{
- return (devicePrm.deceleration);
+ return (device_prm.deceleration);
}
/**********************************************************
@@ -176,7 +184,7 @@
**********************************************************/
motorState_t L6474::L6474_GetDeviceState(void)
{
- return devicePrm.motionState;
+ return device_prm.motionState;
}
/**********************************************************
@@ -204,7 +212,7 @@
**********************************************************/
uint16_t L6474::L6474_GetMaxSpeed(void)
{
- return (devicePrm.maxSpeed);
+ return (device_prm.maxSpeed);
}
/**********************************************************
@@ -213,7 +221,7 @@
**********************************************************/
uint16_t L6474::L6474_GetMinSpeed(void)
{
- return (devicePrm.minSpeed);
+ return (device_prm.minSpeed);
}
/**********************************************************
@@ -257,36 +265,36 @@
int32_t steps;
/* Eventually deactivate motor */
- if (devicePrm.motionState != INACTIVE)
+ if (device_prm.motionState != INACTIVE)
{
L6474_HardStop();
}
/* Get current position */
- devicePrm.currentPosition = L6474_ConvertPosition(L6474_CmdGetParam(L6474_ABS_POS));
+ device_prm.currentPosition = L6474_ConvertPosition(L6474_CmdGetParam(L6474_ABS_POS));
/* Compute the number of steps to perform */
- steps = targetPosition - devicePrm.currentPosition;
+ steps = targetPosition - device_prm.currentPosition;
if (steps >= 0)
{
- devicePrm.stepsToTake = steps;
+ device_prm.stepsToTake = steps;
direction = FORWARD;
}
else
{
- devicePrm.stepsToTake = -steps;
+ device_prm.stepsToTake = -steps;
direction = BACKWARD;
}
if (steps != 0)
{
- devicePrm.commandExecuted = MOVE_CMD;
+ device_prm.commandExecuted = MOVE_CMD;
/* Direction setup */
L6474_SetDirection(direction);
- L6474_ComputeSpeedProfile(devicePrm.stepsToTake);
+ L6474_ComputeSpeedProfile(device_prm.stepsToTake);
/* Motor activation */
L6474_StartMovement();
@@ -303,9 +311,9 @@
L6474_PwmStop();
/* Set inactive state */
- devicePrm.motionState = INACTIVE;
- devicePrm.commandExecuted = NO_CMD;
- devicePrm.stepsToTake = MAX_STEPS;
+ device_prm.motionState = INACTIVE;
+ device_prm.commandExecuted = NO_CMD;
+ device_prm.stepsToTake = MAX_STEPS;
}
/**********************************************************
@@ -317,18 +325,18 @@
void L6474::L6474_Move(motorDir_t direction, uint32_t stepCount)
{
/* Eventually deactivate motor */
- if (devicePrm.motionState != INACTIVE)
+ if (device_prm.motionState != INACTIVE)
{
L6474_HardStop();
}
if (stepCount != 0)
{
- devicePrm.stepsToTake = stepCount;
+ device_prm.stepsToTake = stepCount;
- devicePrm.commandExecuted = MOVE_CMD;
+ device_prm.commandExecuted = MOVE_CMD;
- devicePrm.currentPosition = L6474_ConvertPosition(L6474_CmdGetParam(L6474_ABS_POS));
+ device_prm.currentPosition = L6474_ConvertPosition(L6474_CmdGetParam(L6474_ABS_POS));
/* Direction setup */
L6474_SetDirection(direction);
@@ -349,7 +357,7 @@
void L6474::L6474_Run(motorDir_t direction)
{
/* Eventually deactivate motor */
- if (devicePrm.motionState != INACTIVE)
+ if (device_prm.motionState != INACTIVE)
{
L6474_HardStop();
}
@@ -357,7 +365,7 @@
/* Direction setup */
L6474_SetDirection(direction);
- devicePrm.commandExecuted = RUN_CMD;
+ device_prm.commandExecuted = RUN_CMD;
/* Motor activation */
L6474_StartMovement();
@@ -374,10 +382,10 @@
{
bool cmdExecuted = FALSE;
if ((newAcc != 0)&&
- ((devicePrm.motionState == INACTIVE)||
- (devicePrm.commandExecuted == RUN_CMD)))
+ ((device_prm.motionState == INACTIVE)||
+ (device_prm.commandExecuted == RUN_CMD)))
{
- devicePrm.acceleration = newAcc;
+ device_prm.acceleration = newAcc;
cmdExecuted = TRUE;
}
return cmdExecuted;
@@ -394,10 +402,10 @@
{
bool cmdExecuted = FALSE;
if ((newDec != 0)&&
- ((devicePrm.motionState == INACTIVE)||
- (devicePrm.commandExecuted == RUN_CMD)))
+ ((device_prm.motionState == INACTIVE)||
+ (device_prm.commandExecuted == RUN_CMD)))
{
- devicePrm.deceleration = newDec;
+ device_prm.deceleration = newDec;
cmdExecuted = TRUE;
}
return cmdExecuted;
@@ -434,11 +442,11 @@
bool cmdExecuted = FALSE;
if ((newMaxSpeed >= L6474_MIN_PWM_FREQ)&&
(newMaxSpeed <= L6474_MAX_PWM_FREQ) &&
- (devicePrm.minSpeed <= newMaxSpeed) &&
- ((devicePrm.motionState == INACTIVE)||
- (devicePrm.commandExecuted == RUN_CMD)))
+ (device_prm.minSpeed <= newMaxSpeed) &&
+ ((device_prm.motionState == INACTIVE)||
+ (device_prm.commandExecuted == RUN_CMD)))
{
- devicePrm.maxSpeed = newMaxSpeed;
+ device_prm.maxSpeed = newMaxSpeed;
cmdExecuted = TRUE;
}
return cmdExecuted;
@@ -456,11 +464,11 @@
bool cmdExecuted = FALSE;
if ((newMinSpeed >= L6474_MIN_PWM_FREQ)&&
(newMinSpeed <= L6474_MAX_PWM_FREQ) &&
- (newMinSpeed <= devicePrm.maxSpeed) &&
- ((devicePrm.motionState == INACTIVE)||
- (devicePrm.commandExecuted == RUN_CMD)))
+ (newMinSpeed <= device_prm.maxSpeed) &&
+ ((device_prm.motionState == INACTIVE)||
+ (device_prm.commandExecuted == RUN_CMD)))
{
- devicePrm.minSpeed = newMinSpeed;
+ device_prm.minSpeed = newMinSpeed;
cmdExecuted = TRUE;
}
return cmdExecuted;
@@ -474,9 +482,9 @@
bool L6474::L6474_SoftStop(void)
{
bool cmdExecuted = FALSE;
- if (devicePrm.motionState != INACTIVE)
+ if (device_prm.motionState != INACTIVE)
{
- devicePrm.commandExecuted = SOFT_STOP_CMD;
+ device_prm.commandExecuted = SOFT_STOP_CMD;
cmdExecuted = TRUE;
}
return (cmdExecuted);
@@ -520,12 +528,12 @@
uint32_t i;
uint32_t spiRxData;
uint8_t maxArgumentNbBytes = 0;
- uint8_t spiIndex = numberOfDevices - deviceInstance - 1;
+ uint8_t spiIndex = number_of_devices - device_instance - 1;
bool itDisable = FALSE;
do
{
- spiPreemtionByIsr = FALSE;
+ spi_preemtion_by_isr = FALSE;
if (itDisable)
{
/* re-enable L6474_EnableIrq if disable in previous iteration */
@@ -533,32 +541,32 @@
itDisable = FALSE;
}
- for (i = 0; i < numberOfDevices; i++)
+ for (i = 0; i < number_of_devices; i++)
{
- spiTxBursts[0][i] = L6474_NOP;
- spiTxBursts[1][i] = L6474_NOP;
- spiTxBursts[2][i] = L6474_NOP;
- spiTxBursts[3][i] = L6474_NOP;
- spiRxBursts[1][i] = 0;
- spiRxBursts[2][i] = 0;
- spiRxBursts[3][i] = 0;
+ spi_tx_bursts[0][i] = L6474_NOP;
+ spi_tx_bursts[1][i] = L6474_NOP;
+ spi_tx_bursts[2][i] = L6474_NOP;
+ spi_tx_bursts[3][i] = L6474_NOP;
+ spi_rx_bursts[1][i] = 0;
+ spi_rx_bursts[2][i] = 0;
+ spi_rx_bursts[3][i] = 0;
}
switch (parameter)
{
case L6474_ABS_POS: ;
case L6474_MARK:
- spiTxBursts[0][spiIndex] = ((uint8_t)L6474_GET_PARAM )| (parameter);
+ spi_tx_bursts[0][spiIndex] = ((uint8_t)L6474_GET_PARAM )| (parameter);
maxArgumentNbBytes = 3;
break;
case L6474_EL_POS: ;
case L6474_CONFIG: ;
case L6474_STATUS:
- spiTxBursts[1][spiIndex] = ((uint8_t)L6474_GET_PARAM )| (parameter);
+ spi_tx_bursts[1][spiIndex] = ((uint8_t)L6474_GET_PARAM )| (parameter);
maxArgumentNbBytes = 2;
break;
default:
- spiTxBursts[2][spiIndex] = ((uint8_t)L6474_GET_PARAM )| (parameter);
+ spi_tx_bursts[2][spiIndex] = ((uint8_t)L6474_GET_PARAM )| (parameter);
maxArgumentNbBytes = 1;
}
@@ -566,18 +574,18 @@
/* pre-emption by ISR and SPI transfers*/
L6474_DisableIrq();
itDisable = TRUE;
- } while (spiPreemtionByIsr); // check pre-emption by ISR
+ } while (spi_preemtion_by_isr); // check pre-emption by ISR
for (i = L6474_CMD_ARG_MAX_NB_BYTES-1-maxArgumentNbBytes;
i < L6474_CMD_ARG_MAX_NB_BYTES;
i++)
{
- L6474_WriteBytes(&spiTxBursts[i][0], &spiRxBursts[i][0]);
+ L6474_WriteBytes(&spi_tx_bursts[i][0], &spi_rx_bursts[i][0]);
}
- spiRxData = ((uint32_t)spiRxBursts[1][spiIndex] << 16) |
- (spiRxBursts[2][spiIndex] << 8) |
- (spiRxBursts[3][spiIndex]);
+ spiRxData = ((uint32_t)spi_rx_bursts[1][spiIndex] << 16) |
+ (spi_rx_bursts[2][spiIndex] << 8) |
+ (spi_rx_bursts[3][spiIndex]);
/* re-enable L6474_EnableIrq after SPI transfers*/
L6474_EnableIrq();
@@ -596,12 +604,12 @@
{
uint32_t i;
uint16_t status;
- uint8_t spiIndex = numberOfDevices - deviceInstance - 1;
+ uint8_t spiIndex = number_of_devices - device_instance - 1;
bool itDisable = FALSE;
do
{
- spiPreemtionByIsr = FALSE;
+ spi_preemtion_by_isr = FALSE;
if (itDisable)
{
/* re-enable L6474_EnableIrq if disable in previous iteration */
@@ -609,27 +617,27 @@
itDisable = FALSE;
}
- for (i = 0; i < numberOfDevices; i++)
+ for (i = 0; i < number_of_devices; i++)
{
- spiTxBursts[0][i] = L6474_NOP;
- spiTxBursts[1][i] = L6474_NOP;
- spiTxBursts[2][i] = L6474_NOP;
- spiRxBursts[1][i] = 0;
- spiRxBursts[2][i] = 0;
+ spi_tx_bursts[0][i] = L6474_NOP;
+ spi_tx_bursts[1][i] = L6474_NOP;
+ spi_tx_bursts[2][i] = L6474_NOP;
+ spi_rx_bursts[1][i] = 0;
+ spi_rx_bursts[2][i] = 0;
}
- spiTxBursts[0][spiIndex] = L6474_GET_STATUS;
+ spi_tx_bursts[0][spiIndex] = L6474_GET_STATUS;
/* Disable interruption before checking */
/* pre-emption by ISR and SPI transfers*/
L6474_DisableIrq();
itDisable = TRUE;
- } while (spiPreemtionByIsr); // check pre-emption by ISR
+ } while (spi_preemtion_by_isr); // check pre-emption by ISR
for (i = 0; i < L6474_CMD_ARG_NB_BYTES_GET_STATUS + L6474_RSP_NB_BYTES_GET_STATUS; i++)
{
- L6474_WriteBytes(&spiTxBursts[i][0], &spiRxBursts[i][0]);
+ L6474_WriteBytes(&spi_tx_bursts[i][0], &spi_rx_bursts[i][0]);
}
- status = (spiRxBursts[1][spiIndex] << 8) | (spiRxBursts[2][spiIndex]);
+ status = (spi_rx_bursts[1][spiIndex] << 8) | (spi_rx_bursts[2][spiIndex]);
/* re-enable L6474_EnableIrq after SPI transfers*/
L6474_EnableIrq();
@@ -656,11 +664,11 @@
{
uint32_t i;
uint8_t maxArgumentNbBytes = 0;
- uint8_t spiIndex = numberOfDevices - deviceInstance - 1;
+ uint8_t spiIndex = number_of_devices - device_instance - 1;
bool itDisable = FALSE;
do
{
- spiPreemtionByIsr = FALSE;
+ spi_preemtion_by_isr = FALSE;
if (itDisable)
{
/* re-enable L6474_EnableIrq if disable in previous iteration */
@@ -668,48 +676,48 @@
itDisable = FALSE;
}
- for (i = 0; i < numberOfDevices; i++)
+ for (i = 0; i < number_of_devices; i++)
{
- spiTxBursts[0][i] = L6474_NOP;
- spiTxBursts[1][i] = L6474_NOP;
- spiTxBursts[2][i] = L6474_NOP;
- spiTxBursts[3][i] = L6474_NOP;
+ spi_tx_bursts[0][i] = L6474_NOP;
+ spi_tx_bursts[1][i] = L6474_NOP;
+ spi_tx_bursts[2][i] = L6474_NOP;
+ spi_tx_bursts[3][i] = L6474_NOP;
}
switch (parameter)
{
case L6474_ABS_POS: ;
case L6474_MARK:
- spiTxBursts[0][spiIndex] = parameter;
- spiTxBursts[1][spiIndex] = (uint8_t)(value >> 16);
- spiTxBursts[2][spiIndex] = (uint8_t)(value >> 8);
+ spi_tx_bursts[0][spiIndex] = parameter;
+ spi_tx_bursts[1][spiIndex] = (uint8_t)(value >> 16);
+ spi_tx_bursts[2][spiIndex] = (uint8_t)(value >> 8);
maxArgumentNbBytes = 3;
break;
case L6474_EL_POS: ;
case L6474_CONFIG:
- spiTxBursts[1][spiIndex] = parameter;
- spiTxBursts[2][spiIndex] = (uint8_t)(value >> 8);
+ spi_tx_bursts[1][spiIndex] = parameter;
+ spi_tx_bursts[2][spiIndex] = (uint8_t)(value >> 8);
maxArgumentNbBytes = 2;
break;
default:
- spiTxBursts[2][spiIndex] = parameter;
+ spi_tx_bursts[2][spiIndex] = parameter;
maxArgumentNbBytes = 1;
break;
}
- spiTxBursts[3][spiIndex] = (uint8_t)(value);
+ spi_tx_bursts[3][spiIndex] = (uint8_t)(value);
/* Disable interruption before checking */
/* pre-emption by ISR and SPI transfers*/
L6474_DisableIrq();
itDisable = TRUE;
- } while (spiPreemtionByIsr); // check pre-emption by ISR
+ } while (spi_preemtion_by_isr); // check pre-emption by ISR
/* SPI transfer */
for (i = L6474_CMD_ARG_MAX_NB_BYTES-1-maxArgumentNbBytes;
i < L6474_CMD_ARG_MAX_NB_BYTES;
i++)
{
- L6474_WriteBytes(&spiTxBursts[i][0],&spiRxBursts[i][0]);
+ L6474_WriteBytes(&spi_tx_bursts[i][0],&spi_rx_bursts[i][0]);
}
/* re-enable L6474_EnableIrq after SPI transfers*/
L6474_EnableIrq();
@@ -757,7 +765,7 @@
}
/* Eventually deactivate motor */
- if (devicePrm.motionState != INACTIVE)
+ if (device_prm.motionState != INACTIVE)
{
L6474_HardStop();
}
@@ -779,7 +787,7 @@
**********************************************************/
motorDir_t L6474::L6474_GetDirection(void)
{
- return devicePrm.direction;
+ return device_prm.direction;
}
/**********************************************************
@@ -791,9 +799,9 @@
**********************************************************/
void L6474::L6474_SetDirection(motorDir_t direction)
{
- if (devicePrm.motionState == INACTIVE)
+ if (device_prm.motionState == INACTIVE)
{
- devicePrm.direction = direction;
+ device_prm.direction = direction;
L6474_SetDirectionGpio(direction);
}
}
@@ -814,7 +822,7 @@
newSpeed = L6474_MAX_PWM_FREQ;
}
- devicePrm.speed = newSpeed;
+ device_prm.speed = newSpeed;
L6474_PwmSetFreq(newSpeed);
}
@@ -838,23 +846,23 @@
uint32_t reqDecSteps;
/* compute the number of steps to get the targeted speed */
- uint16_t minSpeed = devicePrm.minSpeed;
- reqAccSteps = (devicePrm.maxSpeed - minSpeed);
- reqAccSteps *= (devicePrm.maxSpeed + minSpeed);
+ uint16_t minSpeed = device_prm.minSpeed;
+ reqAccSteps = (device_prm.maxSpeed - minSpeed);
+ reqAccSteps *= (device_prm.maxSpeed + minSpeed);
reqDecSteps = reqAccSteps;
- reqAccSteps /= (uint32_t)devicePrm.acceleration;
+ reqAccSteps /= (uint32_t)device_prm.acceleration;
reqAccSteps /= 2;
/* compute the number of steps to stop */
- reqDecSteps /= (uint32_t)devicePrm.deceleration;
+ reqDecSteps /= (uint32_t)device_prm.deceleration;
reqDecSteps /= 2;
if(( reqAccSteps + reqDecSteps ) > nbSteps)
{
/* Triangular move */
/* reqDecSteps = (Pos * Dec) /(Dec+Acc) */
- uint32_t dec = devicePrm.deceleration;
- uint32_t acc = devicePrm.acceleration;
+ uint32_t dec = device_prm.deceleration;
+ uint32_t acc = device_prm.acceleration;
reqDecSteps = ((uint32_t) dec * nbSteps) / (acc + dec);
if (reqDecSteps > 1)
@@ -869,8 +877,8 @@
{
reqAccSteps = 0;
}
- devicePrm.endAccPos = reqAccSteps;
- devicePrm.startDecPos = reqDecSteps;
+ device_prm.endAccPos = reqAccSteps;
+ device_prm.startDecPos = reqDecSteps;
}
else
{
@@ -878,8 +886,8 @@
/* accelerating phase to endAccPos */
/* steady phase from endAccPos to startDecPos */
/* decelerating from startDecPos to stepsToTake*/
- devicePrm.endAccPos = reqAccSteps;
- devicePrm.startDecPos = nbSteps - reqDecSteps - 1;
+ device_prm.endAccPos = reqAccSteps;
+ device_prm.startDecPos = nbSteps - reqDecSteps - 1;
}
}
@@ -916,9 +924,9 @@
**********************************************************/
void L6474::L6474_ErrorHandler(uint16_t error)
{
- if (errorHandlerCallback != 0)
+ if (error_handler_callback != 0)
{
- (void) errorHandlerCallback(error);
+ (void) error_handler_callback(error);
}
else
{
@@ -936,11 +944,11 @@
{
uint32_t i;
bool itDisable = FALSE;
- uint8_t spiIndex = numberOfDevices - deviceInstance - 1;
+ uint8_t spiIndex = number_of_devices - device_instance - 1;
do
{
- spiPreemtionByIsr = FALSE;
+ spi_preemtion_by_isr = FALSE;
if (itDisable)
{
/* re-enable L6474_EnableIrq if disable in previous iteration */
@@ -948,19 +956,19 @@
itDisable = FALSE;
}
- for (i = 0; i < numberOfDevices; i++)
+ for (i = 0; i < number_of_devices; i++)
{
- spiTxBursts[3][i] = L6474_NOP;
+ spi_tx_bursts[3][i] = L6474_NOP;
}
- spiTxBursts[3][spiIndex] = param;
+ spi_tx_bursts[3][spiIndex] = param;
/* Disable interruption before checking */
/* pre-emption by ISR and SPI transfers*/
L6474_DisableIrq();
itDisable = TRUE;
- } while (spiPreemtionByIsr); // check pre-emption by ISR
+ } while (spi_preemtion_by_isr); // check pre-emption by ISR
- L6474_WriteBytes(&spiTxBursts[3][0], &spiRxBursts[3][0]);
+ L6474_WriteBytes(&spi_tx_bursts[3][0], &spi_rx_bursts[3][0]);
/* re-enable L6474_EnableIrq after SPI transfers*/
L6474_EnableIrq();
@@ -982,7 +990,7 @@
L6474_CmdSetParam(
L6474_MARK,
0);
- switch (deviceInstance)
+ switch (device_instance)
{
case 0:
L6474_CmdSetParam(
@@ -1086,6 +1094,65 @@
}
/**********************************************************
+ * @brief Sets the registers of the L6474 to initialization values.
+ * @param init Initialization structure.
+ * @retval None.
+ **********************************************************/
+void L6474::L6474_SetRegisterToInitializationValues(L6474_InitTypeDef *init)
+{
+ L6474_CmdSetParam(
+ L6474_ABS_POS,
+ 0
+ );
+ L6474_CmdSetParam(
+ L6474_EL_POS,
+ 0
+ );
+ L6474_CmdSetParam(
+ L6474_MARK,
+ 0
+ );
+ L6474_CmdSetParam(
+ L6474_TVAL,
+ L6474_Tval_Current_to_Par(init->torque_regulation_current_mA)
+ );
+ L6474_CmdSetParam(
+ L6474_T_FAST,
+ (uint8_t) init->maximum_fast_decay_time |
+ (uint8_t) init->fall_time
+ );
+ L6474_CmdSetParam(
+ L6474_TON_MIN,
+ L6474_Tmin_Time_to_Par(init->minimum_ON_time_us)
+ );
+ L6474_CmdSetParam(
+ L6474_TOFF_MIN,
+ L6474_Tmin_Time_to_Par(init->minimum_OFF_time_us)
+ );
+ L6474_CmdSetParam(
+ L6474_OCD_TH,
+ init->overcurrent_threshold
+ );
+ L6474_CmdSetParam(
+ L6474_STEP_MODE,
+ (uint8_t) init->step_selection |
+ (uint8_t) init->sync_selection
+ );
+ L6474_CmdSetParam(
+ L6474_ALARM_EN,
+ init->alarm
+ );
+ L6474_CmdSetParam(
+ L6474_CONFIG,
+ (uint16_t) init->clock |
+ (uint16_t) init->torque_regulation_method |
+ (uint16_t) init->overcurrent_shutwdown |
+ (uint16_t) init->slew_rate |
+ (uint16_t) init->target_swicthing_period
+ );
+}
+
+/**********************************************************
* @brief Sets the parameters of the device to predefined values
* from l6474_target_config.h
* @param None
@@ -1093,42 +1160,40 @@
**********************************************************/
void L6474::L6474_SetDeviceParamsToPredefinedValues(void)
{
- switch (deviceInstance)
+ switch (device_instance)
{
case 0:
- devicePrm.acceleration = L6474_CONF_PARAM_ACC_DEVICE_0;
- devicePrm.deceleration = L6474_CONF_PARAM_DEC_DEVICE_0;
- devicePrm.maxSpeed = L6474_CONF_PARAM_MAX_SPEED_DEVICE_0;
- devicePrm.minSpeed = L6474_CONF_PARAM_MIN_SPEED_DEVICE_0;
+ device_prm.acceleration = L6474_CONF_PARAM_ACC_DEVICE_0;
+ device_prm.deceleration = L6474_CONF_PARAM_DEC_DEVICE_0;
+ device_prm.maxSpeed = L6474_CONF_PARAM_MAX_SPEED_DEVICE_0;
+ device_prm.minSpeed = L6474_CONF_PARAM_MIN_SPEED_DEVICE_0;
break;
case 1:
- devicePrm.acceleration = L6474_CONF_PARAM_ACC_DEVICE_1;
- devicePrm.deceleration = L6474_CONF_PARAM_DEC_DEVICE_1;
- devicePrm.maxSpeed = L6474_CONF_PARAM_MAX_SPEED_DEVICE_1;
- devicePrm.minSpeed = L6474_CONF_PARAM_MIN_SPEED_DEVICE_1;
+ device_prm.acceleration = L6474_CONF_PARAM_ACC_DEVICE_1;
+ device_prm.deceleration = L6474_CONF_PARAM_DEC_DEVICE_1;
+ device_prm.maxSpeed = L6474_CONF_PARAM_MAX_SPEED_DEVICE_1;
+ device_prm.minSpeed = L6474_CONF_PARAM_MIN_SPEED_DEVICE_1;
break;
case 2:
- devicePrm.acceleration = L6474_CONF_PARAM_ACC_DEVICE_2;
- devicePrm.deceleration = L6474_CONF_PARAM_DEC_DEVICE_2;
- devicePrm.maxSpeed = L6474_CONF_PARAM_MAX_SPEED_DEVICE_2;
- devicePrm.minSpeed = L6474_CONF_PARAM_MIN_SPEED_DEVICE_2;
+ device_prm.acceleration = L6474_CONF_PARAM_ACC_DEVICE_2;
+ device_prm.deceleration = L6474_CONF_PARAM_DEC_DEVICE_2;
+ device_prm.maxSpeed = L6474_CONF_PARAM_MAX_SPEED_DEVICE_2;
+ device_prm.minSpeed = L6474_CONF_PARAM_MIN_SPEED_DEVICE_2;
break;
}
- devicePrm.accu = 0;
- devicePrm.currentPosition = 0;
- devicePrm.endAccPos = 0;
- devicePrm.relativePos = 0;
- devicePrm.startDecPos = 0;
- devicePrm.stepsToTake = 0;
- devicePrm.speed = 0;
- devicePrm.commandExecuted = NO_CMD;
- devicePrm.direction = FORWARD;
- devicePrm.motionState = INACTIVE;
-
- L6474_SetRegisterToPredefinedValues();
+ device_prm.accu = 0;
+ device_prm.currentPosition = 0;
+ device_prm.endAccPos = 0;
+ device_prm.relativePos = 0;
+ device_prm.startDecPos = 0;
+ device_prm.stepsToTake = 0;
+ device_prm.speed = 0;
+ device_prm.commandExecuted = NO_CMD;
+ device_prm.direction = FORWARD;
+ device_prm.motionState = INACTIVE;
}
/**********************************************************
@@ -1140,17 +1205,17 @@
{
/* Enable L6474 powerstage */
L6474_CmdEnable();
- if (devicePrm.endAccPos != 0)
+ if (device_prm.endAccPos != 0)
{
- devicePrm.motionState = ACCELERATING;
+ device_prm.motionState = ACCELERATING;
}
else
{
- devicePrm.motionState = DECELERATING;
+ device_prm.motionState = DECELERATING;
}
- devicePrm.accu = 0;
- devicePrm.relativePos = 0;
- L6474_ApplySpeed(devicePrm.minSpeed);
+ device_prm.accu = 0;
+ device_prm.relativePos = 0;
+ L6474_ApplySpeed(device_prm.minSpeed);
}
/**********************************************************
@@ -1161,107 +1226,107 @@
void L6474::L6474_StepClockHandler(void)
{
/* Set isr flag */
- isrFlag = TRUE;
+ isr_flag = TRUE;
/* Incrementation of the relative position */
- devicePrm.relativePos++;
+ device_prm.relativePos++;
- switch (devicePrm.motionState)
+ switch (device_prm.motionState)
{
case ACCELERATING:
{
- uint32_t relPos = devicePrm.relativePos;
- uint32_t endAccPos = devicePrm.endAccPos;
- uint16_t speed = devicePrm.speed;
- uint32_t acc = ((uint32_t)devicePrm.acceleration << 16);
+ uint32_t relPos = device_prm.relativePos;
+ uint32_t endAccPos = device_prm.endAccPos;
+ uint16_t speed = device_prm.speed;
+ uint32_t acc = ((uint32_t)device_prm.acceleration << 16);
- if ((devicePrm.commandExecuted == SOFT_STOP_CMD)||
- ((devicePrm.commandExecuted != RUN_CMD)&&
- (relPos == devicePrm.startDecPos)))
+ if ((device_prm.commandExecuted == SOFT_STOP_CMD)||
+ ((device_prm.commandExecuted != RUN_CMD)&&
+ (relPos == device_prm.startDecPos)))
{
- devicePrm.motionState = DECELERATING;
- devicePrm.accu = 0;
+ device_prm.motionState = DECELERATING;
+ device_prm.accu = 0;
}
- else if ((speed >= devicePrm.maxSpeed)||
- ((devicePrm.commandExecuted != RUN_CMD)&&
+ else if ((speed >= device_prm.maxSpeed)||
+ ((device_prm.commandExecuted != RUN_CMD)&&
(relPos == endAccPos)))
{
- devicePrm.motionState = STEADY;
+ device_prm.motionState = STEADY;
}
else
{
bool speedUpdated = FALSE;
/* Go on accelerating */
if (speed == 0) speed =1;
- devicePrm.accu += acc / speed;
- while (devicePrm.accu >= (0X10000L))
+ device_prm.accu += acc / speed;
+ while (device_prm.accu >= (0X10000L))
{
- devicePrm.accu -= (0X10000L);
+ device_prm.accu -= (0X10000L);
speed +=1;
speedUpdated = TRUE;
}
if (speedUpdated)
{
- if (speed > devicePrm.maxSpeed)
+ if (speed > device_prm.maxSpeed)
{
- speed = devicePrm.maxSpeed;
+ speed = device_prm.maxSpeed;
}
- devicePrm.speed = speed;
- L6474_ApplySpeed(devicePrm.speed);
+ device_prm.speed = speed;
+ L6474_ApplySpeed(device_prm.speed);
}
}
break;
}
case STEADY:
{
- uint16_t maxSpeed = devicePrm.maxSpeed;
- uint32_t relativePos = devicePrm.relativePos;
- if ((devicePrm.commandExecuted == SOFT_STOP_CMD)||
- ((devicePrm.commandExecuted != RUN_CMD)&&
- (relativePos >= (devicePrm.startDecPos))) ||
- ((devicePrm.commandExecuted == RUN_CMD)&&
- (devicePrm.speed > maxSpeed)))
+ uint16_t maxSpeed = device_prm.maxSpeed;
+ uint32_t relativePos = device_prm.relativePos;
+ if ((device_prm.commandExecuted == SOFT_STOP_CMD)||
+ ((device_prm.commandExecuted != RUN_CMD)&&
+ (relativePos >= (device_prm.startDecPos))) ||
+ ((device_prm.commandExecuted == RUN_CMD)&&
+ (device_prm.speed > maxSpeed)))
{
- devicePrm.motionState = DECELERATING;
- devicePrm.accu = 0;
+ device_prm.motionState = DECELERATING;
+ device_prm.accu = 0;
}
- else if ((devicePrm.commandExecuted == RUN_CMD)&&
- (devicePrm.speed < maxSpeed))
+ else if ((device_prm.commandExecuted == RUN_CMD)&&
+ (device_prm.speed < maxSpeed))
{
- devicePrm.motionState = ACCELERATING;
- devicePrm.accu = 0;
+ device_prm.motionState = ACCELERATING;
+ device_prm.accu = 0;
}
break;
}
case DECELERATING:
{
- uint32_t relativePos = devicePrm.relativePos;
- uint16_t speed = devicePrm.speed;
- uint32_t deceleration = ((uint32_t)devicePrm.deceleration << 16);
- if (((devicePrm.commandExecuted == SOFT_STOP_CMD)&&(speed <= devicePrm.minSpeed))||
- ((devicePrm.commandExecuted != RUN_CMD)&&
- (relativePos >= devicePrm.stepsToTake)))
+ uint32_t relativePos = device_prm.relativePos;
+ uint16_t speed = device_prm.speed;
+ uint32_t deceleration = ((uint32_t)device_prm.deceleration << 16);
+ if (((device_prm.commandExecuted == SOFT_STOP_CMD)&&(speed <= device_prm.minSpeed))||
+ ((device_prm.commandExecuted != RUN_CMD)&&
+ (relativePos >= device_prm.stepsToTake)))
{
/* Motion process complete */
L6474_HardStop();
}
- else if ((devicePrm.commandExecuted == RUN_CMD)&&
- (speed <= devicePrm.maxSpeed))
+ else if ((device_prm.commandExecuted == RUN_CMD)&&
+ (speed <= device_prm.maxSpeed))
{
- devicePrm.motionState = STEADY;
+ device_prm.motionState = STEADY;
}
else
{
/* Go on decelerating */
- if (speed > devicePrm.minSpeed)
+ if (speed > device_prm.minSpeed)
{
bool speedUpdated = FALSE;
if (speed == 0) speed =1;
- devicePrm.accu += deceleration / speed;
- while (devicePrm.accu >= (0X10000L))
+ device_prm.accu += deceleration / speed;
+ while (device_prm.accu >= (0X10000L))
{
- devicePrm.accu -= (0X10000L);
+ device_prm.accu -= (0X10000L);
if (speed > 1)
{
speed -=1;
@@ -1271,12 +1336,12 @@
if (speedUpdated)
{
- if (speed < devicePrm.minSpeed)
+ if (speed < device_prm.minSpeed)
{
- speed = devicePrm.minSpeed;
+ speed = device_prm.minSpeed;
}
- devicePrm.speed = speed;
- L6474_ApplySpeed(devicePrm.speed);
+ device_prm.speed = speed;
+ L6474_ApplySpeed(device_prm.speed);
}
}
}
@@ -1288,28 +1353,47 @@
}
}
/* Set isr flag */
- isrFlag = FALSE;
+ isr_flag = FALSE;
+}
+
+/**********************************************************
+ * @brief Converts current in mA to values for TVAL register
+ * @param[in] current_mA current in mA
+ * @retval value for TVAL register
+ **********************************************************/
+float L6474::L6474_Tval_Current_to_Par(float current_mA)
+{
+ return ((float)(((current_mA - 31.25f) / 31.25f) + 0.5f));
}
/**********************************************************
- * @brief Converts mA in compatible values for TVAL register
- * @param[in] Tval
- * @retval TVAL values
+ * @brief Converts values from TVAL register to mA
+ * @param[in] Tval value from TVAL register
+ * @retval current in mA
**********************************************************/
-uint8_t L6474::L6474_Tval_Current_to_Par(double Tval)
+float L6474::L6474_Par_to_Tval_Current(float Tval)
{
- return ((uint8_t)(((Tval - 31.25)/31.25)+0.5));
+ return ((float)((Tval - 0.5f) * 31.25f + 31.25f));
}
/**********************************************************
- * @brief Convert time in us in compatible values
- * for TON_MIN register
- * @param[in] Tmin
- * @retval TON_MIN values
+ * @brief Convert time in us to values for TON_MIN register
+ * @param[in] ton_min_us time in us
+ * @retval value for TON_MIN register
**********************************************************/
-uint8_t L6474::L6474_Tmin_Time_to_Par(double Tmin)
+float L6474::L6474_Tmin_Time_to_Par(float ton_min_us)
{
- return ((uint8_t)(((Tmin - 0.5)*2)+0.5));
+ return ((float)(((ton_min_us - 0.5f) * 2.0f) + 0.5f));
+}
+
+/**********************************************************
+ * @brief Convert values for TON_MIN register to time in us
+ * @param[in] Tmin value from TON_MIN register
+ * @retval time in us
+ **********************************************************/
+float L6474::L6474_Par_to_Tmin_Time(float Tmin)
+{
+ return ((float)(((Tmin - 0.5f) / 2.0f) + 0.5f));
}
/**********************************************************
@@ -1325,9 +1409,9 @@
L6474_ErrorHandler(L6474_ERROR_1);
}
- if (isrFlag)
+ if (isr_flag)
{
- spiPreemtionByIsr = TRUE;
+ spi_preemtion_by_isr = TRUE;
}
}
--- 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
--- a/Components/l6474/l6474_target_config.h Mon Jan 04 15:54:07 2016 +0000 +++ b/Components/l6474/l6474_target_config.h Wed Jan 13 14:35:59 2016 +0000 @@ -215,22 +215,6 @@ #define L6474_CONF_PARAM_CLOCK_SETTING_DEVICE_2 (L6474_CONFIG_INT_16MHZ) -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - #ifdef __cplusplus } #endif
