DIY Logging Volt/Ampmeter
|
Go to the documentation of this file.
119 #define MAX_WHILELOOPS_METER_RESPONSE 9000
122 #define SHUTDOWN_DELAY_UART_MODULE_MS 500
125 #define STARTUP_DELAY_UART_MODULE_MS 2000
128 #define VBAT_MEASUREMENT_PERIOD_S 10
153 static const uint16_t
LUT_period_s[16] = {0, 1, 2, 5, 10, 15, 30, 60, 120, 300, 600, 900, 1800, 3600, 7200, 18000};
220 LL_TIM_CC_EnableChannel(
TIM3, LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH2);
223 LL_TIM_EnableCounter(
TIM3);
226 LL_TIM_GenerateEvent_UPDATE(
TIM3);
296 uint16_t whileLoops = 0;
331 if (oldPower != power)
489 LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);
490 while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_0)
493 LL_RCC_HSI_SetCalibTrimming(16);
497 while(LL_RCC_HSI_IsReady() != 1)
501 LL_PWR_EnableBkUpAccess();
505 while(LL_RCC_LSE_IsReady() != 1)
509 if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE)
511 LL_RCC_ForceBackupDomainReset();
512 LL_RCC_ReleaseBackupDomainReset();
513 LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE);
516 LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
517 LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
518 LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
519 LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI);
522 while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
533 LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSRC_PCLK2_DIV_2);
659 uint16_t encValue = LL_TIM_GetCounter(
TIM3);
664 while ((encValue % 4) > 0) encValue++;
673 for (uint8_t counter = 0; counter < steps; counter++)
791 for (int8_t counter = 0; counter > steps; counter--)
923 USART1_print(
"Date and Time [day/month/year hour:min:sec],Runtime [hour:min:sec],Voltage [V],Current [A],Power [W]\r\n");
924 SEGGER_RTT_printf(0,
"Date and Time [day/month/year hour:min:sec], Runtime [hour:min:sec], Voltage [V], Current [A], Power [W]\r\n");
939 USART1_print(
"Total runtime [hour:min:sec],Capacity [Ah],Capacity [Wh],Max Volt [V],Min Volt [V],Max Curr [A],Min Curr [A]\r\n");
940 SEGGER_RTT_printf(0,
"Total runtime [hour:min:sec], Capacity [Ah], Capacity [Wh], Max Volt [V], Min Volt [V], Max Curr [A], Min Curr [A]\r\n");
1113 #ifdef USE_FULL_ASSERT
1121 void assert_failed(uint8_t *file, uint32_t line)
void displaySaveIcon(void)
Function to display the SAVE status icon on the RIGHT OLED screen.
void checkSwitches(void)
Function to handle switch presses.
void startBattVoltMeasurement(void)
void checkEncoder(void)
Function to handle encoder rotation logic.
void USART1_INIT(void)
USART1 Initialization Function.
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
void LL_SetSystemCoreClock(uint32_t HCLKFrequency)
This function sets directly SystemCoreClock CMSIS variable.
#define SHUTDOWN_DELAY_UART_MODULE_MS
This file contains all the function prototypes for the tim.c file.
void USART2_SendCommand(uint8_t *command, uint8_t bytes)
Send a byte (uint8_t) command to USART2.
void USART3_SendCommand(uint8_t *command, uint8_t bytes)
Send a byte (uint8_t) command to USART3.
#define UART1_DTRout_GPIO_Port
This file contains all the function prototypes for the adc.c file.
volatile uint8_t loggerReady
struct Settings_t settings
static const uint8_t aBY56W_SingleRead[4]
void writeMeasurements(void)
Function to print measurement data.
void setSW1(uint8_t value)
void setSW0(uint8_t value)
#define STARTUP_DELAY_UART_MODULE_MS
void USART_HandleContinuousReception(void)
This function monitors USART1/2/3 buffer filling indication and moves data around accordingly.
void convertValues(void)
Function to convert the measurements to char-arrays.
static const uint8_t LUT_period_s_length
#define TICK_INT_PRIORITY
#define UART1_3V3out_GPIO_Port
U(S)ART functionality for high-precision logging voltage/current meter.
void writeHeader(void)
Function to print the header of the logfile to indicate the columns.
void initDataStruct(void)
Function to initialize/reset the values in the data-struct.
void writeToRTC(void)
Function to update the RTC values according to the data in the struct.
void updateRightDisplay(void)
Function to display updated info on the RIGHT OLED screen.
void initDisplays(void)
Function to initialize the OLED displays.
void forceConversion(void)
Function to force a conversion of all values not (yet) displayed on the OLED screens.
#define VBAT_MEASUREMENT_PERIOD_S
unsigned SEGGER_RTT_WriteString(unsigned BufferIndex, const char *s)
static const uint16_t LUT_period_s[16]
Conversion and settings-related methods and structs for high-precision logging voltage/current meter.
void SystemClock_Config(void)
System Clock Configuration.
HAL_StatusTypeDef HAL_Init(void)
int main(void)
The application entry point.
Display updating functionality for high-precision logging voltage/current meter.
struct RTC_dateTime_t rtc
uint8_t decSecondPassed(void)
Function to decrease the value of secondPassed.
Main header-file for the high-precision logging voltage/current meter project.
This file contains all the function prototypes for the gpio.c file.
void readFromRTC(void)
Function to update the RTC data in the struct.
void initSettingsStruct(void)
Function to initialize/reset the values in the settings-struct.
volatile uint8_t secPassed
int SEGGER_RTT_printf(unsigned BufferIndex, const char *sFormat,...)
uint32_t HAL_GetTick(void)
RTC functionality for high-precision logging voltage/current meter.
#define MAX_WHILELOOPS_METER_RESPONSE
void USART3_INIT(void)
USART3 Initialization Function.
void USART1_print(char *message)
Print a string (char array) to USARTx.
void USART2_INIT(void)
USART2 Initialization Function.
void setENCkey(uint8_t value)
void Activate_ADC(void)
Perform ADC activation procedure to make it ready to convert (ADC instance: ADC2).
This file contains all the function prototypes for the i2c.c file.
Utility functionality for high-precision logging voltage/current meter.
void finishDisplayUpdates(void)
Function to finish the screen-updates.
void Error_Handler(void)
This function is executed in case of error occurrence.
void updateLeftDisplay(void)
Function to display updated info on the LEFT OLED screen.
void writeFooter(void)
Function to print the footer of the logfile (two lines).
void RTC_Init(void)
Function to initialize the Real Time Clock.