6621E 遥控红外码 输出配置理解参考

wen sir · 234次点击 · 2023-06-06


6621E 可通过类似NEC/RCA方式编码成任何想要发送的红外码。非常灵活自由。


每帧红外码,由N个PWM调制波,每个PWM调制波由(m毫秒调制高电平,和n ms非调制的低电平组成)


//TCL RCA编码格式  头+user+code+n_user+n_code
uint32_t RCA_Code[] =
{
    b_pre, //头帧
    b_c3, b_c2, b_c1, b_c0, //用户码低4位
    b_d7, b_d6, b_d5, b_d4, b_d3, b_d2, b_d1, b_d0, //遥控码 8位
    b_nc3, b_nc2, b_nc1, b_nc0, // 用户码低4位 反码
    b_nd7, b_nd6, b_nd5, b_nd4, b_nd3, b_nd2, b_nd1, b_nd0, //遥控码 8位反码
    b_wait,//空间码
};


/*------------------------------------------------------------------------------
|  标准NEC编码格式:前导码 + 8位地址码 + 8位地址反码 + 8位命令码 + 8位命令反码 |
-------------------------------------------------------------------------------*/
//红外遥控器编码
uint32_t NEC_code[] =
{
    preamble,
    b0, b0, b0, b0, b0, b0, b0, b0, //addr
    b1, b1, b1, b1, b1, b1, b1, b1, //addr_contrary
    b0, b1, b0, b0, b0, b0, b1, b0, //command
    b1, b0, b1, b1, b1, b1, b0, b1, //command_contrary
    End,
    repeat0, repeat1,
};
uint32_t REPEAT_code[] =
{
    repeat0, repeat1,
};


const uint32_t preamble = 0x00ab8156;  //前导码:9ms carrier(high),4.5ms低电平(low)

const uint32_t b0       = 0x00158015;  //'0':0.56ms high, 0.56ms low,在编码中用作发送二进制0
const uint32_t b1       = 0x00408015;  //'1': 0.56ms high, 1.69ms low, 在编码中用作发送二进制1
const uint32_t repeat0  = 0x00568156;  //9ms high,2.25ms low
const uint32_t repeat1  = 0x0e478015;  //0.56ms high,96.19ms low
const uint32_t End      = 0x05F08015;  //0.56ms high,40ms low

#define _H  (1) //输出调制高电平
#define _L  (0) //输出非调制低电平
#define f0  (0) //预设频率0,此为38K ,
#define f1  (1) //预设频率1,如50K
const uint32_t PWM_Rca_preamble = ((((_L) << 15) | ((f0) << 14) | (38 * 4)) << 16) | (((_H) << 15) | ((f0) << 14) | (38 * 4)); // 4H+4L   ms
const uint32_t PWM_Rca_b0       = ((((_L) << 15) | ((f0) << 14) | (38 * 1)) << 16) | (((_H) << 15) | ((f0) << 14) | (38 / 2)); // 0.5H+1L ms
const uint32_t PWM_Rca_b1       = ((((_L) << 15) | ((f0) << 14) | (38 * 2)) << 16) | (((_H) << 15) | ((f0) << 14) | (38 / 2)); // 0.5H+2L ms
const uint32_t PWM_Rca_End      = ((((_L) << 15) | ((f0) << 14) | (38 * 8)) << 16) | (((_H) << 15) | ((f0) << 14) | (38 / 2)); // 0.5H+8L ms

    每个调制波的的计算可参考 上面  PWM_Rca_preamble     的组成方式。38对应38K的调制信号。 因为38K,表示一秒钟有38K个脉冲,

1ms 有38个脉冲, 因此,总脉冲数为 为 n(ms)x38. 

    同理,如56K调制,则需要调为 n(ms)x56....


RCA 配置 示例

    uint8_t usr_code0, usr_code1;
    uint8_t key_code0, key_code1;
    usr_code0 = 0x0f;
    usr_code1 = usr_code0 ^ 0xff;
    key_code0 = ir_code;
    key_code1 = ir_code ^ 0xff;
    RCA_Code[b_pre] = PWM_Rca_preamble;
    RCA_Code[b_c3] = ((usr_code0 & (1 << 3)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_c2] = ((usr_code0 & (1 << 2)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_c1] = ((usr_code0 & (1 << 1)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_c0] = ((usr_code0 & (1 << 0)) ? PWM_Rca_b1 : PWM_Rca_b0);
    //
    RCA_Code[b_d7] = ((key_code0 & (1 << 7)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_d6] = ((key_code0 & (1 << 6)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_d5] = ((key_code0 & (1 << 5)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_d4] = ((key_code0 & (1 << 4)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_d3] = ((key_code0 & (1 << 3)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_d2] = ((key_code0 & (1 << 2)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_d1] = ((key_code0 & (1 << 1)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_d0] = ((key_code0 & (1 << 0)) ? PWM_Rca_b1 : PWM_Rca_b0);
    //
    RCA_Code[b_nc3] = ((usr_code1 & (1 << 3)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_nc2] = ((usr_code1 & (1 << 2)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_nc1] = ((usr_code1 & (1 << 1)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_nc0] = ((usr_code1 & (1 << 0)) ? PWM_Rca_b1 : PWM_Rca_b0);
    //
    RCA_Code[b_nd7] = ((key_code1 & (1 << 7)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_nd6] = ((key_code1 & (1 << 6)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_nd5] = ((key_code1 & (1 << 5)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_nd4] = ((key_code1 & (1 << 4)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_nd3] = ((key_code1 & (1 << 3)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_nd2] = ((key_code1 & (1 << 2)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_nd1] = ((key_code1 & (1 << 1)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_nd0] = ((key_code1 & (1 << 0)) ? PWM_Rca_b1 : PWM_Rca_b0);
    RCA_Code[b_wait] = PWM_Rca_End;

 

  ir_tx_config_t config =

    {
        .mode           = FIFO,
        .carrier_freq0  = 38000, //38K
        .duty_cycle0    = (double)1 / 3, //占空比为1/3
        .carrier_freq1  = 50000, //50K
        .duty_cycle1    = (double)1 / 2,
        .data_src       = RCA_Code,
        .data_num       = sizeof(RCA_Code) / sizeof(uint32_t), //总的输出周期数。

        .bUse_intr      = true,
        .fifo_trigger_lvl = 5,
        .fifo_cnt_intr_mask = FIFO_EMPTY_INTR_MASK,// FIFO_CNT_INTR_MASK,  //IR_TX有5个中断源。根据选择配置
        .callback[3]    = irtx_fifo_cnt_callback,

    };

中断 改为 FIFO_EMPTY_INTR_MASK  中断, 减少异常中断次数。

中断程序小修改如下

    if (NULL != irtx_env.callback[3] && (irtx_env.fifo_cnt_intr_mask & 0x2))
    {
        if (((HS_IR_TX->FIFO_SR) & 0x10) == 0x10)
        {
            //HS_IR_TX->FIFO_CNT_INT_MASK = 0;  //关闭fifo计数中断,否则中断会不停到来
        }
        else
        {
            HS_IR_TX->FIFO_CNT_INT_MASK = 0;  //关闭fifo计数中断,否则中断会不停到来
        }
        irtx_env.callback[3]();
    }


image.png



image.png




6621E_ir_send_RCA-202306099769.rar
被收藏 0  ∙  0 赞  
加入收藏
点赞
4 回复  
善言善语 (您需要 登录 后才能回复 没有账号 ?)

请先登录网站