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.

[参考译文] CC2340R5:Zephyr PWM 驱动器占空比干扰

Guru**** 2779905 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1618854/cc2340r5-zephyr-pwm-driver-duty-cycle-glitches

器件型号: CC2340R5

您好:

我试图了解 CC2340 的 PWM 驱动程序在 Zephyr 中的工作方式、原始驱动程序更新看起来类似这样:

	capture_compare_action = (flags & PWM_POLARITY_INVERTED) ? 0xB : 0xA;

	if (channel == 0) {
		HWREG(config->base + LGPT_O_C0CC) = pulse;
		HWREG(config->base + LGPT_O_C0CFG) = 0x100 | capture_compare_action;
	} else if (channel == 1) {
		HWREG(config->base + LGPT_O_C1CC) = pulse;
		HWREG(config->base + LGPT_O_C1CFG) = 0x200 | capture_compare_action;
	} else if (channel == 2) {
		HWREG(config->base + LGPT_O_C2CC) = pulse;
		HWREG(config->base + LGPT_O_C2CFG) = 0x400 | capture_compare_action;
	} else {
		LOG_ERR("Invalid chan ID");
		return -ENOTSUP;
	}

	/* get it from flags */
	HWREG(config->base + LGPT_O_CTL) = LGPT_CTL_MODE_UPDWN_PER;
	HWREG(config->base + LGPT_O_TGT) = period;

	/* Activate LGPT */

	HWREG(config->base + LGPT_O_STARTCFG) = 0x1;


不过、当更新 PWM 占空比时、这会导致毛刺脉冲:

【图片未加载】

我更改了此处驱动程序中的代码以使用 PCxCC 和 LGPT_O_PTGT 寄存器、这不会改变 PWM 行为、但我仍然会出现干扰。 我还尝试了 PCxCCNC、因为这在我们 SDK 的低级驱动程序中使用。 行为也一样。

我还看到每次调用驱动程序时都会启动计时器、因此我在此添加了一个 if 语句、仅在未启动计时器时才启动计时器。

这是我的最终实现、我仍然会遇到干扰、更不用说现在占空比行为不再平滑递增、这有点像是在争论几个步骤。 关于驱动程序为何不反映写入哪个寄存器的更改有何建议?

	capture_compare_action = (flags & PWM_POLARITY_INVERTED) ? 0xB : 0xA;

	if (channel == 0) {
		HWREG(config->base + LGPT_O_PC0CCNC) = pulse;
		HWREG(config->base + LGPT_O_C0CFG) = 0x100 | capture_compare_action;
	} else if (channel == 1) {
		HWREG(config->base + LGPT_O_PC1CCNC) = pulse;
		HWREG(config->base + LGPT_O_C1CFG) = 0x200 | capture_compare_action;
	} else if (channel == 2) {
		HWREG(config->base + LGPT_O_PC2CCNC) = pulse;
		HWREG(config->base + LGPT_O_C2CFG) = 0x400 | capture_compare_action;
	} else {
		LOG_ERR("Invalid chan ID");
		return -ENOTSUP;
	}

	/* get it from flags */
	HWREG(config->base + LGPT_O_CTL) = LGPT_CTL_MODE_UPDWN_PER;
	HWREG(config->base + LGPT_O_PTGTNC) = period;

	/* Activate LGPT */
	if (HWREG(config->base + LGPT_O_STARTCFG) == 0) {
		HWREG(config->base + LGPT_O_STARTCFG) = 0x1;
	}

 

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    嗨、Munan、

    感谢您联系我们! 我们将查看您的问题、尽快回复您!

    此致、

    Tarek D

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    嗨、Munan、

    将此内容移动到电子邮件中!

    此致、

    Tarek D