我能使用CC2640R2F输出PWM脉冲,但是如何输出固定数量的PWM脉冲呢?
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脉冲
为您提供两个方向:
1.需要编程控制CC2640R2F的GPIO口生成所需的脉冲序列
2.还可以考虑使用CC2640R2F的硬件定时器来生成精确的PWM脉冲
您现在是用什么方式来输出PWM呢?
我现在输出PWM的方法如下,如何修改才能输出固定数量的PWM脉冲?
比如我想输出10个PWM脉冲数(其中包含高脉冲和低脉冲)
//生成微秒PWM方波
int pwm()
{
// Import PWM Driver definitions
//#include <ti/drivers/PWM.h>
PWM_Handle pwm;
PWM_Params pwmParams;
uint32_t dutyValue;
// Initialize the PWM driver.
PWM_init();
// Initialize the PWM parameters
PWM_Params_init(&pwmParams);
pwmParams.idleLevel = PWM_IDLE_LOW; // Output low when PWM is not running
pwmParams.periodUnits = PWM_PERIOD_HZ; // Period is in Hz
pwmParams.periodValue = 1e6; // 1MHz (1e6 = 1000000), 1us
pwmParams.dutyUnits = PWM_DUTY_FRACTION; // Duty is in fractional percentage
pwmParams.dutyValue = 0; // 0% initial duty cycle
// Open the PWM instance
pwm = PWM_open(Board_PWM0, &pwmParams); // PWM0输出PWM到引脚GPIO6
//pwm = PWM_open(Board_PWM1, &pwmParams); // PWM1输出PWM到引脚GPIO7
if (pwm == NULL) {
return 0;
// PWM_open() failed
//while (1);
}
PWM_start(pwm); // start PWM with 0% duty cycle
//计算占空比
dutyValue = (uint32_t) (((uint64_t) PWM_DUTY_FRACTION_MAX * 50) / 100);
PWM_setDuty(pwm, dutyValue); // set duty cycle to 50%
return 1;
}