AM32 电调学习–输入获取分析
#define INTERVAL_TIMER TIM2 ; 过零时间测量
psc=31
#define TEN_KHZ_TIMER TIM6 ;tenKhzRoutine frq=1M load=1M/20k
psc=63
#define UTILITY_TIMER TIM17
#define COM_TIMER TIM14 //PeriodElapsedCallback 过零后等待时间中断
psc=31
#define IC_TIMER_REGISTER TIM3
psc=0
PB4 tim3_chn1
一、使用到的变量
dma1chan1 interrupt transfercomplete:
- uint16_t signaltimeout = 0;
- out_put: 0:receiveDshotDma1:
1:sendDshotDma - char dshot_telemetry = 0; dshort检测到标志
processDshot(EXTI4_15_IRQHandler)<--DMA1_Channel1_IRQHandler
- ic_timer_prescaler char ic_timer_prescaler = CPU_FREQUENCY_MHZ / 5;
- output_timer_prescaler
if (CPU_FREQUENCY_MHZ > 100) {
output_timer_prescaler = 1;
} else {
output_timer_prescaler = 0;
}
- char inputSet = 0; 输入方式是否已经决定标志
二、输入端口设置
- PB4设置为tim3 channel1.
- dma1 channel1 ,方向per(halfword)–>memory(word)
- 分频为0
- 双沿触发
三、开始处理
- 在main初始化中调用receiveDshotDma().
- 在dma中断中处理transfercomplete()
void transfercomplete()
{
signaltimeout = 0;
if (armed && dshot_telemetry) {
if (out_put) {
receiveDshotDma();
compute_dshot_flag = 2;
return;
} else {
sendDshotDma();
compute_dshot_flag = 1;
return;
}
}
if (inputSet == 0) {
detectInput();
receiveDshotDma();
return;
}
if (inputSet == 1) {
if (dshot_telemetry) {
if (out_put) {
make_dshot_package(e_com_time);
computeDshotDMA();
receiveDshotDma();
return;
} else {
sendDshotDma();
return;
}
} else {
if (dshot == 1) {
computeDshotDMA();
receiveDshotDma();
}
if (servoPwm == 1) {
if (getInputPinState()) {
buffersize = 3;
} else {
buffersize = 2;
computeServoInput();
}
receiveDshotDma();
}
}
if (!armed) {
if (dshot && (average_count < 8) && (zero_input_count > 5)) {
average_count++;
average_packet_length = average_packet_length + (dma_buffer[31] - dma_buffer[0]);
if (average_count == 8) {
dshot_frametime_high = (average_packet_length >> 3) + (average_packet_length >> 7);
dshot_frametime_low = (average_packet_length >> 3) - (average_packet_length >> 7);
}
}
if (adjusted_input < 0) {
adjusted_input = 0;
}
if (adjusted_input == 0 && calibration_required == 0) { // note this in input..not newinput so it
// will be adjusted be main loop
zero_input_count++;
} else {

最低0.47元/天 解锁文章
1万+





