extras/new_pwm: multi-channel soft PWM with example

This commit is contained in:
Nochkin 2017-12-15 00:15:41 -05:00
parent c3ae04c93f
commit 86572c4b76
4 changed files with 63 additions and 0 deletions

3
.gitmodules vendored
View file

@ -34,3 +34,6 @@
[submodule "extras/libesphttpd/libesphttpd/lib/heatshrink"] [submodule "extras/libesphttpd/libesphttpd/lib/heatshrink"]
path = extras/libesphttpd/libesphttpd/lib/heatshrink path = extras/libesphttpd/libesphttpd/lib/heatshrink
url = https://github.com/atomicobject/heatshrink url = https://github.com/atomicobject/heatshrink
[submodule "extras/new_pwm"]
path = extras/new_pwm
url = https://github.com/nochkin/new_pwm

View file

@ -0,0 +1,4 @@
# Simple makefile for simple example
PROGRAM = new_pwm
EXTRA_COMPONENTS = extras/new_pwm
include ../../common.mk

View file

@ -0,0 +1,55 @@
/* Very basic example to test the pwm library
* Hook up an LED to pin14 and you should see the intensity change
*
* Part of esp-open-rtos
* Copyright (C) 2015 Javier Cardona (https://github.com/jcard0na)
* BSD Licensed as described in the file LICENSE
*/
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "new_pwm.h"
#define PWM_CHANNELS 3
const uint32_t period = 5000; // * 200ns ^= 1 kHz
// PWM setup
uint32_t io_info[PWM_CHANNELS][3] = {
{0, 0, 12},
{0, 0, 13},
{0, 0, 15},
};
// Initial duty: all off
uint32_t pwm_duty_init[PWM_CHANNELS] = {0};
void pwm_task(void *pvParameters)
{
uint32_t counts[PWM_CHANNELS] = {0, 1000, 3000};
while(1) {
vTaskDelay(10);
for (uint8_t ii=0; ii<PWM_CHANNELS; ii++) {
pwm_set_duty(counts[ii], ii);
counts[ii] += period/32;
if (counts[ii] > period)
counts[ii] = 0;
}
pwm_start();
}
}
void user_init(void)
{
uart_set_baud(0, 115200);
printf("SDK version:%s\n", sdk_system_get_sdk_version());
printf("pwm_init()\n");
pwm_init(period, pwm_duty_init, PWM_CHANNELS, io_info);
printf("pwm_start()\n");
pwm_start();
xTaskCreate(pwm_task, "new_pwm", 256, NULL, 2, NULL);
}

1
extras/new_pwm Submodule

@ -0,0 +1 @@
Subproject commit 8b8fc35f5fa6c6209e9d77dc539cf34f0f151c30