小弟我现在想做一个可见光通信:需要用pwm波控制led灯传输数据。
现在,遇到一个问题:
pwm频率设置成10kHz,发送一个12位的二进制data[0],我的想法是用定时器改变占空比,但是,尝试之后没能实现。
求工程师们指下路。
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.
小弟我现在想做一个可见光通信:需要用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);
}