This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

3200 控制 pwm



小弟我现在想做一个可见光通信:需要用pwm波控制led灯传输数据。

现在,遇到一个问题:

                                       pwm频率设置成10kHz,发送一个12位的二进制data[0],我的想法是用定时器改变占空比,但是,尝试之后没能实现。

求工程师们指下路。

  • 1、参考TI的PWM例程,将PWM的信号输出。

    2、通过定时器更新PWM的占空比只需要在程序中更新比较值,具体代码如下:

    void UpdateDutyCycle(unsigned long ulBase, unsigned long ulTimer,unsigned char ucLevel)
    {
    //
    // Match value is updated to reflect the new dutycycle settings
    //
    MAP_TimerMatchSet(ulBase,ulTimer,(ucLevel*DUTYCYCLE_GRANULARITY));
    }

    // RYB - Update the duty cycle of the corresponding timers.
    // This changes the brightness of the LEDs appropriately.
    // The timers used are as per LP schematics.
    // 改变占空比!
    for(iLoopCnt = 0; iLoopCnt < 255; iLoopCnt++)
    {
    UpdateDutyCycle(TIMERA2_BASE, TIMER_B, iLoopCnt);
    UpdateDutyCycle(TIMERA3_BASE, TIMER_B, iLoopCnt);
    UpdateDutyCycle(TIMERA3_BASE, TIMER_A, iLoopCnt);
    MAP_UtilsDelay(100000);
    }

  • 您好, Terry Han

               我有一个问题希望得到您的指教:

               我用上升沿触发中断函数,触发函数中用按位与,来控制输出数据1和数据0的pwm占空比。

               更新占空比如何设定,可以使输出高电平代表数据位为1,低电平数据位为0。这样做的原因是,下一步我要用比较器读出01数据。