mirror of
https://github.com/esp8266/Arduino.git
synced 2025-11-28 17:36:39 +03:00
Support multiple tone(), analogWrite(), and Servo (#4640)
Remove and rewrite all the parts of the core/libraries using TIMER1 and consolidate into a single, shared waveform generation interrupt structure. Tone, analogWrite(), Servo all now just call into this shared resource to perform their tasks so are all compatible and can be used simultaneously. This setup enables multiple tones, analogWrites, servos, and stepper motors to be controlled with reasonable accuracy. It uses both TIMER1 and the internal ESP cycle counter to handle timing of waveform edges. TIMER1 is used in non-reload mode and only edges cause interrupts. The interrupt is started and stopped as required, minimizing overhead when these features are not being used. A generic "startWaveform(pin, high-US, low-US, runtime-US)" and "stopWaveform(pin)" allow for further types of interfaces. Minimum high or low period is ~1 us. Add a tone(float) method, useful when working with lower frequencies. Fixes #4321. Fixes 4349.
This commit is contained in:
committed by
GitHub
parent
ea4720b03e
commit
ebda795f34
@@ -279,6 +279,7 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 100000
|
||||
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
|
||||
|
||||
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
|
||||
void tone(uint8_t _pin, double frequency, unsigned long duration = 0);
|
||||
void noTone(uint8_t _pin);
|
||||
|
||||
// WMath prototypes
|
||||
|
||||
Reference in New Issue
Block a user