2016-11-23 03:28:16 -05:00
|
|
|
/* Sigma-delta Example
|
|
|
|
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "esp_system.h"
|
|
|
|
#include "driver/sigmadelta.h"
|
|
|
|
/*
|
2017-09-25 15:20:48 -04:00
|
|
|
* This test code will configure sigma-delta and set GPIO4 as a signal output pin.
|
|
|
|
* If you connect this GPIO4 with a LED, you will see the LED blinking slowly.
|
2016-11-23 03:28:16 -05:00
|
|
|
*/
|
|
|
|
|
2017-09-25 15:20:48 -04:00
|
|
|
/*
|
|
|
|
* Configure and initialize the sigma delta modulation
|
|
|
|
* on channel 0 to output signal on GPIO4
|
2016-11-23 03:28:16 -05:00
|
|
|
*/
|
2017-03-22 00:36:11 -04:00
|
|
|
static void sigmadelta_example_init(void)
|
2016-11-23 03:28:16 -05:00
|
|
|
{
|
2017-09-25 15:20:48 -04:00
|
|
|
sigmadelta_config_t sigmadelta_cfg = {
|
|
|
|
.channel = SIGMADELTA_CHANNEL_0,
|
|
|
|
.sigmadelta_prescale = 80,
|
|
|
|
.sigmadelta_duty = 0,
|
2018-09-27 05:55:29 -04:00
|
|
|
.sigmadelta_gpio = GPIO_NUM_4,
|
2017-09-25 15:20:48 -04:00
|
|
|
};
|
|
|
|
sigmadelta_config(&sigmadelta_cfg);
|
2016-11-23 03:28:16 -05:00
|
|
|
}
|
|
|
|
|
2017-09-25 15:20:48 -04:00
|
|
|
/*
|
|
|
|
* Perform the sigma-delta modulation test
|
|
|
|
* by changing the duty of the output signal.
|
2016-11-23 03:28:16 -05:00
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
void app_main(void)
|
2016-11-23 03:28:16 -05:00
|
|
|
{
|
2017-03-22 00:36:11 -04:00
|
|
|
sigmadelta_example_init();
|
2017-09-25 15:20:48 -04:00
|
|
|
|
2016-11-23 03:28:16 -05:00
|
|
|
int8_t duty = 0;
|
|
|
|
int inc = 1;
|
2017-09-25 15:20:48 -04:00
|
|
|
while (1) {
|
2016-11-23 03:28:16 -05:00
|
|
|
sigmadelta_set_duty(SIGMADELTA_CHANNEL_0, duty);
|
2017-09-25 15:20:48 -04:00
|
|
|
/* By changing delay time, you can change the blink frequency of LED */
|
2016-12-21 20:42:21 -05:00
|
|
|
vTaskDelay(10 / portTICK_PERIOD_MS);
|
2016-11-23 03:28:16 -05:00
|
|
|
|
|
|
|
duty += inc;
|
2017-09-25 15:20:48 -04:00
|
|
|
if (duty == 127 || duty == -127) {
|
|
|
|
inc = (-1) * inc;
|
|
|
|
}
|
2016-11-23 03:28:16 -05:00
|
|
|
}
|
|
|
|
}
|