2016-11-23 08:28:16 +00: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"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This test code intended to configure sigma-delta and set GPIO4 as signal output pin.
|
|
|
|
* If you connect this GPIO4 with an LED, you will see the LED blinking slowly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sigma-delta initialization.
|
|
|
|
*/
|
2017-03-22 04:36:11 +00:00
|
|
|
static void sigmadelta_example_init(void)
|
2016-11-23 08:28:16 +00:00
|
|
|
{
|
|
|
|
sigmadelta_config_t sigmadelta_cfg = {
|
|
|
|
/* Sigma-delta channel0*/
|
|
|
|
.channel = SIGMADELTA_CHANNEL_0,
|
|
|
|
/* Sigma-delta set duty 10*/
|
|
|
|
.sigmadelta_duty = 10,
|
|
|
|
/* Set prescale 30 */
|
|
|
|
.sigmadelta_prescale = 80,
|
|
|
|
/*select GPIO4 as output_io */
|
|
|
|
.sigmadelta_gpio = 4,
|
|
|
|
};
|
|
|
|
sigmadelta_config(&sigmadelta_cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sigma-delta test to change duty of output signal.
|
|
|
|
*/
|
|
|
|
void app_main()
|
|
|
|
{
|
2017-03-22 04:36:11 +00:00
|
|
|
sigmadelta_example_init();
|
2016-11-23 08:28:16 +00:00
|
|
|
int8_t duty = 0;
|
|
|
|
int inc = 1;
|
|
|
|
while(1) {
|
|
|
|
sigmadelta_set_duty(SIGMADELTA_CHANNEL_0, duty);
|
|
|
|
/*by changing delay time, you can change the blink frequency of LED. */
|
2016-12-22 01:42:21 +00:00
|
|
|
vTaskDelay(10 / portTICK_PERIOD_MS);
|
2016-11-23 08:28:16 +00:00
|
|
|
|
|
|
|
duty += inc;
|
|
|
|
if(duty == 127 || duty == -127) inc = (-1) * inc;
|
|
|
|
}
|
|
|
|
}
|