1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-02 14:22:55 +03:00

Add support for hardware Sigma Delta generator

Provides a simple interface to attach/detach pins to the sigma-delta generator, and get/set the 2 parameters prescaler & target.  Working example that fades the onboard LED is provided.  Code and sample by @stefaandesmet2003.
This commit is contained in:
Earle F. Philhower, III
2018-03-10 12:07:04 -08:00
committed by GitHub
parent 3b269c4a96
commit afcbcd5cc9
4 changed files with 339 additions and 5 deletions

View File

@ -0,0 +1,48 @@
/* Any copyright is dedicated to the Public Domain. */
#include "sigma_delta.h"
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT); // blinkie & sigma-delta mix
uint32_t reqFreq = 1000;
uint32_t realFreq;
realFreq = sigmaDeltaSetup(0, reqFreq); // chose a low frequency
Serial.println();
Serial.println("Start Sigma Delta Example\n");
Serial.printf("Frequency = %u\n", realFreq);
}
void loop() {
uint8_t duty, iRepeat;
Serial.println("Attaching the built in led to the sigma delta source now\n");
Serial.printf("Current duty = %i, prescaler = %i\n", sigmaDeltaRead(), sigmaDeltaGetPrescaler());
sigmaDeltaAttachPin(LED_BUILTIN);
Serial.println("Dimming builtin led...\n");
for (iRepeat = 0; iRepeat < 10; iRepeat++) {
for (duty = 0; duty < 255; duty = duty + 5) {
sigmaDeltaWrite(0, duty);
delay(10);
}
for (duty = 255; duty > 0; duty = duty - 5) {
sigmaDeltaWrite(0, duty);
delay(10);
}
}
Serial.println("Detaching builtin led & playing a blinkie\n");
sigmaDeltaDetachPin(LED_BUILTIN);
for (iRepeat = 0; iRepeat < 20; iRepeat++) {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
delay(500);
}
}