Skip to content

Commit f76edbf

Browse files
committed
Fixed ADC output jumping problem
1 parent 2cb6af7 commit f76edbf

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

radio/src/boards/generic_stm32/analog_inputs.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ static bool adc_start_read()
7070
if (n_ADC_spi > 0) {
7171
success = success && ads79xx_adc_start_read(&_ADC_spi[0], _ADC_inputs);
7272
}
73-
#endif
74-
#if defined(FLYSKY_GIMBAL)
75-
flysky_gimbal_start_read();
7673
#endif
7774
return success;
7875
}
@@ -85,9 +82,6 @@ static void adc_wait_completion()
8582
if (n_ADC_spi > 0) ads79xx_adc_wait_completion(&_ADC_spi[0], _ADC_inputs);
8683
#endif
8784
stm32_hal_adc_wait_completion(_ADC_adc, n_ADC, _ADC_inputs, n_inputs);
88-
#if defined(FLYSKY_GIMBAL)
89-
flysky_gimbal_wait_completion();
90-
#endif
9185
}
9286

9387
const etx_hal_adc_driver_t _adc_driver = {

radio/src/targets/common/arm/stm32/flysky_gimbal_driver.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ static uint8_t _fs_gimbal_version = GIMBAL_V1;
7272
static uint8_t _fs_gimbal_mode = V1_MODE;
7373
static uint8_t _fs_gimbal_mode_cmd = V1_MODE;
7474
static bool _fs_gimbal_read_finished = true;
75+
static uint32_t _fs_lastReadTick = 0;
76+
static uint32_t _fs_readTick;
77+
static uint32_t _fs_sync_period = 0;
7578

7679
static int _fs_get_byte(uint8_t* data)
7780
{
@@ -210,7 +213,7 @@ static void flysky_gimbal_loop(void*)
210213
if (majorVersion == 2 && minorVersion >= 1) {
211214
_fs_gimbal_version = GIMBAL_V2;
212215
// Enable sync mode
213-
_fs_cmd_set_mode(SYNC_1000Hz);
216+
_fs_cmd_set_mode(SYNC_RESAMPLING);
214217
}
215218
} else if (HallProtocol.hallID.hall_Id.packetID == FLYSKY_PACKET_MODE_ID) {
216219
_fs_gimbal_mode = _fs_gimbal_mode_cmd;
@@ -265,6 +268,11 @@ void flysky_gimbal_start_read()
265268
if(_fs_sync_enabled()) {
266269
if (_fs_gimbal_read_finished) {
267270
_fs_gimbal_read_finished = false;
271+
_fs_lastReadTick = _fs_readTick;
272+
_fs_readTick = timersGetUsTick();
273+
if (_fs_lastReadTick != 0) {
274+
_fs_sync_period = _fs_readTick - _fs_lastReadTick;
275+
}
268276
_fs_cmd_start_read();
269277
}
270278
}

radio/src/targets/common/arm/stm32/flysky_gimbal_driver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ enum GIMBAL_VERSION {
133133

134134
enum V2_GIMBAL_MODE {
135135
V1_MODE = 0,
136-
SYNC_400Hz = 1,
137-
SYNC_1000Hz = 2
136+
SYNC_SAMPLING = 1, // Can serve sampling frequency < 400Hz
137+
SYNC_RESAMPLING = 2 // Can serve sampling frequency up to 1000Hz
138138
};
139139

140140
extern signed short hall_raw_values[FLYSKY_HALL_CHANNEL_COUNT];

radio/src/tasks/mixer_task.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#include "hal/gpio.h"
3434
#endif
3535

36+
#if defined(FLYSKY_GIMBAL)
37+
#include "flysky_gimbal_driver.h"
38+
#endif
39+
3640
RTOS_TASK_HANDLE mixerTaskId;
3741
RTOS_DEFINE_STACK(mixerTaskId, mixerStack, MIXER_STACK_SIZE);
3842

@@ -250,6 +254,14 @@ void doMixerCalculations()
250254
getADC();
251255
DEBUG_TIMER_STOP(debugTimerGetAdc);
252256

257+
// Need to put all in a group to ensure DMA transfer will not affect ADC sampling
258+
#if defined(FLYSKY_GIMBAL)
259+
flysky_gimbal_start_read();
260+
#endif
261+
#if defined(FLYSKY_GIMBAL)
262+
flysky_gimbal_wait_completion();
263+
#endif
264+
253265
DEBUG_TIMER_START(debugTimerGetSwitches);
254266
getSwitchesPosition(!s_mixer_first_run_done);
255267
DEBUG_TIMER_STOP(debugTimerGetSwitches);

0 commit comments

Comments
 (0)