Skip to content

Commit a1eb13a

Browse files
committed
fix pa2 input f051, fix rc car mode
1 parent 42c02f5 commit a1eb13a

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

Mcu/f051/Src/IO.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void receiveDshotDma()
2727
#endif
2828
#ifdef USE_TIMER_15_CHANNEL_1
2929
RCC->APB2RSTR |= LL_APB1_GRP2_PERIPH_TIM15;
30-
RCC->APB2RSTR &= LL_APB1_GRP2_PERIPH_TIM15;
30+
RCC->APB2RSTR &= ~LL_APB1_GRP2_PERIPH_TIM15;
3131
#endif
3232
IC_TIMER_REGISTER->CCMR1 = 0x6001;
3333
IC_TIMER_REGISTER->CCER = 0xa;
@@ -63,7 +63,7 @@ void sendDshotDma()
6363
#endif
6464
#ifdef USE_TIMER_15_CHANNEL_1
6565
RCC->APB2RSTR |= LL_APB1_GRP2_PERIPH_TIM15;
66-
RCC->APB2RSTR &= LL_APB1_GRP2_PERIPH_TIM15;
66+
RCC->APB2RSTR &= ~LL_APB1_GRP2_PERIPH_TIM15;
6767
#endif
6868
IC_TIMER_REGISTER->CCMR1 = 0x60;
6969
IC_TIMER_REGISTER->CCER = 0x3;

Mcu/f051/Src/peripherals.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void UN_TIM_Init(void)
381381
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
382382
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
383383
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
384-
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
384+
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
385385
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
386386
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
387387
#endif
@@ -425,8 +425,8 @@ void UN_TIM_Init(void)
425425
/* TIM16 interrupt Init */
426426

427427
#ifdef USE_TIMER_15_CHANNEL_1
428-
NVIC_SetPriority(TIM15_IRQn, 0);
429-
NVIC_EnableIRQ(TIM15_IRQn);
428+
NVIC_SetPriority(IC_DMA_IRQ_NAME, 1);
429+
NVIC_EnableIRQ(IC_DMA_IRQ_NAME);
430430
#endif
431431
#ifdef USE_TIMER_3_CHANNEL_1
432432
NVIC_SetPriority(IC_DMA_IRQ_NAME, 1);

Src/main.c

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ char RC_CAR_REVERSE = 0; // have to set bidirectional, comp_pwm off and stall pr
335335
uint16_t ADC_CCR = 30;
336336
uint16_t current_angle = 90;
337337
uint16_t desired_angle = 90;
338-
338+
char return_to_center = 0;
339339
uint16_t target_e_com_time = 0;
340340
int16_t Speed_pid_output;
341341
char use_speed_control_loop = 0;
@@ -1002,32 +1002,40 @@ void setInput()
10021002
if (newinput > (1000 + (servo_dead_band << 1))) {
10031003
if (forward == dir_reversed) {
10041004
adjusted_input = 0;
1005-
if (running) {
1005+
// if (running) {
10061006
prop_brake_active = 1;
1007-
} else {
1008-
forward = 1 - dir_reversed;
1009-
}
1007+
if(return_to_center){
1008+
forward = 1 - dir_reversed;
1009+
prop_brake_active = 0;
1010+
return_to_center = 0;
1011+
}
10101012
}
10111013
if (prop_brake_active == 0) {
1014+
return_to_center = 0;
10121015
adjusted_input = map(newinput, 1000 + (servo_dead_band << 1), 2000, 47, 2047);
10131016
}
10141017
}
10151018
if (newinput < (1000 - (servo_dead_band << 1))) {
1016-
if (forward == (1 - dir_reversed)) {
1017-
if (running) {
1019+
if (forward == (1 - dir_reversed)) {
1020+
adjusted_input = 0;
10181021
prop_brake_active = 1;
1019-
} else {
1020-
forward = dir_reversed;
1021-
}
1022-
adjusted_input = 0;
1022+
if(return_to_center){
1023+
forward = dir_reversed;
1024+
prop_brake_active = 0;
1025+
return_to_center = 0;
1026+
}
10231027
}
10241028
if (prop_brake_active == 0) {
1029+
return_to_center = 0;
10251030
adjusted_input = map(newinput, 0, 1000 - (servo_dead_band << 1), 2047, 47);
10261031
}
10271032
}
10281033
if (newinput >= (1000 - (servo_dead_band << 1)) && newinput <= (1000 + (servo_dead_band << 1))) {
10291034
adjusted_input = 0;
1030-
prop_brake_active = 0;
1035+
if (prop_brake_active) {
1036+
prop_brake_active = 0;
1037+
return_to_center = 1;
1038+
}
10311039
}
10321040
} else {
10331041
if (newinput > (1000 + (servo_dead_band << 1))) {
@@ -1210,7 +1218,7 @@ void setInput()
12101218
}
12111219

12121220
if (!comp_pwm) {
1213-
duty_cycle = 0;
1221+
duty_cycle_setpoint = 0;
12141222
if (!running) {
12151223
old_routine = 1;
12161224
zero_crosses = 0;
@@ -1224,8 +1232,8 @@ void setInput()
12241232
}
12251233
if (RC_CAR_REVERSE && prop_brake_active) {
12261234
#ifndef PWM_ENABLE_BRIDGE
1227-
duty_cycle = getAbsDif(1000, newinput) + 1000;
1228-
if (duty_cycle == 2000) {
1235+
duty_cycle_setpoint = getAbsDif(1000, newinput) + 1000;
1236+
if (duty_cycle_setpoint >= 1999) {
12291237
fullBrake();
12301238
} else {
12311239
proportionalBrake();
@@ -1457,7 +1465,7 @@ void tenKhzRoutine()
14571465
} else {
14581466

14591467
if (prop_brake_active) {
1460-
adjusted_duty_cycle = TIMER1_MAX_ARR - ((duty_cycle * tim1_arr)/TIMER1_MAX_ARR);
1468+
adjusted_duty_cycle = TIMER1_MAX_ARR - duty_cycle;
14611469
} else {
14621470
adjusted_duty_cycle = ((duty_cycle * tim1_arr) / TIMER1_MAX_ARR);
14631471
}
@@ -1551,6 +1559,9 @@ void zcfoundroutine()
15511559
}
15521560
#ifdef MCU_GDE23
15531561
TIMER_CAR(COM_TIMER) = waitTime;
1562+
#endif
1563+
#ifdef MCU_F051
1564+
COM_TIMER->ARR = waitTime;
15541565
#endif
15551566
commutate();
15561567
bemfcounter = 0;

0 commit comments

Comments
 (0)