| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #include "foc/samples.h"
- #include "bsp/bsp.h"
- #include "bsp/adc.h"
- #include "math/fast_math.h"
- #include "math/fix_math.h"
- #include "os/os_task.h"
- #include "foc/foc_config.h"
- #include "bsp/delay.h"
- typedef struct {
- float value;
- float filted_value;
- float lowpass;
- }samples_t;
- static void sample_vbus(void);
- static void sample_throttle(void);
- static void sample_uvw_phase(void);
- static u32 sample_task(void *);
- static samples_t _vbus;
- #ifdef THROTTLE_CHAN
- static samples_t _throttle;
- #endif
- #ifdef U_VOL_ADC_CHAN
- static samples_t _uvw_phase[3];
- #endif
- void samples_init(void){
- _vbus.filted_value = (MAX_vDC);
- _vbus.value = (MAX_vDC);
- _vbus.lowpass = (0.001f);
- sample_vbus();
- #ifdef THROTTLE_CHAN
- _throttle.filted_value = (0);
- _throttle.value = (0);
- _throttle.lowpass = (0.01f);
- sample_throttle();
- #endif
- #ifdef U_VOL_ADC_CHAN
- _uvw_phase[0].value = _uvw_phase[0].filted_value = 0;
- _uvw_phase[0].lowpass = 0.01f;
- _uvw_phase[1].value = _uvw_phase[1].filted_value = 0;
- _uvw_phase[1].lowpass = 0.01f;
- _uvw_phase[2].value = _uvw_phase[2].filted_value = 0;
- _uvw_phase[2].lowpass = 0.01f;
- sample_uvw_phase();
- #endif
- shark_task_create(sample_task, NULL);
- }
- void get_phase_vols(float *uvw) {
- uvw[0] = _uvw_phase[0].filted_value;
- uvw[1] = _uvw_phase[1].filted_value;
- uvw[2] = _uvw_phase[2].filted_value;
- }
- float get_vbus_float(void) {
- return (_vbus.filted_value);
- }
- s16 get_vbus_sfix5(void){
- return _vbus.filted_value;
- }
- float get_throttle_float(void) {
- #ifdef THROTTLE_CHAN
- return _throttle.filted_value;
- #else
- return 0.0f;
- #endif
- }
- static u32 sample_task(void *param) {
- sample_vbus();
- sample_throttle();
- sample_uvw_phase();
- return 0;
- }
- u32 sapmple_delta;
- static void sample_vbus(void){
- u32 ticks = task_ticks_abs();
- s16 vadc = adc_get_vbus();
- _vbus.value = (float)vadc * VBUS_VOL_CEOF;
- LowPass_Filter(_vbus.filted_value, _vbus.value, _vbus.lowpass);
- sapmple_delta = task_ticks_rel(ticks);
- }
- static void sample_throttle(void){
- #ifdef THROTTLE_CHAN
- s16 vadc = adc_get_throttle();
- _throttle.value = (float)vadc * THROTTLE_VOL_CEOF;
- LowPass_Filter(_throttle.filted_value, _throttle.value, _throttle.lowpass);
- #endif
- }
- static void sample_uvw_phase(void) {
- #ifdef U_VOL_ADC_CHAN
- u16 uvw[3];
- adc_get_uvw_phaseV(uvw);
- _uvw_phase[0].value = (float)uvw[0] * UVW_VOL_CEOF;
- LowPass_Filter(_uvw_phase[0].filted_value, _uvw_phase[0].value, _uvw_phase[0].lowpass);
- _uvw_phase[1].value = (float)uvw[1] * UVW_VOL_CEOF;
- LowPass_Filter(_uvw_phase[1].filted_value, _uvw_phase[1].value, _uvw_phase[1].lowpass);
- _uvw_phase[2].value = (float)uvw[2] * UVW_VOL_CEOF;
- LowPass_Filter(_uvw_phase[2].filted_value, _uvw_phase[2].value, _uvw_phase[2].lowpass);
- #endif
- }
|