66 lines
2.6 KiB
Plaintext
66 lines
2.6 KiB
Plaintext
/*
|
|
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
/**
|
|
* @defgroup PWM PWM Driver
|
|
* @brief Generic PWM Driver.
|
|
* @details This module implements a generic PWM (Pulse Width Modulation)
|
|
* driver.
|
|
* @pre In order to use the PWM driver the @p HAL_USE_PWM option
|
|
* must be enabled in @p halconf.h.
|
|
*
|
|
* @section pwm_1 Driver State Machine
|
|
* The driver implements a state machine internally, not all the driver
|
|
* functionalities can be used in any moment, any transition not explicitly
|
|
* shown in the following diagram has to be considered an error and shall
|
|
* be captured by an assertion (if enabled).
|
|
* @dot
|
|
digraph example {
|
|
rankdir="LR";
|
|
node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
|
|
edge [fontname=Helvetica, fontsize=8];
|
|
uninit [label="PWM_UNINIT", style="bold"];
|
|
stop [label="PWM_STOP\nLow Power"];
|
|
ready [label="PWM_READY\nClock Enabled"];
|
|
uninit -> stop [label="pwmInit()"];
|
|
stop -> stop [label="pwmStop()"];
|
|
stop -> ready [label="pwmStart()"];
|
|
ready -> stop [label="pwmStop()"];
|
|
ready -> ready [label="pwmEnableChannel()\npwmDisableChannel()"];
|
|
}
|
|
* @enddot
|
|
*
|
|
* @section pwm_2 PWM Operations.
|
|
* This driver abstracts a generic PWM timer composed of:
|
|
* - A clock prescaler.
|
|
* - A main up counter.
|
|
* - A comparator register that resets the main counter to zero when the limit
|
|
* is reached. An optional callback can be generated when this happens.
|
|
* - An array of @p PWM_CHANNELS PWM channels, each channel has an output,
|
|
* a comparator and is able to invoke an optional callback when a comparator
|
|
* match with the main counter happens.
|
|
* .
|
|
* A PWM channel output can be in two different states:
|
|
* - <b>IDLE</b>, when the channel is disabled or after a match occurred.
|
|
* - <b>ACTIVE</b>, when the channel is enabled and a match didn't occur yet
|
|
* in the current PWM cycle.
|
|
* .
|
|
* Note that the two states can be associated to both logical zero or one in
|
|
* the @p PWMChannelConfig structure.
|
|
*
|
|
* @ingroup HAL_NORMAL_DRIVERS
|
|
*/
|