“One Wire Hackbrett” – 2nd Semester Software

In my ongoing research on controlling solenoids, I have been exploring the use of PWM (Pulse Width Modulation) as a strategy to control these actuators. To enhance my understanding, I studied the work of Professor Winfried Ritsch, who has extensively researched this topic. Specifically, I found his “PWMEnvelope” [1] repository to be a valuable resource for experimenting with my instrument.

In this chapter of my research, I aim to summarize the key points that are essential for understanding and implementing Professor Ritsch’s code. By simplifying the concepts and principles, I hope to provide a clear overview of how the code functions and how it can be applied to my own project of controlling solenoids.

Envelopes are used to control PWM signals. In the attack phase, there is a fade to gradually reach the stroke level. After the stroke time, a sustain phase is applied to maintain the desired level, followed by a release phase to fade out the signal. By working with these parameters, we directly influence the timbral result. Like a piano key, by changing the level of pressure and duration of the attack we can achieve different sonic results. To ensure the safe operation of these devices, especially when using duty cycles lower than 100%, “PWM one-shot pulses” are utilized to prevent any potential issues.

Attack Stroke Hold Release for solenoids:

         _                      stroke level

       /   |_____          hold level

  _ /                 \_      off

  A   S   H        R      times  

To implement this functionality with the ESP platform, the LED-C Library[2] is used for generating the PWM signal, while the Timer library handles the one-shot timer feature.

The LED Control (LEDC) peripheral is a feature of ESP32 microcontrollers that is primarily used for controlling the intensity of LEDs. However, it can also be used to generate PWM signals for other purposes. The LEDC has 8 channels, each capable of generating independent waveforms. The LEDC channels usually have a 4-Channel high-speed mode and a 4-Channel low-speed mode, which provide different ranges of frequency for LED control.

The specific frequencies achievable in each mode may vary depending on the microcontroller or LED driver being used. These channels can be used to drive RGB LED devices, among other applications. The PWM controller of the LEDC allows for gradual increase or decrease of the duty cycle, enabling smooth fades without requiring processor intervention.

To set up a channel in the LEDC, three steps are involved:

  • Timer Configuration: Specify the PWM signal’s frequency and duty cycle resolution;
  • Channel Configuration: Associate the channel with the timer and GPIO pins to output the PWM signal;
  • Change PWM Signal: Modify the PWM signal to control the LED’s intensity.

The ESP32’s Timer Library[3] can be used to generate PWM signals by configuring it to repeatedly count up to a certain value and then reset. The ratio of the time it takes to count up to the reset value compared to the total period determines the duty cycle of the PWM signal. By adjusting the duty cycle, it can control the average power or intensity delivered to the device connected to the output pin.

When using multiple libraries or processes that rely on timers in the ESP32 microcontroller, it is advisable to allocate each process to a specific hardware timer or counter to avoid interference between the processes. By assigning dedicated timers to different processes, potential conflicts, such as conflicting interrupt handling or timing discrepancies, can be avoided. Moreover, assigning separate timers to different processes helps maintain the integrity of each process’s timing operations and provides precise timing control.


[1] Ritsch, W. IEM development area, Sign in · GitLab. Available at: https://git.iem.at/uC/pwmenvelope/-/tree/master/examples/playing (Accessed: 11 June 2023).

[2] Led control (LEDC) ESP. Available at: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html (Accessed: 11 June 2023).

[3] General purpose timer (no date) ESP. Available at: https://docs.espressif.com/projects/esp-idf/en/v4.3/esp32/api-reference/peripherals/timer.html (Accessed: 16 June 2023).

Leave a Reply

Your email address will not be published. Required fields are marked *