void SCT_irq_handler(void) could not invoke output_raw_channels()
Closed this issue · 2 comments
Please check void SCT_irq_handler(void) in rc-light-controller-master\mk4-tlc5940-lpc812\firmware\servo_reader.c
if (channel_flags & (1 << i)) {
output_raw_channels(result);
channel_flags = (1 << i);
}
channel_flags |= (1 << i);
whatever channel_flags and i change, output_raw_channels() is impossible to run. I picked up related code and verified in VS2015. Obviously, output_raw_channels(result) has no chance to run.
Locke
Hi,
if (channel_flags & (1 << i)) {
output_raw_channels(result);
channel_flags = (1 << i);
}
channel_flags |= (1 << i);
The important part of this code is that channel_flags is declared static,
i.e. it persists between interrupts.
The code checks if a particular servo channel has been seen a second time,
and if it has it calls output_raw_channels().
This code allows automatic detection of how many servo channels are
connected to the light controller, and it also ensures that the order in
which servo pulses are sent by the receiver does not matter.
Example:
- At startup channel_flags is 0. result[ST, TH, CH3] are all set to 0 to
indicate "no servo pulse". - Only two servo channels are connected to the light controller; Steering
(ST, setup for timer capture CTIN_1) and Throttle (TH, setup for timer
capture CTIN_2). CH3/AUX (setup for timer capture CTIN_3) is not connected. - The receiver outputs TH first, then followed by ST (most transmitters
output ST first, but some like FrSky GT3B output TH first) - The interrupt triggers Timer Capture CTIN_2 at the rising edge of TH.
start[TH] is set with the timer value. channel_flags is 0, so
output_raw_channels is not called. channel_flag bit TH is set at the end
of the function. - The interrupt triggers Timer Capture CTIN_2 at the falling edge of TH.
The pulse duration for TH is calculated and saved in result[TH] - The interrupt triggers Timer Capture CTIN_1 at the rising edge of ST.
start[ST] is set with the timer value. channel_flags has only the TH bit
set, but not the ST bit, so output_raw_channels is not called.
channel_flag bit ST is set at the end of the function. - The interrupt triggers Timer Capture CTIN_1 at the falling edge of ST.
The pulse duration for ST is calculated and saved in result[ST] - [around 4..20 ms go by until the receiver repeats the servo channels]
- The interrupt triggers Timer Capture CTIN_2 at the rising edge of TH.
start[TH] is set with the timer value. channel_flags has the TH bit now set
from the pulse pulse before, which makes the if statement you quoted
true, therefore output_raw_channel is being called, with result[ST] and
result[TH] holding the measured pulse durations, and result[CH3] being 0
because this channel is not connected so it was not measured. After
output_raw_channel returns the TH bit in channel_flags is set because we
are just processing a new rising edge for TH, all other bits are cleared.
kind regards, Werner
On Mon, Jan 11, 2016 at 11:07 PM, Locke Huang notifications@github.com
wrote:
Please check void SCT_irq_handler(void) in
rc-light-controller-master\mk4-tlc5940-lpc812\firmware\servo_readercif (channel_flags & (1 << i)) { output_raw_channels(result); channel_flags = (1 << i); } channel_flags |= (1 << i);
whatever channel_flags and i change, output_raw_channels() is impossible
to run I picked up related code and verified in VS2015 Obviously,
output_raw_channels(result) has no chance to runLocke
—
Reply to this email directly or view it on GitHub
#2.
Hello, Werner:
Thanks for the so detailed explanation. You are exact right. output_raw_channels(result); will be invoked in THE SECOND rising edge of TH. I verified this with my VS. It is well designed and very intelligent.
I should noticed the PWM for receiver is contentious. Thanks for the clarify. And this is an awesome project. Please kindly close this "issue".
BR
Locke