Updated sigma delta API documenation and example

This commit is contained in:
krzychb 2017-09-25 21:20:48 +02:00
parent 2908e8a33a
commit b5e4c76bfe
4 changed files with 51 additions and 37 deletions

View file

@ -27,14 +27,14 @@ extern "C" {
* @brief Sigma-delta channel list * @brief Sigma-delta channel list
*/ */
typedef enum{ typedef enum{
SIGMADELTA_CHANNEL_0 = 0, /*!< Sigma-delta channel0 */ SIGMADELTA_CHANNEL_0 = 0, /*!< Sigma-delta channel 0 */
SIGMADELTA_CHANNEL_1 = 1, /*!< Sigma-delta channel1 */ SIGMADELTA_CHANNEL_1 = 1, /*!< Sigma-delta channel 1 */
SIGMADELTA_CHANNEL_2 = 2, /*!< Sigma-delta channel2 */ SIGMADELTA_CHANNEL_2 = 2, /*!< Sigma-delta channel 2 */
SIGMADELTA_CHANNEL_3 = 3, /*!< Sigma-delta channel3 */ SIGMADELTA_CHANNEL_3 = 3, /*!< Sigma-delta channel 3 */
SIGMADELTA_CHANNEL_4 = 4, /*!< Sigma-delta channel4 */ SIGMADELTA_CHANNEL_4 = 4, /*!< Sigma-delta channel 4 */
SIGMADELTA_CHANNEL_5 = 5, /*!< Sigma-delta channel5 */ SIGMADELTA_CHANNEL_5 = 5, /*!< Sigma-delta channel 5 */
SIGMADELTA_CHANNEL_6 = 6, /*!< Sigma-delta channel6 */ SIGMADELTA_CHANNEL_6 = 6, /*!< Sigma-delta channel 6 */
SIGMADELTA_CHANNEL_7 = 7, /*!< Sigma-delta channel7 */ SIGMADELTA_CHANNEL_7 = 7, /*!< Sigma-delta channel 7 */
SIGMADELTA_CHANNEL_MAX, SIGMADELTA_CHANNEL_MAX,
} sigmadelta_channel_t; } sigmadelta_channel_t;
@ -64,7 +64,8 @@ esp_err_t sigmadelta_config(const sigmadelta_config_t *config);
* *
* This function is used to set Sigma-delta channel duty, * This function is used to set Sigma-delta channel duty,
* If you add a capacitor between the output pin and ground, * If you add a capacitor between the output pin and ground,
* the average output voltage Vdc = VDDIO / 256 * duty + VDDIO/2, VDDIO is power supply voltage. * the average output voltage will be Vdc = VDDIO / 256 * duty + VDDIO/2,
* where VDDIO is the power supply voltage.
* *
* @param channel Sigma-delta channel number * @param channel Sigma-delta channel number
* @param duty Sigma-delta duty of one channel, the value ranges from -128 to 127, recommended range is -90 ~ 90. * @param duty Sigma-delta duty of one channel, the value ranges from -128 to 127, recommended range is -90 ~ 90.

View file

@ -1,11 +1,25 @@
Sigma-delta Modulation Sigma-delta Modulation
====================== ======================
Overview Introduction
-------- ------------
ESP32 has a second-order sigma-delta modulation module. ESP32 has a second-order sigma-delta modulation module. This driver configures the channels of the sigma-delta module.
This driver configures the channels of the sigma-delta module.
Functionality Overview
----------------------
There are eight independent sigma-delta modulation channels identified with :cpp:type:`sigmadelta_channel_t`. Each channel is capable to output the binary, hardware generated signal with the sigma-delta modulation.
Selected channel should be set up by providing configuration parameters in :cpp:type:`sigmadelta_config_t` and then applying this configuration with :cpp:func:`sigmadelta_config`.
Another option is to call individual functions, that will configure all required parameters one by one:
* **Prescaler** of the sigma-delta generator - :cpp:func:`sigmadelta_set_prescale`
* **Duty** of the output signal - :cpp:func:`sigmadelta_set_duty`
* **GPIO pin** to output modulated signal - :cpp:func:`sigmadelta_set_pin`
The range of the 'duty' input parameter of :cpp:func:`sigmadelta_set_duty` is from -128 to 127 (eight bit signed integer). If zero value is set, then the output signal's duty will be about 50%, see description of :cpp:func:`sigmadelta_set_duty`.
Application Example Application Example
------------------- -------------------
@ -16,4 +30,3 @@ API Reference
------------- -------------
.. include:: /_build/inc/sigmadelta.inc .. include:: /_build/inc/sigmadelta.inc

View file

@ -1,7 +1,7 @@
# Example: sigma_delta modulation # Example: sigma_delta modulation
This example uses the sigma_delta output modulation driver to generate modulated output on a GPIO. This example uses the sigma-delta driver to generate modulated output on a GPIO.
By default the GPIO output is 4, however you can edit this in the `sigmadelta_init()` function inside `main/sigmadelta_test.c`. By default the GPIO output is 4, however you can edit this in the `sigmadelta_init()` function inside `main/sigmadelta_test.c`.
If you connect an LED to the output GPIO, you will see it blinking slowly. If you connect a LED to the output GPIO, you will see it blinking slowly.

View file

@ -11,44 +11,44 @@
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_system.h" #include "esp_system.h"
#include "driver/sigmadelta.h" #include "driver/sigmadelta.h"
/* /*
* This test code intended to configure sigma-delta and set GPIO4 as signal output pin. * This test code will configure sigma-delta and set GPIO4 as a signal output pin.
* If you connect this GPIO4 with an LED, you will see the LED blinking slowly. * If you connect this GPIO4 with a LED, you will see the LED blinking slowly.
*/ */
/** /*
* @brief Sigma-delta initialization. * Configure and initialize the sigma delta modulation
* on channel 0 to output signal on GPIO4
*/ */
static void sigmadelta_example_init(void) static void sigmadelta_example_init(void)
{ {
sigmadelta_config_t sigmadelta_cfg = { sigmadelta_config_t sigmadelta_cfg = {
/* Sigma-delta channel0*/ .channel = SIGMADELTA_CHANNEL_0,
.channel = SIGMADELTA_CHANNEL_0, .sigmadelta_prescale = 80,
/* Sigma-delta set duty 10*/ .sigmadelta_duty = 0,
.sigmadelta_duty = 10, .sigmadelta_gpio = 4,
/* Set prescale 30 */ };
.sigmadelta_prescale = 80, sigmadelta_config(&sigmadelta_cfg);
/*select GPIO4 as output_io */
.sigmadelta_gpio = 4,
};
sigmadelta_config(&sigmadelta_cfg);
} }
/** /*
* @brief Sigma-delta test to change duty of output signal. * Perform the sigma-delta modulation test
* by changing the duty of the output signal.
*/ */
void app_main() void app_main()
{ {
sigmadelta_example_init(); sigmadelta_example_init();
int8_t duty = 0; int8_t duty = 0;
int inc = 1; int inc = 1;
while(1) { while (1) {
sigmadelta_set_duty(SIGMADELTA_CHANNEL_0, duty); sigmadelta_set_duty(SIGMADELTA_CHANNEL_0, duty);
/*by changing delay time, you can change the blink frequency of LED. */ /* By changing delay time, you can change the blink frequency of LED */
vTaskDelay(10 / portTICK_PERIOD_MS); vTaskDelay(10 / portTICK_PERIOD_MS);
duty += inc; duty += inc;
if(duty == 127 || duty == -127) inc = (-1) * inc; if (duty == 127 || duty == -127) {
inc = (-1) * inc;
}
} }
} }