A method to realize IR remote control with Kinetis

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

A method to realize IR remote control with Kinetis

1,696件の閲覧回数
hongdong_chu
NXP Employee
NXP Employee

To implement IR transmitter, the first thing is to generate 38KHz infrared carrier. For kinetis microcontroller, such as KL16, we can use TPM module working in Edge-aligned PWM mode to generate carrier signal. Here is an example of TPM configuration, which output 38KHz, 1/3 duty cycle PWM signal:

SIM_SCGC6 |= SIM_SCGC6_TPM1_MASK;

         TPM1_SC = (TPM_SC_CMOD(0x00) | TPM_SC_PS(0x00));

         TPM1_C1SC = TPM_CnSC_CHF_MASK;

         TPM1_SC &= (uint32_t)~(uint32_t)((TPM_SC_TOF_MASK | TPM_SC_CPWMS_MASK));

         TPM1_CONF = (uint32_t)((TPM1_CONF & (uint32_t)~(uint32_t)(

                    TPM_CONF_CROT_MASK |

                    TPM_CONF_CSOO_MASK |

                    TPM_CONF_CSOT_MASK |

                    TPM_CONF_GTBEEN_MASK

                    )) | (uint32_t)(

                    TPM_CONF_DBGMODE(0x03)

                    ));

         TPM1_C1SC = (uint32_t)((TPM1_C1SC & (uint32_t)~(uint32_t)(

                    TPM_CnSC_CHF_MASK |

                    TPM_CnSC_CHIE_MASK |

                    TPM_CnSC_ELSA_MASK |

                    TPM_CnSC_DMA_MASK |

                    0xFFFFFF02U

                    )) | (uint32_t)(

                    TPM_CnSC_MSB_MASK |

                    TPM_CnSC_ELSB_MASK

                    ));

         TPM1_C1V = TPM_CnV_VAL(0x01A4);

         TPM1_MOD = (uint32_t)((TPM1_MOD & (uint32_t)~(uint32_t)(

                    TPM_MOD_MOD(0xFB12)

                    )) | (uint32_t)(

                    TPM_MOD_MOD(0x04ED)

                    ));

         TPM1_CNT &= (uint32_t)~(uint32_t)(TPM_CNT_COUNT(0xFFFF));

         TPM1_SC = (uint32_t)((TPM1_SC & (uint32_t)~(uint32_t)(

                    TPM_SC_DMA_MASK |

                    TPM_SC_TOF_MASK |

                    TPM_SC_TOIE_MASK |

                    TPM_SC_CPWMS_MASK |

                    TPM_SC_CMOD(0x02) |

                    TPM_SC_PS(0x07)

                    )) | (uint32_t)(

                    TPM_SC_CMOD(0x01)

                    ));

For NEC protocol, which consists of 9ms head, 4.5ms transition and 32 bit data, periodic interrupt timer can be used to generate exact IR data. The period of timer can be 10us, which is precise enough. In ISR, IR data is sent sequentially according to the protocol and interrupt counter. Here is configuration of PIT timer:

       SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;

         PIT_MCR = 0x00U;

         PIT_TFLG0 = PIT_TFLG_TIF_MASK;

         PIT_LDVAL0 = PIT_LDVAL_TSV(0xEF);

         NVIC_IPR5 = (uint32_t)((NVIC_IPR5 & (uint32_t)~(uint32_t)(

                    NVIC_IP_PRI_22(0x7F)

                    )) | (uint32_t)(

                    NVIC_IP_PRI_22(0x80)

                    ));

         NVIC_ISER |= NVIC_ISER_SETENA(0x00400000);

         PIT_TCTRL0 &= (uint32_t)~(uint32_t)(

                   PIT_TCTRL_TIE_MASK |

                   PIT_TCTRL_TEN_MASK |

                   0xFFFFFFF8U

                   );

         PIT_TCTRL0 |= PIT_TCTRL_TEN_MASK;

If two pins are used for IR transmitting, carrier is output on one pin and IR data on another pin, then carrier can always be on and IR data is modulated on carrier by hardware circuit. If only one pin is available, we need carry out modulation by software that control carrier on/off with IR data.

ラベル(1)
0 件の賞賛
返信
0 返答(返信)