|
|
|
@ -123,25 +123,14 @@ uint32_t pwm_timeout = 0;
|
|
|
|
|
|
|
|
|
|
|
|
#define IN_RANGE(x, low, up) (((x) >= (low)) && ((x) <= (up)))
|
|
|
|
#define IN_RANGE(x, low, up) (((x) >= (low)) && ((x) <= (up)))
|
|
|
|
|
|
|
|
|
|
|
|
int PWM_Signal_Correct(int16_t x, int16_t max, int16_t min) {
|
|
|
|
|
|
|
|
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(void) {
|
|
|
|
void PWM_ISR_CH1_Callback(void) {
|
|
|
|
// Dummy loop with 16 bit count wrap around
|
|
|
|
// Dummy loop with 16 bit count wrap around
|
|
|
|
uint16_t rc_signal = TIM3->CNT;
|
|
|
|
uint16_t rc_signal = TIM3->CNT;
|
|
|
|
TIM3->CNT = 0;
|
|
|
|
TIM3->CNT = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (IN_RANGE(rc_signal, 900, 2100)){
|
|
|
|
// The interval check below should be larger than the feasible PWM interval of ~[500, 2500] ms
|
|
|
|
|
|
|
|
if (IN_RANGE(rc_signal, 200, 4000)){
|
|
|
|
timeout = 0;
|
|
|
|
timeout = 0;
|
|
|
|
pwm_timeout = 0;
|
|
|
|
pwm_timeout = 0;
|
|
|
|
pwm_captured_ch1_value = CLAMP(rc_signal, 1000, 2000) - 1000;
|
|
|
|
pwm_captured_ch1_value = CLAMP(rc_signal, 1000, 2000) - 1000;
|
|
|
|
@ -154,7 +143,8 @@ void PWM_ISR_CH2_Callback(void) {
|
|
|
|
uint16_t rc_signal = TIM2->CNT;
|
|
|
|
uint16_t rc_signal = TIM2->CNT;
|
|
|
|
TIM2->CNT = 0;
|
|
|
|
TIM2->CNT = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (IN_RANGE(rc_signal, 900, 2100)){
|
|
|
|
// The interval check below should be larger than the feasible PWM interval of ~[900, 2100] ms
|
|
|
|
|
|
|
|
if (IN_RANGE(rc_signal, 200, 3000)){
|
|
|
|
timeout = 0;
|
|
|
|
timeout = 0;
|
|
|
|
pwm_timeout = 0;
|
|
|
|
pwm_timeout = 0;
|
|
|
|
pwm_captured_ch2_value = CLAMP(rc_signal, 1000, 2000) - 1000;
|
|
|
|
pwm_captured_ch2_value = CLAMP(rc_signal, 1000, 2000) - 1000;
|
|
|
|
@ -164,11 +154,11 @@ void PWM_ISR_CH2_Callback(void) {
|
|
|
|
// SysTick executes once each ms
|
|
|
|
// SysTick executes once each ms
|
|
|
|
void PWM_SysTick_Callback(void) {
|
|
|
|
void PWM_SysTick_Callback(void) {
|
|
|
|
pwm_timeout++;
|
|
|
|
pwm_timeout++;
|
|
|
|
// Stop after 500 ms without PPM signal
|
|
|
|
// Stop after 500 ms without PWM 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; // limit the timeout to max timeout value of 500 ms
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|