Previously, I followed this tutorial here (https://www.hackster.io/mircemk/diy-che ... ice-bd972d) to make a simple pulsed electromagnetic field therapy device. It has a Gaqqee PWM module (to generate the PWM signals), feeding to a potentiometer (for the gain), and then to HW-517 mos switch driver (basically, just nmos to switch on/off the coils at different frequencies - 25Hz, or 100Hz, or even 18kHz).
Now, to improve in the next version, I want to add an ESP32 board to programmatically control things and control them over wifi/my phone.
I see this PWM module (from previous version: https://www.aliexpress.com/i/1005002656 ... pt=glo2vnm) has TTL serial communication pins (TXD, RXD). So, thinking, basically I can use ESP32 to control the frequency and the duty cycle that I want.
However, when I research more, it seems ESP32 has internal PWM modules (?).
To be specific, I try to follow this tutorial here: https://randomnerdtutorials.com/esp32-pwm-arduino-ide/
But I am stuck in the loop here. I don't understand what "ledcWrite(ledChannel, dutyCycle)" actually does. Sorry, not coming from an electrician background.
Code: Select all
void loop(){
// increase the LED brightness
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
// decrease the LED brightness
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
}
But then in this topic (viewtopic.php?f=12&t=11039), the author just uses the following, without looping:
Code: Select all
void loop() {
const int dutyCycle = 1024;
ledcWrite(ledChannel, dutyCycle);
const int dutyCycle2 = 64;
ledcWrite(ledChannel2, dutyCycle2);
}
Overall, I think I just want to write square wave patterns (1 and then 0) to 1 of the output pins of the ESP32 board. Then I connect that pin to the pwm input of HW-517 to control the copper coils.
Thank you very much.