Small jitter to avoid schwebung

This commit is contained in:
2025-12-24 14:17:27 +01:00
parent 27c686479a
commit 9f4cab68d9
2 changed files with 8 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
help:
# plot - Plot the latest measurement
# monitor - Build and monitor onto esp if connected to /dev/ttyUSB0
# mon - Monitor onto esp if connected to /dev/ttyUSB0
# push - Build and monitor onto esp if connected to /dev/ttyUSB0
# env - Start the esp environment on nix
# server - Start the go server

View File

@@ -1,9 +1,9 @@
/*
Voltage measurement device over WiFi (batched, 30 Hz)
Voltage measurement device over WiFi (batched, ~30 Hz with jitter)
*/
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
@@ -11,7 +11,6 @@
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "esp_adc/adc_cali.h"
#include "esp_adc/adc_oneshot.h"
#include "esp_adc/adc_cali_scheme.h"
@@ -21,12 +20,12 @@
#define SERVER_URL "http://192.168.178.157:8080/data"
#define SAMPLE_RATE_HZ 30
#define SAMPLE_RATE_HZ 20
#define SAMPLE_PERIOD_MS (1000 / SAMPLE_RATE_HZ)
#define BATCH_SIZE 100
#define CHANNEL ADC_CHANNEL_6
#define CALIBRATION_FACTOR 1650.0f
#define CALIBRATION_FACTOR 1600.0f
#define EXAMPLE_ESP_WIFI_SSID "Jaguar"
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
@@ -193,8 +192,9 @@ static void measure_task(void *arg)
count = 0;
}
int jitter = (rand() % 10) - 5; // ±2 ms random
vTaskDelayUntil(&last_wake,
pdMS_TO_TICKS(SAMPLE_PERIOD_MS));
pdMS_TO_TICKS(SAMPLE_PERIOD_MS + jitter));
}
}