change wss to moving sum
This commit is contained in:
parent
2afdfa8293
commit
75950a226d
@ -40,6 +40,7 @@
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
#define TIM_BASE_FREQ 96000000UL
|
||||
#define WSS_HISTORY_SIZE 10
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
@ -66,6 +67,9 @@ TIM_HandleTypeDef* PWM_TIM_MAP[3] = {&htim1, &htim4, &htim3};
|
||||
static uint8_t pwm_ch_active[8];
|
||||
|
||||
static uint16_t wss_flanks[2];
|
||||
static uint16_t wss_flanks_avg[2];
|
||||
static uint8_t wss_flanks_history[2][WSS_HISTORY_SIZE];
|
||||
static uint8_t wss_flanks_history_idx[2]; // index of the oldest entry (next to be overwritten)
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@ -119,7 +123,11 @@ void loop_1kHz() {
|
||||
break;
|
||||
|
||||
case FIN:
|
||||
value = wss_flanks[signal->channel];
|
||||
uint8_t oldest_hist_idx = wss_flanks_history_idx[signal->channel];
|
||||
// subtract oldest entry from avg
|
||||
wss_flanks_avg[signal->channel] -= wss_flanks_history[signal->channel][oldest_hist_idx];
|
||||
// overwrite oldest history entry with new value and reset counter
|
||||
wss_flanks_history[signal->channel][oldest_hist_idx] = wss_flanks[signal->channel];
|
||||
wss_flanks[signal->channel] = 0;
|
||||
break;
|
||||
|
||||
@ -247,6 +255,10 @@ int main(void)
|
||||
mscounter = 0;
|
||||
setup_complete = 1;
|
||||
|
||||
memset(wss_flanks, 0, sizeof(wss_flanks));
|
||||
memset(wss_flanks_avg, 0, sizeof(wss_flanks));
|
||||
memset(wss_flanks_history, 0, sizeof(wss_flanks_history));
|
||||
memset(wss_flanks_history_idx, 0, sizeof(wss_flanks_history_idx));
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
|
Loading…
x
Reference in New Issue
Block a user