aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/templates
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-11-21 11:12:54 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-11-21 11:12:54 +0000
commit66c5a970fa52e53e643ef1f3365b4d30debd5bfe (patch)
tree6cea71ea231f0a27ebef680a0f60f19bc9175280 /os/hal/templates
parent297a1cefa8e045e68c6b12d1cb31525a086ae4ec (diff)
downloadChibiOS-66c5a970fa52e53e643ef1f3365b4d30debd5bfe.tar.gz
ChibiOS-66c5a970fa52e53e643ef1f3365b4d30debd5bfe.tar.bz2
ChibiOS-66c5a970fa52e53e643ef1f3365b4d30debd5bfe.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2406 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/templates')
-rw-r--r--os/hal/templates/pwm_lld.h21
1 files changed, 19 insertions, 2 deletions
diff --git a/os/hal/templates/pwm_lld.h b/os/hal/templates/pwm_lld.h
index 1b0b38f75..2b8cf294f 100644
--- a/os/hal/templates/pwm_lld.h
+++ b/os/hal/templates/pwm_lld.h
@@ -138,6 +138,21 @@ struct PWMDriver {
/*===========================================================================*/
/**
+ * @brief Converts from fraction to pulse width.
+ * @note Be careful with rounding errors, this is integer math not magic.
+ * You can specify tenths of thousandth but make sure you have the
+ * proper hardware resolution by carefully choosing the clock source
+ * and prescaler settings, see @p PWM_COMPUTE_PSC.
+ *
+ * @param[in] numerator numerator of the fraction
+ * @param[in] denominator percentage as an integer between 0 and numerator
+ * @return The pulse width to be passed to @p pwmEnableChannel().
+ *
+ * @api
+ */
+#define PWM_FRACTION_TO_WIDTH(pwmp, numerator, denominator) 0
+
+/**
* @brief Converts from degrees to pulse width.
* @note Be careful with rounding errors, this is integer math not magic.
* You can specify hundredths of degrees but make sure you have the
@@ -150,7 +165,8 @@ struct PWMDriver {
*
* @api
*/
-#define PWM_DEGREES_TO_WIDTH(pwmp, degrees) 0
+#define PWM_DEGREES_TO_WIDTH(pwmp, degrees) \
+ PWM_FRACTION_TO_WIDTH(pwmp, 36000, degrees)
/**
* @brief Converts from percentage to pulse width.
@@ -165,7 +181,8 @@ struct PWMDriver {
*
* @api
*/
-#define PWM_PERCENTAGE_TO_WIDTH(pwmp, percentage) 0
+#define PWM_PERCENTAGE_TO_WIDTH(pwmp, percentage) \
+ PWM_FRACTION_TO_WIDTH(pwmp, 10000, percentage)
/*===========================================================================*/
/* External declarations. */