- Use camelCase for variable names and struct/enum declaration.
- Use PascalCase for struct/enum definition.
- Use descriptive names that clearly indicate the purpose of the variable.
- Append extensions _left and _right to variables representing left and right components, respectively.
- Avoid adding more extensions with underscore.
- Constants must be named in UPPERCASE.
Example:
- ADC offsets / slopes
#define CURRENT_SLOPE 54.4217687f /**< [A/V] (10/(4.7+10)) * ( 1 / (12.5 mV / A)) */
#define CURRENT_OFFSET 1.70068027211f /**< [V] (10/(4.7+10))* 2.5 V */
- Reference torque
torqueRef_left
torqueRef_right
- Encoder struct definition and declaration
typedef struct {} Encoder;
// Definition of Encoder structEncoder encoder_left;
// Declaration of an Encoder struct
- Dead-time and Switching time constants
DT
TS
- Use snake_case for function names.
- Use descriptive names that clearly indicate the purpose of the function, even if it seems too long.
Example:
initialize_inverter()
limit_torque_to_prevent_overspeed()
tasks_1ms()
- Self-developed .c/.h pairs must be named in UPPERCASE, making it easy to distinguish between them and autogenerated files.
Example:
MEASUREMENTS.c/.h
-> Self-developedadc.c/.h
-> Autogenerated
- Use common abbreviations only when they are widely understood within the context of the project.
- Avoid ambiguous or unclear abbreviations.
Example:
- ADC (Analog-to-Digital Converter)
- FSM (Finite State Machine)
- LUT (Look-Up Table)
- Every file and function must be preceded by a Doxygen style comment with a clear explanation of its purpose.
Example:
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file PCB_IO.c
* @brief This file provides functions for handling GPIOs.
******************************************************************************
* @attention
*
* Copyright (c) 2024 David Redondo (@dweggg in GitHub).
* All rights reserved.
*
* This software is licensed under the Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license.
* For more information, see: https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
*
******************************************************************************
*/
/* USER CODE END Header */
/**
* @brief Convert ADC reading to physical measurement with linear response.
* @param[in] bits The ADC reading.
* @param[in] slope The slope (volts per unit).
* @param[in] offset The offset (volts at zero).
* @retval measurement The physical measurement.
*/
float get_linear(uint32_t bits, float slope, float offset);
/**
* @brief Computes d-q currents from current measurements and electrical angle.
*
* This function computes the d-q currents from phase currents (ABC), theta_e, and stores
* the results in the provided pointers.
*
* @param[in] ia Phase A current in A.
* @param[in] ib Phase B current in A.
* @param[in] ic Phase C current in A.
* @param[in] theta_e Electrical rotor position in radians.
* @param[out] idMeas Pointer to store the D-axis current.
* @param[out] iqMeas Pointer to store the Q-axis current.
*/
void get_idiq(float ia, float ib, float ic, float theta_e, float *idMeas, float *iqMeas);