Skip to content

Commit 7c95515

Browse files
committed
ADC Sliding window test works
1 parent f7000f6 commit 7c95515

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

G4PERTESTING/Core/Src/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "spi.h"
3030
#include "tim.h"
3131
#include "usart.h"
32+
#include "malloc.h"
3233
/* Private includes ----------------------------------------------------------*/
3334
/* USER CODE BEGIN Includes */
3435

@@ -62,11 +63,11 @@ void SystemClock_Config(void);
6263

6364
/* Private user code ---------------------------------------------------------*/
6465
/* USER CODE BEGIN 0 */
65-
#define WINDOW_SIZE 2 // weighted average for now can extend to other window functions
66+
#define WINDOW_SIZE 10 // weighted average for now can extend to other window functions
6667
#define NUM_SIGNALS 1
6768
volatile uint16_t buffers[NUM_SIGNALS] = {0}; // Contains new values
6869
uint16_t outputs[NUM_SIGNALS] = {0}; // Updated averages
69-
uint16_t adcDataValues[NUM_SIGNALS][WINDOW_SIZE] = {0};
70+
uint16_t *adcDataValues[NUM_SIGNALS] = {0};
7071

7172
/* Enable ITM for SWO output */
7273
static void ITM_Enable(void)
@@ -152,6 +153,7 @@ int main(void)
152153
/* USER CODE BEGIN 2 */
153154
ADC_Configure();
154155
/* USER CODE END 2 */
156+
adcDataValues[0] = malloc(sizeof(uint16_t)*WINDOW_SIZE);
155157

156158
/* Infinite loop */
157159
/* USER CODE BEGIN WHILE */
@@ -170,6 +172,8 @@ int main(void)
170172
ADC_UpdateAnalogValues(adcDataValues, buffers, NUM_SIGNALS, WINDOW_SIZE, outputs);
171173
LOGOMATIC("Moving Average: %u\n", outputs[0]);
172174
}
175+
176+
free(adcDataValues[0]);
173177
}
174178

175179
/**

0 commit comments

Comments
 (0)