miniFOC 1.0.3
This open-source project aims to accomplish a FOC(Field Oriented Control) scheme that is operatable with minimum costs in China.
filter.c
Go to the documentation of this file.
1/**************************************************************************/
11#include "filter.h"
12#include "system.h"
13#include "foc.h"
14#include "config.h"
15
20
28void filter_coefficient_config(Filter_Structure_t *param, float cutoff_freq, float sample_freq, float coefficient) {
29 /* clear the value of the first order low pass filter parameter handler */
30 user_memset(param, 0x00, sizeof(Filter_Structure_t));
31
32 /* the RC time constant is calculated from the cut-off frequency */
33 float time_const = 1.0f / (6.2831852f * cutoff_freq);
34
35 /* calculation of digital low-pass filter coefficients */
36 param->coefficient1 = (1.0f / (1.0f + time_const * sample_freq)) * coefficient;
37 param->coefficient2 = (time_const * sample_freq) / (1.0f + time_const * sample_freq);
38 param->current_result = 0;
39 param->last_result = 0;
40}
41
45void filter_config(void) {
48}
49
56float filter_update_value(Filter_Structure_t *param, short value) {
57 /* judge whether the input parameters are abnormal,
58 * calculate the output value of the first-order low-pass filter */
59 if (value < 200 && value > -200)
60 param->current_result = param->coefficient1 * (float) value + param->coefficient2 * param->last_result;
61
62 /* update the output value of the previous time */
63 param->last_result = param->current_result;
64 return param->current_result;
65}
used to place important parameter configurations for users
#define SPEED_UP_FREQ
set speed update frequency to 200Hz
Definition: config.h:32
#define TIM13_FREQUENCY
set speed/angle PID loop frequency to 100Hz
Definition: config.h:30
void filter_coefficient_config(Filter_Structure_t *param, float cutoff_freq, float sample_freq, float coefficient)
configure low-pass filter parameters
Definition: filter.c:28
float filter_update_value(Filter_Structure_t *param, short value)
update the output value of the first-order low-pass filter
Definition: filter.c:56
volatile Filter_Structure_t velocity_filter
motor rotation speed low pass filter handle
Definition: filter.c:19
void filter_config(void)
configure low-pass filter parameters
Definition: filter.c:45
this is the header file of filter.c, which defines the structure of filter algorithm.
this is the header file of foc.c, which defines the structure of FOC algorithm and angle conversion f...
#define SPEED_COEFFICIENT
mechanical rotate speed conversion factor
Definition: foc.h:28
structure of low-pass filter algorithm
Definition: filter.h:16
float coefficient2
low-pass filter coefficient 2
Definition: filter.h:18
float last_result
previous calculation results of low-pass filter
Definition: filter.h:19
float current_result
current calculation results of low-pass filter
Definition: filter.h:20
float coefficient1
low-pass filter coefficient 1
Definition: filter.h:17
void user_memset(void *buf, unsigned char data, unsigned char num)
format buffer array to fixed value, replace memset function
Definition: system.c:49
system basic function header file