You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/08/05 18:02:34 UTC

[GitHub] [incubator-nuttx] PetervdPerk commented on a diff in pull request #6788: LPC17xx_40xx PWM multichannel support

PetervdPerk commented on code in PR #6788:
URL: https://github.com/apache/incubator-nuttx/pull/6788#discussion_r939049907


##########
arch/arm/src/lpc17xx_40xx/lpc17_40_pwm.c:
##########
@@ -279,19 +327,135 @@ static int pwm_timer(struct lpc17_40_pwmtimer_s *priv,
                      const struct pwm_info_s *info)
 {
   irqstate_t flags;
+  uint32_t i;
+  uint32_t ret = OK;
+  uint32_t lerval = LER0_EN;
+  uint32_t pcrval = 0;
+  uint32_t mr0_freq;
 
   flags = enter_critical_section();
 
-  putreg32(info->frequency, LPC17_40_PWM1_MR0);         /* Set PWMMR0 = number of counts */
+  mr0_freq = 1.f / info->frequency * LPC17_40_PWM_CLOCK / 10;
+
+  putreg32(mr0_freq, LPC17_40_PWM1_MR0);         /* Set PWMMR0 = number of counts */
+
+#ifndef CONFIG_PWM_MULTICHAN
   putreg32(info->duty, LPC17_40_PWM1_MR1);              /* Set PWM cycle */
+#else
+  for (i = 0; i < CONFIG_PWM_NCHANNELS; i++)
+    {
+     switch (priv->channels[i].channel)
+       {
+#ifdef CONFIG_LPC17_40_PWM1_CHANNEL1
+         case 1:
+           {
+             putreg32(b16toi((uint64_t)info->channels[i].duty * mr0_freq
+                             + b16HALF),
+                      LPC17_40_PWM1_MR1); /* Set PWM cycle */
+             break;
+           }
+#endif
+
+#ifdef CONFIG_LPC17_40_PWM1_CHANNEL2
+         case 2:
+           {
+             putreg32(b16toi((uint64_t)info->channels[i].duty * mr0_freq
+                             + b16HALF),
+                      LPC17_40_PWM1_MR2); /* Set PWM cycle */
+             break;
+           }
+#endif
+
+#ifdef CONFIG_LPC17_40_PWM1_CHANNEL3
+         case 3:
+           {
+             putreg32(b16toi((uint64_t)info->channels[i].duty * mr0_freq
+                             + b16HALF),
+                      LPC17_40_PWM1_MR3); /* Set PWM cycle */
+             break;
+           }
+#endif
+
+#ifdef CONFIG_LPC17_40_PWM1_CHANNEL4
+         case 4:
+           {
+             putreg32(b16toi((uint64_t)info->channels[i].duty * mr0_freq
+                             + b16HALF),
+                      LPC17_40_PWM1_MR4); /* Set PWM cycle */
+             break;
+           }
+#endif
+
+#ifdef CONFIG_LPC17_40_PWM1_CHANNEL5
+         case 5:
+           {
+             putreg32(b16toi((uint64_t)info->channels[i].duty * mr0_freq
+                             + b16HALF),
+                      LPC17_40_PWM1_MR5); /* Set PWM cycle */
+             break;
+           }
+#endif
+
+#ifdef CONFIG_LPC17_40_PWM1_CHANNEL6
+         case 6:
+           {
+             putreg32(b16toi((uint64_t)info->channels[i].duty * mr0_freq

Review Comment:
   Thanks for the suggestion found out that `ub16mulub16` did exactly what I needed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org