From 003ee5c7d38bfbc423f71b8ba6158451b0ebddab Mon Sep 17 00:00:00 2001 From: uno21 Date: Sat, 26 Apr 2025 15:17:34 -0600 Subject: [PATCH 1/6] teoria --- app/inc/MovMotorPrueba.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 app/inc/MovMotorPrueba.h diff --git a/app/inc/MovMotorPrueba.h b/app/inc/MovMotorPrueba.h new file mode 100644 index 0000000..d787fe0 --- /dev/null +++ b/app/inc/MovMotorPrueba.h @@ -0,0 +1,37 @@ +#include "CanBusTask.h" + +// Prueba de mover el motor, aumenta la velocidad cada segundo + + +void StartCANTxTask(void* argument) { + uint8_t speed = 0; // Velocidad inicial + CAN_TxHeaderTypeDef txHeader; + uint8_t txData[8] = {0}; // Datos CAN (8 bytes) + uint32_t txMailbox; + + // Configurar el encabezado del mensaje CAN + txHeader.StdId = CONTROL_ID_1FF; // ID del motor + txHeader.RTR = CAN_RTR_DATA; + txHeader.IDE = CAN_ID_STD; + txHeader.DLC = RM_DLC; // Longitud de datos (8 bytes) + + for (;;) { + // Incrementar la velocidad + speed += 10; // Incremento de 10 unidades por segundo + if (speed > 255) speed = 0; // Reiniciar si supera el máximo + + // Configurar los datos del mensaje + txData[0] = speed; // Velocidad en el primer byte + for (int i = 1; i < 8; i++) { + txData[i] = 0; // Rellenar con ceros + } + + // Enviar el mensaje CAN + if (HAL_CAN_AddTxMessage(&hcan1, &txHeader, txData, &txMailbox) != HAL_OK) { + // Manejar error de transmisión + } + + // Esperar 1 segundo + osDelay(1000); + } +} \ No newline at end of file From 4d3030f23b0e1f4738f340afe0afe63a934bdac7 Mon Sep 17 00:00:00 2001 From: uno21 Date: Sat, 26 Apr 2025 15:18:42 -0600 Subject: [PATCH 2/6] teoria --- app/inc/MovMotorPrueba.h | 1 - 1 file changed, 1 deletion(-) diff --git a/app/inc/MovMotorPrueba.h b/app/inc/MovMotorPrueba.h index d787fe0..6efbd5c 100644 --- a/app/inc/MovMotorPrueba.h +++ b/app/inc/MovMotorPrueba.h @@ -2,7 +2,6 @@ // Prueba de mover el motor, aumenta la velocidad cada segundo - void StartCANTxTask(void* argument) { uint8_t speed = 0; // Velocidad inicial CAN_TxHeaderTypeDef txHeader; From 61f0e72937d5fb037e4331014a122df595a246c3 Mon Sep 17 00:00:00 2001 From: uno21 Date: Sat, 26 Apr 2025 15:19:16 -0600 Subject: [PATCH 3/6] teoria --- app/inc/MovMotorPrueba.h | 1 - 1 file changed, 1 deletion(-) diff --git a/app/inc/MovMotorPrueba.h b/app/inc/MovMotorPrueba.h index 6efbd5c..10100bf 100644 --- a/app/inc/MovMotorPrueba.h +++ b/app/inc/MovMotorPrueba.h @@ -1,6 +1,5 @@ #include "CanBusTask.h" -// Prueba de mover el motor, aumenta la velocidad cada segundo void StartCANTxTask(void* argument) { uint8_t speed = 0; // Velocidad inicial From a9b2e7038c78351deb518c55893b1c9873479090 Mon Sep 17 00:00:00 2001 From: uno21 Date: Sat, 26 Apr 2025 15:22:00 -0600 Subject: [PATCH 4/6] teoria --- app/inc/MovMotorPrueba.h | 1 - 1 file changed, 1 deletion(-) diff --git a/app/inc/MovMotorPrueba.h b/app/inc/MovMotorPrueba.h index 10100bf..4aa48a1 100644 --- a/app/inc/MovMotorPrueba.h +++ b/app/inc/MovMotorPrueba.h @@ -1,6 +1,5 @@ #include "CanBusTask.h" - void StartCANTxTask(void* argument) { uint8_t speed = 0; // Velocidad inicial CAN_TxHeaderTypeDef txHeader; From aab6720d5e967ecb9e99bdc58e8dff6eb532eae9 Mon Sep 17 00:00:00 2001 From: uno21 Date: Sat, 26 Apr 2025 16:20:51 -0600 Subject: [PATCH 5/6] Mover motor con PWD y no con CAN --- app/inc/MovMotorPrueba.h | 46 ++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/app/inc/MovMotorPrueba.h b/app/inc/MovMotorPrueba.h index 4aa48a1..24f7c9c 100644 --- a/app/inc/MovMotorPrueba.h +++ b/app/inc/MovMotorPrueba.h @@ -1,34 +1,24 @@ -#include "CanBusTask.h" +#include "main.h" + #include "cmsis_os.h" + #include "robotConfig.h" // Asegúrate de incluir el archivo donde se define htim3 -void StartCANTxTask(void* argument) { - uint8_t speed = 0; // Velocidad inicial - CAN_TxHeaderTypeDef txHeader; - uint8_t txData[8] = {0}; // Datos CAN (8 bytes) - uint32_t txMailbox; + extern TIM_HandleTypeDef htim3; // Declaración del temporizador existente - // Configurar el encabezado del mensaje CAN - txHeader.StdId = CONTROL_ID_1FF; // ID del motor - txHeader.RTR = CAN_RTR_DATA; - txHeader.IDE = CAN_ID_STD; - txHeader.DLC = RM_DLC; // Longitud de datos (8 bytes) + void StartPWMTxTask(void* argument) { + uint32_t dutyCycle = 0; // Ciclo de trabajo inicial (0%) - for (;;) { - // Incrementar la velocidad - speed += 10; // Incremento de 10 unidades por segundo - if (speed > 255) speed = 0; // Reiniciar si supera el máximo + // Iniciar el PWM en el canal 1 del temporizador 3 + HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); - // Configurar los datos del mensaje - txData[0] = speed; // Velocidad en el primer byte - for (int i = 1; i < 8; i++) { - txData[i] = 0; // Rellenar con ceros - } + for (;;) { + // Incrementar el ciclo de trabajo + dutyCycle += 100; // Incremento de 10% (100/1000) + if (dutyCycle > 1000) dutyCycle = 0; // Reiniciar si supera el 100% - // Enviar el mensaje CAN - if (HAL_CAN_AddTxMessage(&hcan1, &txHeader, txData, &txMailbox) != HAL_OK) { - // Manejar error de transmisión - } + // Actualizar el ciclo de trabajo + __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, dutyCycle); - // Esperar 1 segundo - osDelay(1000); - } -} \ No newline at end of file + // Esperar 1 segundo + osDelay(1000); + } + } \ No newline at end of file From 952d54c6701bb1abb0fbab86eae6e0137c8808d3 Mon Sep 17 00:00:00 2001 From: uno21 Date: Thu, 1 May 2025 22:30:19 -0600 Subject: [PATCH 6/6] Fix tim.c, pa q jale el motor (teoria) --- app/inc/MovMotorPrueba.h | 45 +++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/app/inc/MovMotorPrueba.h b/app/inc/MovMotorPrueba.h index 24f7c9c..04a90e8 100644 --- a/app/inc/MovMotorPrueba.h +++ b/app/inc/MovMotorPrueba.h @@ -1,24 +1,35 @@ +#ifndef MOVMOTORPRUEBA_H +#define MOVMOTORPRUEBA_H + #include "main.h" - #include "cmsis_os.h" - #include "robotConfig.h" // Asegúrate de incluir el archivo donde se define htim3 +#include "cmsis_os.h" +#include "tim.h" + +extern TIM_HandleTypeDef htim3; // Declaración del timer existente - extern TIM_HandleTypeDef htim3; // Declaración del temporizador existente +/* Tarea PWM para control del motor */ +void StartPWMTxTask(void const * argument) { + uint32_t dutyCycle = 0; // Ciclo de trabajo inicial (0%) - void StartPWMTxTask(void* argument) { - uint32_t dutyCycle = 0; // Ciclo de trabajo inicial (0%) + // Iniciar PWM en el canal 1 del timer 3 + if (HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1) != HAL_OK) { + // Manejar error si el PWM no inicia correctamente + Error_Handler(); + } - // Iniciar el PWM en el canal 1 del temporizador 3 - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); + for(;;) { + // Incrementar el ciclo de trabajo + dutyCycle += 100; // Incrementar en 10% (100/1000) + if (dutyCycle > 1000) { + dutyCycle = 0; // Reiniciar si excede el 100% + } - for (;;) { - // Incrementar el ciclo de trabajo - dutyCycle += 100; // Incremento de 10% (100/1000) - if (dutyCycle > 1000) dutyCycle = 0; // Reiniciar si supera el 100% + // Actualizar el ciclo de trabajo + __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, dutyCycle); - // Actualizar el ciclo de trabajo - __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, dutyCycle); + // Esperar 1 segundo + osDelay(1000); + } +} - // Esperar 1 segundo - osDelay(1000); - } - } \ No newline at end of file +#endif /* MOVMOTORPRUEBA_H */ \ No newline at end of file