mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
OP-924: Ensures that the PPM pulse turns off between PPM frames.
This commit is contained in:
parent
e642183dee
commit
39c6e81d07
@ -2072,9 +2072,9 @@ static void rfm22_sendPPM(struct pios_rfm22b_dev *rfm22b_dev)
|
||||
|
||||
// See if we have any valid channels.
|
||||
bool valid_input_detected = false;
|
||||
for (uint8_t i = 1; i <= PIOS_PPM_NUM_INPUTS; ++i) {
|
||||
rfm22b_dev->ppm_packet.channels[i - 1] = PIOS_RCVR_Read(PIOS_PPM_RECEIVER, i);
|
||||
if((rfm22b_dev->ppm_packet.channels[i - 1] != PIOS_RCVR_INVALID) && (rfm22b_dev->ppm_packet.channels[i - 1] != PIOS_RCVR_TIMEOUT))
|
||||
for (uint8_t i = 0; i < PIOS_PPM_NUM_INPUTS; ++i) {
|
||||
rfm22b_dev->ppm_packet.channels[i] = PIOS_RCVR_Read(PIOS_PPM_RECEIVER, i + 1);
|
||||
if((rfm22b_dev->ppm_packet.channels[i] != PIOS_RCVR_INVALID) && (rfm22b_dev->ppm_packet.channels[i] != PIOS_RCVR_TIMEOUT))
|
||||
valid_input_detected = true;
|
||||
}
|
||||
|
||||
|
@ -49,14 +49,15 @@ struct pios_ppm_out_dev {
|
||||
enum pios_ppm_out_dev_magic magic;
|
||||
const struct pios_ppm_out_cfg * cfg;
|
||||
|
||||
uint32_t triggering_period;
|
||||
uint32_t TriggeringPeriod;
|
||||
uint32_t ChannelSum;
|
||||
uint8_t NumChannelCounter;
|
||||
uint16_t ChannelValue[PIOS_PPM_OUT_MAX_CHANNELS];
|
||||
|
||||
uint8_t supv_timer;
|
||||
bool Tracking;
|
||||
uint8_t SupvTimer;
|
||||
bool Fresh;
|
||||
bool Tracking;
|
||||
bool Enabled;
|
||||
};
|
||||
|
||||
static void PIOS_PPM_Out_Supervisor(uint32_t ppm_id);
|
||||
@ -118,12 +119,12 @@ int32_t PIOS_PPM_Out_Init(uint32_t *ppm_out_id, const struct pios_ppm_out_cfg *
|
||||
ppm_dev->cfg = cfg;
|
||||
|
||||
// Set up the state variables
|
||||
ppm_dev->triggering_period = PIOS_PPM_OUT_HIGH_PULSE_US;
|
||||
ppm_dev->TriggeringPeriod = PIOS_PPM_OUT_HIGH_PULSE_US;
|
||||
ppm_dev->ChannelSum = 0;
|
||||
ppm_dev->NumChannelCounter = 0;
|
||||
|
||||
// Flush counter variables
|
||||
for (uint8_t i = 0; i < PIOS_PPM_OUT_MAX_CHANNELS; i++)
|
||||
for (uint8_t i = 0; i < PIOS_PPM_OUT_MAX_CHANNELS; ++i)
|
||||
ppm_dev->ChannelValue[i] = 1000;
|
||||
|
||||
uint32_t tim_id;
|
||||
@ -166,9 +167,10 @@ int32_t PIOS_PPM_Out_Init(uint32_t *ppm_out_id, const struct pios_ppm_out_cfg *
|
||||
PIOS_PPM_Out_Enable_Disable(ppm_dev, false);
|
||||
|
||||
// Configure the supervisor
|
||||
ppm_dev->supv_timer = 0;
|
||||
ppm_dev->SupvTimer = 0;
|
||||
ppm_dev->Fresh = FALSE;
|
||||
ppm_dev->Tracking = FALSE;
|
||||
ppm_dev->Enabled = FALSE;
|
||||
if (!PIOS_RTC_RegisterTickCallback(PIOS_PPM_Out_Supervisor, (uint32_t)ppm_dev)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
@ -193,8 +195,8 @@ void PIOS_PPM_OUT_Set(uint32_t ppm_out_id, uint8_t servo, uint16_t position)
|
||||
|
||||
// Reenable the TIM if it's been turned off.
|
||||
if (!ppm_dev->Tracking) {
|
||||
PIOS_PPM_Out_Enable_Disable(ppm_dev, true);
|
||||
ppm_dev->Tracking = TRUE;
|
||||
PIOS_PPM_Out_Enable_Disable(ppm_dev, true);
|
||||
}
|
||||
|
||||
// Update the position
|
||||
@ -207,21 +209,29 @@ static void PIOS_PPM_OUT_tim_edge_cb (uint32_t tim_id, uint32_t context, uint8_t
|
||||
if (!PIOS_PPM_Out_validate(ppm_dev))
|
||||
return;
|
||||
|
||||
// Just return if the device is disabled.
|
||||
if (!ppm_dev->Enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Turn off the PPM stream if we are no longer receiving update
|
||||
// Note: This must happen between frames.
|
||||
if ((ppm_dev->NumChannelCounter == 0) && !ppm_dev->Tracking) {
|
||||
// Flush counter variables
|
||||
for (uint8_t i = 0; i < PIOS_PPM_OUT_MAX_CHANNELS; ++i) {
|
||||
ppm_dev->ChannelValue[i] = 1000;
|
||||
}
|
||||
PIOS_PPM_Out_Enable_Disable(ppm_dev, false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Finish out the frame if we reached the last channel.
|
||||
uint32_t pulse_width;
|
||||
if ((ppm_dev->NumChannelCounter >= PIOS_PPM_OUT_MAX_CHANNELS)) {
|
||||
pulse_width = PIOS_PPM_OUT_FRAME_PERIOD_US - ppm_dev->ChannelSum;
|
||||
ppm_dev->NumChannelCounter = 0;
|
||||
ppm_dev->ChannelSum = 0;
|
||||
|
||||
// Have we not received a sample for the supervisor timeout.
|
||||
if (!ppm_dev->Tracking) {
|
||||
// Flush counter variables
|
||||
for (uint8_t i = 0; i < PIOS_PPM_OUT_MAX_CHANNELS; i++)
|
||||
ppm_dev->ChannelValue[i] = 1000;
|
||||
PIOS_PPM_Out_Enable_Disable(ppm_dev, false);
|
||||
}
|
||||
} else
|
||||
} else
|
||||
ppm_dev->ChannelSum += (pulse_width = ppm_dev->ChannelValue[ppm_dev->NumChannelCounter++]);
|
||||
|
||||
// Initiate the pulse
|
||||
@ -233,8 +243,9 @@ static void PIOS_PPM_OUT_tim_edge_cb (uint32_t tim_id, uint32_t context, uint8_t
|
||||
static void PIOS_PPM_Out_Enable_Disable(struct pios_ppm_out_dev *ppm_dev, bool enable)
|
||||
{
|
||||
const struct pios_tim_channel *chan = ppm_dev->cfg->channel;
|
||||
uint32_t trig = enable ? ppm_dev->triggering_period : 0;
|
||||
uint32_t trig = enable ? ppm_dev->TriggeringPeriod : 0;
|
||||
FunctionalState state = enable ? ENABLE : DISABLE;
|
||||
ppm_dev->Enabled = enable;
|
||||
switch (chan->timer_chan) {
|
||||
case TIM_Channel_1:
|
||||
TIM_ITConfig(chan->timer, TIM_IT_CC1 | TIM_IT_Update, state);
|
||||
@ -260,18 +271,18 @@ static void PIOS_PPM_Out_Supervisor(uint32_t ppm_out_id) {
|
||||
if (!PIOS_PPM_Out_validate(ppm_dev))
|
||||
return;
|
||||
|
||||
/*
|
||||
* RTC runs at 625Hz so divide down the base rate so that this loop runs at 25Hz.
|
||||
*/
|
||||
if(++(ppm_dev->supv_timer) < 25) {
|
||||
// RTC runs at 625Hz so divide down the base rate so that this loop runs at 12.5Hz.
|
||||
if(++(ppm_dev->SupvTimer) < 50) {
|
||||
return;
|
||||
}
|
||||
ppm_dev->supv_timer = 0;
|
||||
ppm_dev->SupvTimer = 0;
|
||||
|
||||
// Go into failsafe the channel values haven't been refreshed since the last time through.
|
||||
if (!ppm_dev->Fresh) {
|
||||
ppm_dev->Tracking = FALSE;
|
||||
}
|
||||
|
||||
// Set Fresh to false to test if channel values are being refreshed.
|
||||
ppm_dev->Fresh = FALSE;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user