change wss to moving sum
This commit is contained in:
parent
2afdfa8293
commit
75950a226d
@ -40,6 +40,7 @@
|
|||||||
/* Private define ------------------------------------------------------------*/
|
/* Private define ------------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN PD */
|
/* USER CODE BEGIN PD */
|
||||||
#define TIM_BASE_FREQ 96000000UL
|
#define TIM_BASE_FREQ 96000000UL
|
||||||
|
#define WSS_HISTORY_SIZE 10
|
||||||
/* USER CODE END PD */
|
/* USER CODE END PD */
|
||||||
|
|
||||||
/* Private macro -------------------------------------------------------------*/
|
/* Private macro -------------------------------------------------------------*/
|
||||||
@ -66,6 +67,9 @@ TIM_HandleTypeDef* PWM_TIM_MAP[3] = {&htim1, &htim4, &htim3};
|
|||||||
static uint8_t pwm_ch_active[8];
|
static uint8_t pwm_ch_active[8];
|
||||||
|
|
||||||
static uint16_t wss_flanks[2];
|
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 */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
@ -119,7 +123,11 @@ void loop_1kHz() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case FIN:
|
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;
|
wss_flanks[signal->channel] = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -247,6 +255,10 @@ int main(void)
|
|||||||
mscounter = 0;
|
mscounter = 0;
|
||||||
setup_complete = 1;
|
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 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user