mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 15:25:36 +03:00
Improvement to the way that timers are forced to overflow, which should allow PPM on CC3D to work properly.
This commit is contained in:
parent
c0ed21a818
commit
5096873ab1
2 changed files with 13 additions and 14 deletions
|
@ -37,7 +37,7 @@ typedef void (*pwmWriteFuncPtr)(uint8_t index, uint16_t value); // function poi
|
|||
|
||||
typedef struct {
|
||||
volatile timCCR_t *ccr;
|
||||
volatile timCNT_t *cnt;
|
||||
volatile TIM_TypeDef *tim;
|
||||
uint16_t period;
|
||||
pwmWriteFuncPtr pwmWritePtr;
|
||||
} pwmOutputPort_t;
|
||||
|
@ -46,7 +46,6 @@ static pwmOutputPort_t pwmOutputPorts[MAX_PWM_OUTPUT_PORTS];
|
|||
|
||||
static pwmOutputPort_t *motors[MAX_PWM_MOTORS];
|
||||
static pwmOutputPort_t *servos[MAX_PWM_SERVOS];
|
||||
static volatile uint16_t* lastCounterPtr;
|
||||
|
||||
#define PWM_BRUSHED_TIMER_MHZ 8
|
||||
|
||||
|
@ -120,7 +119,7 @@ static pwmOutputPort_t *pwmOutConfig(const timerHardware_t *timerHardware, uint8
|
|||
break;
|
||||
}
|
||||
p->period = period;
|
||||
p->cnt = &timerHardware->tim->CNT;
|
||||
p->tim = timerHardware->tim;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
@ -144,22 +143,22 @@ void pwmWriteMotor(uint8_t index, uint16_t value)
|
|||
void pwmFinishedWritingMotors(uint8_t numberMotors)
|
||||
{
|
||||
uint8_t index;
|
||||
volatile TIM_TypeDef *lastTimerPtr = NULL;
|
||||
|
||||
|
||||
if(feature(FEATURE_ONESHOT125)){
|
||||
|
||||
for(index = 0; index < numberMotors; index++){
|
||||
// Force the counter to overflow if it's the first motor to output, or if we change timers
|
||||
if((index == 0) || (motors[index]->cnt != lastCounterPtr)){
|
||||
lastCounterPtr = motors[index]->cnt;
|
||||
|
||||
*motors[index]->cnt = 0xfffe;
|
||||
// Force the timer to overflow if it's the first motor to output, or if we change timers
|
||||
if(motors[index]->tim != lastTimerPtr){
|
||||
lastTimerPtr = motors[index]->tim;
|
||||
|
||||
// Force an overflow by setting the UG bit
|
||||
motors[index]->tim->EGR |= 0x0001;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait until the timers have overflowed (should take less than 0.125 uS)
|
||||
while(*motors[numberMotors - 1]->cnt >= 0xfffe){
|
||||
}
|
||||
|
||||
// Set the compare register to 0, which stops the output pulsing if the timer overflows before the main loop completes again.
|
||||
// This compare register will be set to the output value on the next main loop.
|
||||
for(index = 0; index < numberMotors; index++){
|
||||
|
|
|
@ -82,7 +82,7 @@ static uint16_t captures[PWM_PORTS_OR_PPM_CAPTURE_COUNT];
|
|||
|
||||
static uint8_t ppmFrameCount = 0;
|
||||
static uint8_t lastPPMFrameCount = 0;
|
||||
static uint8_t ppmCountDivisor = 1;
|
||||
static uint8_t ppmCountShift = 0;
|
||||
|
||||
typedef struct ppmDevice {
|
||||
uint8_t pulseIndex;
|
||||
|
@ -161,7 +161,7 @@ static void ppmEdgeCallback(timerCCHandlerRec_t* cbRec, captureCompare_t capture
|
|||
ppmDev.currentTime += ppmDev.largeCounter;
|
||||
|
||||
// Divide by 8 if Oneshot125 is active and this is a CC3D board
|
||||
ppmDev.currentTime = ppmDev.currentTime / ppmCountDivisor;
|
||||
ppmDev.currentTime = ppmDev.currentTime >> ppmCountShift;
|
||||
|
||||
/* Capture computation */
|
||||
ppmDev.deltaTime = ppmDev.currentTime - ppmDev.previousTime;
|
||||
|
@ -332,7 +332,7 @@ void ppmInConfig(const timerHardware_t *timerHardwarePtr)
|
|||
timerConfigure(timerHardwarePtr, (uint16_t)PPM_TIMER_PERIOD, PWM_TIMER_MHZ);
|
||||
|
||||
if((timerHardwarePtr->tim == TIM4) && (feature(FEATURE_ONESHOT125))){
|
||||
ppmCountDivisor = 8;
|
||||
ppmCountShift = 3; // Divide by 8 if the timer is running at 8 MHz
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue