Tool/software:
Hi teams,
I am using LGPTimer driver to output 3 channel PWM.
How can I control a single PWM channel? Specifically, after configuring the LGPTimer parameters and calling LGPTimerLPF3_open
to initialize the driver, all three PWM channels are active. However, at certain times, I need to disable one of the channels (e.g., disable channel 2).
What I came up is to control the register directly, please see the code below. Is it the recommended way to achieve this functionality?
LGPTimerLPF3_Handle lgptHandle; LGPTimerLPF3_Params params; uint32_t cntTargetVal = 48000 / 2; // 1kHz PWM count in crystal of 48 MHz uint32_t chCompVal0 = cntTargetVal/2; // duty of 50% uint32_t chCompVal1 = cntTargetVal - cntTargetVal/10; // duty of 10% uint32_t chCompVal2 = cntTargetVal - cntTargetVal/20; // duty of 5% // Configure channels action LGPTimerLPF3_Params_init(¶ms); params.channelProperty[0].action = LGPTimerLPF3_CH_TOGGLE_ON_COMPARE_PERIODIC; params.channelProperty[1].action = LGPTimerLPF3_CH_TOGGLE_ON_COMPARE_PERIODIC; params.channelProperty[2].action = LGPTimerLPF3_CH_TOGGLE_ON_COMPARE_PERIODIC; // Open driver lgptHandle = LGPTimerLPF3_open(0, ¶ms); // Set channel output signal period LGPTimerLPF3_setInitialCounterTarget(lgptHandle, cntTargetVal, false); // Set channel output signal duty cycle LGPTimerLPF3_setInitialChannelCompVal(lgptHandle, LGPTimerLPF3_CH_NO_0, chCompVal0, false); LGPTimerLPF3_setInitialChannelCompVal(lgptHandle, LGPTimerLPF3_CH_NO_1, chCompVal1, false); LGPTimerLPF3_setInitialChannelCompVal(lgptHandle, LGPTimerLPF3_CH_NO_2, chCompVal2, false); // Start the LGPTimer in up-down-periodic mode LGPTimerLPF3_start(lgptHandle, LGPTimerLPF3_CTL_MODE_UPDWN_PER); while(1) { usleep(100000); // Disable HWREG(LGPT3_BASE | 0x000000C8) &= 0xFFFFFFF0; usleep(100000); // Enable HWREG(LGPT3_BASE | 0x000000C8) |= 0x0000000E; }
Thanks.
BR,
Connor.