hal_pwm.dox 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @defgroup PWM PWM Driver
  15. * @brief Generic PWM Driver.
  16. * @details This module implements a generic PWM (Pulse Width Modulation)
  17. * driver.
  18. * @pre In order to use the PWM driver the @p HAL_USE_PWM option
  19. * must be enabled in @p halconf.h.
  20. *
  21. * @section pwm_1 Driver State Machine
  22. * The driver implements a state machine internally, not all the driver
  23. * functionalities can be used in any moment, any transition not explicitly
  24. * shown in the following diagram has to be considered an error and shall
  25. * be captured by an assertion (if enabled).
  26. * @dot
  27. digraph example {
  28. rankdir="LR";
  29. node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
  30. edge [fontname=Helvetica, fontsize=8];
  31. uninit [label="PWM_UNINIT", style="bold"];
  32. stop [label="PWM_STOP\nLow Power"];
  33. ready [label="PWM_READY\nClock Enabled"];
  34. uninit -> stop [label="pwmInit()"];
  35. stop -> stop [label="pwmStop()"];
  36. stop -> ready [label="pwmStart()"];
  37. ready -> stop [label="pwmStop()"];
  38. ready -> ready [label="pwmEnableChannel()\npwmDisableChannel()"];
  39. }
  40. * @enddot
  41. *
  42. * @section pwm_2 PWM Operations.
  43. * This driver abstracts a generic PWM timer composed of:
  44. * - A clock prescaler.
  45. * - A main up counter.
  46. * - A comparator register that resets the main counter to zero when the limit
  47. * is reached. An optional callback can be generated when this happens.
  48. * - An array of @p PWM_CHANNELS PWM channels, each channel has an output,
  49. * a comparator and is able to invoke an optional callback when a comparator
  50. * match with the main counter happens.
  51. * .
  52. * A PWM channel output can be in two different states:
  53. * - <b>IDLE</b>, when the channel is disabled or after a match occurred.
  54. * - <b>ACTIVE</b>, when the channel is enabled and a match didn't occur yet
  55. * in the current PWM cycle.
  56. * .
  57. * Note that the two states can be associated to both logical zero or one in
  58. * the @p PWMChannelConfig structure.
  59. *
  60. * @ingroup HAL_NORMAL_DRIVERS
  61. */