1 /* Sigma-delta Example
2
3 This example code is in the Public Domain (or CC0 licensed, at your option.)
4
5 Unless required by applicable law or agreed to in writing, this
6 software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7 CONDITIONS OF ANY KIND, either express or implied.
8 */
9 #include <stdio.h>
10 #include "freertos/FreeRTOS.h"
11 #include "freertos/task.h"
12 #include "esp_system.h"
13 #include "driver/sigmadelta.h"
14 /*
15 * This test code will configure sigma-delta and set GPIO4 as a signal output pin.
16 * If you connect this GPIO4 with a LED, you will see the LED blinking slowly.
17 */
18
19 /*
20 * Configure and initialize the sigma delta modulation
21 * on channel 0 to output signal on GPIO4
22 */
sigmadelta_example_init(void)23 static void sigmadelta_example_init(void)
24 {
25 sigmadelta_config_t sigmadelta_cfg = {
26 .channel = SIGMADELTA_CHANNEL_0,
27 .sigmadelta_prescale = 80,
28 .sigmadelta_duty = 0,
29 .sigmadelta_gpio = GPIO_NUM_4,
30 };
31 sigmadelta_config(&sigmadelta_cfg);
32 }
33
34 /*
35 * Perform the sigma-delta modulation test
36 * by changing the duty of the output signal.
37 */
app_main(void)38 void app_main(void)
39 {
40 sigmadelta_example_init();
41
42 int8_t duty = 0;
43 int inc = 1;
44 while (1) {
45 sigmadelta_set_duty(SIGMADELTA_CHANNEL_0, duty);
46 /* By changing delay time, you can change the blink frequency of LED */
47 vTaskDelay(10 / portTICK_PERIOD_MS);
48
49 duty += inc;
50 if (duty == 127 || duty == -127) {
51 inc = (-1) * inc;
52 }
53 }
54 }
55