AM32 电调学习--tenKhzRoutine()函数分析

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:

  1. uint16_t signaltimeout = 0;
  2. out_put: 0:receiveDshotDma1:
    1:sendDshotDma
  3. char dshot_telemetry = 0; dshort检测到标志
processDshot(EXTI4_15_IRQHandler)<--DMA1_Channel1_IRQHandler
  1. ic_timer_prescaler char ic_timer_prescaler = CPU_FREQUENCY_MHZ / 5;
  2. output_timer_prescaler
        if (CPU_FREQUENCY_MHZ > 100) {
            output_timer_prescaler = 1;
        } else {
            output_timer_prescaler = 0;
        }

  1. char inputSet = 0; 输入方式是否已经决定标志

二、输入端口设置

  1. PB4设置为tim3 channel1.
  2. dma1 channel1 ,方向per(halfword)–>memory(word)
  3. 分频为0
  4. 双沿触发

三、开始处理

  1. 在main初始化中调用receiveDshotDma().
  2. 在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 {
               
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值