✅ Práctica 7
▷ #TSCLab #TCLab #ESP32 #Arduino #Control #MACI
En el siguiente blog se presenta la septima práctica y corresponde a la segunda del laboratorio de control de velocidad.
Objetivo general:
- Entender el funcionamiento del motor DC con PWM para aumentar o bajar la velocidad usando código de programación en el IDE de Arduino.
Objetivos específicos:
- Comparar los resultados de movimiento cambiando los parámetros.
Materiales:
- PCB de Temperature Control Lab (TSC-Lab)
Introducción:
En la práctica anterior, al motor se le enviaba señales de High y Low para ponerlo en marcha. Sin embargo, dentro de la realidad a un motor no se lo controla así, en algunas ocasiones se lo requiere hacer girar con cierta velocidad y durante esta práctica para tener control sobre la misma se lo hace con señales PWM.
Procedimiento:
Se asume que la placa del ESP-32 ha sido previamente instalada en el IDE de Arduino.
- Copiar el código en el IDE de Arduino:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
****************************** TSC-Lab ******************************* | |
***************************** PRACTICE 7 ***************************** | |
This practice is about speed control using PWM | |
By: Kevin E. Chica O | |
More information: https://tsc-lab.blogspot.com/ | |
*/ | |
//motor | |
int motor1Pin1 = 33; | |
int motor1Pin2 = 25; | |
int enable1Pin = 32; | |
// Setting PWM properties | |
const int freq = 30000; | |
const int pwmChannel = 0; | |
const int resolution = 8; | |
int dutyCycle = 200; | |
void motor( void *pvParameters ); | |
void setup() { | |
Serial.begin(115200); | |
// sets the pins as outputs: | |
pinMode(motor1Pin1, OUTPUT); | |
pinMode(motor1Pin2, OUTPUT); | |
pinMode(enable1Pin, OUTPUT); | |
// configure LED PWM functionalitites | |
ledcSetup(pwmChannel, freq, resolution); | |
// attach the channel to the GPIO to be controlled | |
ledcAttachPin(enable1Pin, pwmChannel); | |
xTaskCreate( | |
motor | |
, "MotorDC" // Descriptive name of the function (MAX 8 characters) | |
, 2048 // Size required in STACK memory | |
, NULL // INITIAL parameter to receive (void *) | |
, 0 // Priority, priority = 3 (configMAX_PRIORITIES - 1) is the highest, priority = 0 is the lowest. | |
, NULL ); // Variable that points to the task (optional) | |
} | |
void loop() { | |
} | |
void motor( void *pvParameters ) { | |
while (1) { | |
// Move DC motor forward with increasing speed | |
digitalWrite(motor1Pin1, HIGH); | |
digitalWrite(motor1Pin2, LOW); | |
while (dutyCycle <= 255) { | |
ledcWrite(pwmChannel, dutyCycle); | |
Serial.print("Forward with duty cycle: "); | |
Serial.println(dutyCycle); | |
dutyCycle = dutyCycle + 5; | |
vTaskDelay(500); | |
} | |
// Stop the DC motor | |
Serial.println("Motor stopped"); | |
digitalWrite(motor1Pin1, LOW); | |
digitalWrite(motor1Pin2, LOW); | |
vTaskDelay(4000); | |
dutyCycle = 200; | |
// Move DC motor backwards with increasing speed | |
digitalWrite(motor1Pin1, LOW); | |
digitalWrite(motor1Pin2, HIGH); | |
while (dutyCycle <= 255) { | |
ledcWrite(pwmChannel, dutyCycle); | |
Serial.print("Backwards with duty cycle: "); | |
Serial.println(dutyCycle); | |
dutyCycle = dutyCycle + 5; | |
vTaskDelay(500); | |
} | |
// Stop the DC motor | |
Serial.println("Motor stopped"); | |
digitalWrite(motor1Pin1, LOW); | |
digitalWrite(motor1Pin2, LOW); | |
vTaskDelay(4000); | |
dutyCycle = 200; | |
} | |
} |
Repositories: https://github.com/vasanza/TSC-Lab/tree/main/Practice7
- Cargar el código a la placa.
- Observar el movimiento del motor.
Nota: cambie los parámetros y vuelva a realizar el proceso antes detallado y compare los resultados. Por ejemplo, se podría modificar el dutyCycle inicial o el incremento del mismo.
Comments
Post a Comment