Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 87 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,89 @@
---

# ArmBookCurso2024

Primer ejemplo básico para aprender a usar las herramientas
## **Título:** Control de Sistema de Tratamiento de Agua

### **Alumno:** Jesús García

### **Objetivo:**
Desarrollar un sistema de monitoreo y control para un proceso de tratamiento de agua.

### **Descripción:**

Este sistema controla el suministro y la producción de agua ultrapura mediante un tratamiento por ósmosis inversa. Utiliza diferentes módulos y periféricos para monitorear la presión y gestionar las bombas, optimizando el proceso de tratamiento de agua y garantizando su seguridad y eficiencia.

### **Componentes del sistema:**

1. **Módulo `control_system`:**
Inicializa el panel de control y actualiza el sistema constantemente.

2. **Módulo `panel_control`:**
Interactúa con los siguientes módulos:
- `buttons`: Gestiona la interacción con el usuario mediante botones.
- `display`: Muestra la información del sistema en la pantalla.
- `matrix_keypad`: Permite la entrada de datos mediante un teclado 4x3.
- `pressure_sensor`: Monitorea la presión de entrada y salida del sistema.
- `pumps`: Controla el funcionamiento de las bombas.
- `serial_communication`: Comunica información sobre el sistema mediante UART.

### **Funcionamiento:**

El sistema monitorea dos presiones clave:
- **P1:** Presión de entrada (antes de los filtros).
- **P2:** Presión de salida (después de los filtros).

En función de estas presiones, el sistema controla el encendido y apagado de las bombas para evitar condiciones peligrosas como la falta de agua o sobrepresión.

### **Interacción con el usuario:**

El usuario puede interactuar con el sistema mediante un botón que, al ser presionado de manera extendida, despliega un menú serial con las siguientes opciones:

1. **Ajustar Frecuencia de la Bomba:**
Permite ingresar la frecuencia de operación de las bombas mediante el teclado de 4x3.

2. **Verificar Estado del Sistema:**
Imprime las variables de estado del sistema en la pantalla.

3. **Detener Sistema:**
Detiene el funcionamiento de las bombas de manera segura.

### **Operación del sistema:**

- **Bombas P1 y P2:**
Funcionan dentro de los rangos de presión mínima y máxima.
La bomba P1 está controlada por la presión de entrada, mientras que P2 se controla por la presión de salida.

- **Pantalla LCD:**
Muestra el estado de cada variable del sistema, actualizándose periódicamente.

### **Plataforma de desarrollo:**
- **STM32 Nucleo-144**

### **Periféricos utilizados:**

- **USER BUTTON:**
Inicia o apaga el sistema.

- **LED 1:**
Indica un cambio de estado para iniciar el modo menú.

- **LED 2:**
Indica el estado de la bomba P1.

- **LED 3:**
Indica el estado de la bomba P2.

- **ANALOG IN 1:**
Simula un sensor de presión.

- **UART:**
Comunica información sobre el estado del sistema a un PC.

- **TECLADO:**
Permite navegar en el menú serial e ingresar la frecuencia de las bombas.

- **LCD:**
Visualiza los estados de las variables periódicamente.

---
3 changes: 3 additions & 0 deletions README.md.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ArmBookCurso2024

Primer ejemplo básico para aprender a usar las herramientas
32 changes: 32 additions & 0 deletions arm_book_lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//=====[#include guards - begin]===============================================

#ifndef _ARM_BOOK_LIB_H_
#define _ARM_BOOK_LIB_H_

//=====[Libraries]=============================================================

#include <mbed.h>

//=====[Declaration of public defines]=========================================

// Functional states
#ifndef OFF
#define OFF 0
#endif
#ifndef ON
#define ON (!OFF)
#endif

// Electrical states
#ifndef LOW
#define LOW 0
#endif
#ifndef HIGH
#define HIGH (!LOW)
#endif

#define delay(ms) thread_sleep_for( ms )

//=====[#include guards - end]=================================================

#endif // _ARM_BOOK_LIB_H_
15 changes: 8 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "mbed.h"
//=====[Libraries]=============================================================

int main()
{
DigitalIn B1_USER(BUTTON1);
#include "control_system.h"

DigitalOut LD1(LED1);
//=====[Main function, the program entry point after power on or reset]========

int main()
{
controlSystemInit();
while (true) {
LD1 = B1_USER;
controlSystemUpdate();
}
}
}
2 changes: 1 addition & 1 deletion mbed-os.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os.git#26606218ad9d1ee1c8781aa73774fd7ea3a7658e
https://github.com/ARMmbed/mbed-os.git#17dc3dc2e6e2817a8bd3df62f38583319f0e4fed
7 changes: 7 additions & 0 deletions mbed_app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"target_overrides": {
"*": {
"target.printf_lib": "std"
}
}
}
104 changes: 104 additions & 0 deletions modules/buttons/buttons.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//=====[Libraries]=============================================================

#include "buttons.h"
#include "mbed.h"
#include "arm_book_lib.h"

#include "serial_communication.h"


//=====[Declaration of private defines]========================================
#define DEBOUNCE_KEY_TIME_MS 400


//=====[Declaration of private data types]=====================================
typedef enum {
BUTTON_UP,
BUTTON_DEBOUNCE,
BUTTON_DOWN,
} buttonState_t;



//=====[Declaration and initialization of public global objects]===============
DigitalIn menuButton(BUTTON1);
DigitalOut Led_1(LED1);

//=====[Declaration of external public global variables]=======================
bool pressedButton = false;

//=====[Declaration and initialization of public global variables]=============

//=====[Declaration and initialization of private global variables]============
static buttonState_t buttonState = BUTTON_UP;
static int timeIncrement_ms = 0;

//=====[Declarations (prototypes) of private functions]========================
static void buttonReset();
static void buttonsUpdate();


//=====[Implementations of public functions]===================================
void buttonsInit( int updateTime_ms )
{
timeIncrement_ms = updateTime_ms;
menuButton.mode(PullDown);
Led_1=0;
buttonState= BUTTON_UP;
}

bool statusButton(){
buttonsUpdate();
return pressedButton;
}



//=====[Implementations of private functions]==================================

static void buttonsUpdate()
{
static int accumulatedDebouncebuttonTime = 0;
switch( buttonState ) {

case BUTTON_UP:
pressedButton = false;
if( menuButton == true) {
buttonState = BUTTON_DEBOUNCE;
accumulatedDebouncebuttonTime=0;
}
break;

case BUTTON_DEBOUNCE:
if( accumulatedDebouncebuttonTime >=
DEBOUNCE_KEY_TIME_MS ) {
if( menuButton == true ) {
Led_1=1;
buttonState = BUTTON_DOWN;
} else {
buttonState = BUTTON_UP;
}
}
accumulatedDebouncebuttonTime =
accumulatedDebouncebuttonTime + timeIncrement_ms;
break;

case BUTTON_DOWN:
if( menuButton == false ) {
pressedButton = true;
Led_1=0;
buttonState = BUTTON_UP;
}
break;

default:
buttonReset();
break;

}
}

static void buttonReset()
{
buttonState = BUTTON_UP;
}
17 changes: 17 additions & 0 deletions modules/buttons/buttons.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//=====[#include guards - begin]===============================================

#ifndef _BUTTONS_H_
#define _BUTTONS_H_

//=====[Declaration of public defines]=========================================

//=====[Declaration of public data types]======================================

//=====[Declarations (prototypes) of public functions]=========================

void buttonsInit( int updateTime_ms );
bool statusButton();

//=====[#include guards - end]=================================================

#endif
38 changes: 38 additions & 0 deletions modules/control_system/control_system.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//=====[Libraries]=============================================================

#include "arm_book_lib.h"

#include "control_system.h"
#include "control_panel.h"
#include "serial_communication.h"

//pendiente de agregar mas modulos con los cuales interactua


//=====[Declaration of private defines]========================================

//=====[Declaration of private data types]=====================================

//=====[Declaration and initialization of public global objects]===============

//=====[Declaration of external public global variables]=======================

//=====[Declaration and initialization of public global variables]=============

//=====[Declaration and initialization of private global variables]============

//=====[Declarations (prototypes) of private functions]========================

//=====[Implementations of public functions]===================================

void controlSystemInit(){
controlPanelInit();
}

void controlSystemUpdate()
{
controlPanelUpdate();
delay(SYSTEM_TIME_INCREMENT_MS);
}

//=====[Implementations of private functions]==================================
18 changes: 18 additions & 0 deletions modules/control_system/control_system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//=====[#include guards - begin]===============================================

#ifndef _SMART_HOME_SYSTEM_H_
#define _SMART_HOME_SYSTEM_H_

//=====[Declaration of public defines]=========================================
#define SYSTEM_TIME_INCREMENT_MS 10

//=====[Declaration of public data types]======================================

//=====[Declarations (prototypes) of public functions]=========================

void controlSystemInit();
void controlSystemUpdate();

//=====[#include guards - end]=================================================

#endif // _SMART_HOME_SYSTEM_H_
Loading