Update control.c
- removed the `PWM_signal_Correct(..)` function, because it is already existing here 34c6e4d610/Src/util.c (L844-L862)
- added (void) to the functions
- limited `pwm_timeout` to 500 instead of 0, ottherwise the timeout won't work properly, because it will will reset every time.
This commit is contained in:
parent
21a8f757d0
commit
b95307f260
|
@ -90,19 +90,7 @@ uint16_t pwm_captured_ch1_value = 500;
|
||||||
uint16_t pwm_captured_ch2_value = 500;
|
uint16_t pwm_captured_ch2_value = 500;
|
||||||
uint32_t pwm_timeout = 0;
|
uint32_t pwm_timeout = 0;
|
||||||
|
|
||||||
int PWM_Signal_Correct(int x, int max, int min) {
|
void PWM_ISR_CH1_Callback(void) {
|
||||||
int outVal = 0;
|
|
||||||
if(x > -PWM_DEADBAND && x < PWM_DEADBAND) {
|
|
||||||
outVal = 0;
|
|
||||||
} else if(x > 0) {
|
|
||||||
outVal = (float)CLAMP(x-PWM_DEADBAND, 0, max - PWM_DEADBAND) / (max - PWM_DEADBAND) * 1000;
|
|
||||||
} else {
|
|
||||||
outVal = 0 - ((float)CLAMP(x+PWM_DEADBAND, min + PWM_DEADBAND, 0) / (min + PWM_DEADBAND) * 1000);
|
|
||||||
}
|
|
||||||
return outVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PWM_ISR_CH1_Callback() {
|
|
||||||
// Dummy loop with 16 bit count wrap around
|
// Dummy loop with 16 bit count wrap around
|
||||||
uint16_t rc_signal = TIM2->CNT;
|
uint16_t rc_signal = TIM2->CNT;
|
||||||
TIM2->CNT = 0;
|
TIM2->CNT = 0;
|
||||||
|
@ -114,7 +102,7 @@ void PWM_ISR_CH1_Callback() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PWM_ISR_CH2_Callback() {
|
void PWM_ISR_CH2_Callback(void) {
|
||||||
// Dummy loop with 16 bit count wrap around
|
// Dummy loop with 16 bit count wrap around
|
||||||
uint16_t rc_signal = TIM2->CNT;
|
uint16_t rc_signal = TIM2->CNT;
|
||||||
TIM2->CNT = 0;
|
TIM2->CNT = 0;
|
||||||
|
@ -127,17 +115,17 @@ void PWM_ISR_CH2_Callback() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SysTick executes once each ms
|
// SysTick executes once each ms
|
||||||
void PWM_SysTick_Callback() {
|
void PWM_SysTick_Callback(void) {
|
||||||
pwm_timeout++;
|
pwm_timeout++;
|
||||||
// Stop after 500 ms without PPM signal
|
// Stop after 500 ms without PPM signal
|
||||||
if(pwm_timeout > 500) {
|
if(pwm_timeout > 500) {
|
||||||
//pwm_captured_ch1_value = 500;
|
//pwm_captured_ch1_value = 500;
|
||||||
pwm_captured_ch2_value = 500;
|
pwm_captured_ch2_value = 500;
|
||||||
pwm_timeout = 0;
|
pwm_timeout = 500;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PWM_Init() {
|
void PWM_Init(void) {
|
||||||
// PWM Timer (TIM2)
|
// PWM Timer (TIM2)
|
||||||
__HAL_RCC_TIM2_CLK_ENABLE();
|
__HAL_RCC_TIM2_CLK_ENABLE();
|
||||||
TimHandle.Instance = TIM2;
|
TimHandle.Instance = TIM2;
|
||||||
|
|
Loading…
Reference in New Issue