SOLDADOR DE DOBLE PULSO CON BLUEPILL STM32F103

Dependencies:   mbed QEI Debounced TextLCD

Committer:
tony63
Date:
Thu Jun 20 02:45:52 2019 +0000
Revision:
3:f3e7caa1d402
Parent:
2:75153c8d2ef0
version2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tony63 2:75153c8d2ef0 1 //demo display y encoder
tony63 2:75153c8d2ef0 2 //programa para probar un bluepill con encoder y lcd y pulsadores
tony63 2:75153c8d2ef0 3 //control de soldador de punto de doble pulso
tony63 2:75153c8d2ef0 4 //se emiten dos pulsos y una espera intermedia
tony63 2:75153c8d2ef0 5 //antes de hacer esto se carga un condensador de 5F por 3seg con el IGBT1
tony63 2:75153c8d2ef0 6 //luego se envian los pulsos de soldadura por el IGBT, con los tiempos configurados
hudakz 0:271d74b09d64 7 #include "mbed.h"
hudakz 0:271d74b09d64 8 #include "TextLCD.h"
tony63 2:75153c8d2ef0 9 #include "QEI.h"
tony63 3:f3e7caa1d402 10 /*
tony63 3:f3e7caa1d402 11 #include "mbed.h"
tony63 3:f3e7caa1d402 12 #include "QEI.h"
tony63 3:f3e7caa1d402 13 QEI encoder (PB_13, PB_12, NC, 100);//PB12 ES EL CLK... PB13 ES EL DT DE ARDUINO ENCO
tony63 3:f3e7caa1d402 14 Serial COM(PB_6, PB_7);
hudakz 1:e10c603cf0ae 15
tony63 3:f3e7caa1d402 16
tony63 3:f3e7caa1d402 17 int main() {
tony63 3:f3e7caa1d402 18
tony63 3:f3e7caa1d402 19 while(1){
tony63 3:f3e7caa1d402 20 wait(0.1);
tony63 3:f3e7caa1d402 21 COM.printf("Pulses is: %i\n", encoder.getPulses());
tony63 3:f3e7caa1d402 22 }
tony63 3:f3e7caa1d402 23
tony63 3:f3e7caa1d402 24 }
tony63 3:f3e7caa1d402 25 */
tony63 2:75153c8d2ef0 26 // se configura el lcd en este caso uno de cuatro filas
tony63 3:f3e7caa1d402 27 TextLCD lcd(PA_3, PA_2, PA_1, PA_0, PC_15, PC_14, TextLCD::LCD16x4); // 4-bit bus: RS, E, D4, D5, D6, D7
hudakz 0:271d74b09d64 28
tony63 2:75153c8d2ef0 29 int p=0,p1=0,p2=0,espera=0,pulsos=0; //variables del programa
tony63 2:75153c8d2ef0 30 int i=0; //posicion de la variable en el display
tony63 3:f3e7caa1d402 31 QEI wheel (PB_13, PB_12, NC, 100); //configuramos encoder de libreria. dos fases y pulsos x rev
tony63 3:f3e7caa1d402 32 InterruptIn button(PB_14);
tony63 3:f3e7caa1d402 33 DigitalIn fire(PB_15);
tony63 2:75153c8d2ef0 34 DigitalOut IGBT(PB_6); //señal para el igbt
tony63 2:75153c8d2ef0 35 DigitalOut IGBT1(PB_8); //señal para el igbt1 de carga del condensador
hudakz 0:271d74b09d64 36
tony63 2:75153c8d2ef0 37 void flip() {
tony63 3:f3e7caa1d402 38 wait_ms(1);
tony63 2:75153c8d2ef0 39 if(button==0){
tony63 2:75153c8d2ef0 40 i++;
tony63 2:75153c8d2ef0 41 if(i>2){
tony63 2:75153c8d2ef0 42 i=0;
tony63 2:75153c8d2ef0 43 }
tony63 2:75153c8d2ef0 44 }
tony63 2:75153c8d2ef0 45 }
hudakz 0:271d74b09d64 46
tony63 2:75153c8d2ef0 47 void weld() {
tony63 3:f3e7caa1d402 48
tony63 2:75153c8d2ef0 49 IGBT1=1; // carga el condensador
tony63 2:75153c8d2ef0 50 wait(3); //tres segundos
tony63 2:75153c8d2ef0 51 IGBT1=0; //fin de la carga
tony63 2:75153c8d2ef0 52 IGBT=0;
tony63 3:f3e7caa1d402 53 wait_ms(1);
tony63 2:75153c8d2ef0 54 IGBT=1;
tony63 2:75153c8d2ef0 55 wait_ms(p1);
tony63 2:75153c8d2ef0 56 IGBT=0;
tony63 2:75153c8d2ef0 57 wait_ms(espera);
tony63 2:75153c8d2ef0 58 IGBT=1;
tony63 2:75153c8d2ef0 59 wait_ms(p2);
tony63 2:75153c8d2ef0 60 IGBT=0;
tony63 3:f3e7caa1d402 61 }
tony63 2:75153c8d2ef0 62
tony63 2:75153c8d2ef0 63 //..............................INICIA EL PROGRAMA.......................................................
tony63 2:75153c8d2ef0 64 int main()
tony63 2:75153c8d2ef0 65 {
tony63 2:75153c8d2ef0 66 //...............PANTALLA INICIAL...........................................
tony63 3:f3e7caa1d402 67
tony63 2:75153c8d2ef0 68 button.fall(&flip);
tony63 2:75153c8d2ef0 69 IGBT1=0; //apaga el igbt de carga
tony63 2:75153c8d2ef0 70 lcd.cls();
tony63 2:75153c8d2ef0 71 lcd.locate(3,0); //se posiciona en col 3 y fila 0
tony63 2:75153c8d2ef0 72 lcd.printf("SPOT WELDER"); //primer mensaje
tony63 2:75153c8d2ef0 73 lcd.locate(3,1); //se posiciona en col 3 y fila 0
tony63 2:75153c8d2ef0 74 lcd.printf("DUAL PULSE"); //primer mensaje
tony63 2:75153c8d2ef0 75 wait(3); //espera 3 seg
tony63 3:f3e7caa1d402 76
tony63 2:75153c8d2ef0 77 lcd.cls(); //borra pantalla
tony63 2:75153c8d2ef0 78 lcd.locate(0,0); //se posiciona en col 8 y fila 0
tony63 2:75153c8d2ef0 79 lcd.printf("P1="); //se marca una variable
tony63 2:75153c8d2ef0 80 lcd.locate(8,0); //se posiciona 0,1
tony63 2:75153c8d2ef0 81 lcd.printf("P2="); //se marca una variable
tony63 2:75153c8d2ef0 82 lcd.locate(0,1); //se posiciona en 8,1
tony63 2:75153c8d2ef0 83 lcd.printf("Esp="); //se marca una variable
tony63 2:75153c8d2ef0 84 lcd.setCursor(TextLCD::CurOff_BlkOn); //se configura el cursor LCD parpadeante.
tony63 2:75153c8d2ef0 85
tony63 2:75153c8d2ef0 86 //..............................FIN PANTALLA INICIAL.....................................
tony63 2:75153c8d2ef0 87 //.............programa ciclico..........................................................
tony63 2:75153c8d2ef0 88 while(1){
tony63 2:75153c8d2ef0 89 if(i==0){
tony63 2:75153c8d2ef0 90 lcd.locate(3,0);
tony63 3:f3e7caa1d402 91 lcd.printf(" ");
tony63 3:f3e7caa1d402 92 p1=p1+wheel.getPulses();
tony63 2:75153c8d2ef0 93 if(p1<0){
tony63 2:75153c8d2ef0 94 p1=0;
hudakz 0:271d74b09d64 95 }
tony63 3:f3e7caa1d402 96 if(p1>999){
tony63 3:f3e7caa1d402 97 p1=999;
tony63 3:f3e7caa1d402 98 }
tony63 2:75153c8d2ef0 99 lcd.locate(3,0);
tony63 2:75153c8d2ef0 100 lcd.printf("%d",p1);
tony63 3:f3e7caa1d402 101 wheel.reset();
tony63 3:f3e7caa1d402 102 wait_ms(5);
tony63 3:f3e7caa1d402 103 if(fire==0){
tony63 3:f3e7caa1d402 104 weld();
tony63 3:f3e7caa1d402 105 }
hudakz 0:271d74b09d64 106
tony63 2:75153c8d2ef0 107 }
tony63 2:75153c8d2ef0 108 if(i==1){
tony63 2:75153c8d2ef0 109 lcd.locate(11,0);
tony63 3:f3e7caa1d402 110 lcd.printf(" ");
tony63 3:f3e7caa1d402 111 p2=p2+wheel.getPulses();
tony63 2:75153c8d2ef0 112 if(p2<0){
tony63 2:75153c8d2ef0 113 p2=0;
tony63 2:75153c8d2ef0 114 }
tony63 3:f3e7caa1d402 115 if(p2>999){
tony63 3:f3e7caa1d402 116 p2=999;
tony63 3:f3e7caa1d402 117 }
tony63 2:75153c8d2ef0 118 lcd.locate(11,0);
tony63 2:75153c8d2ef0 119 lcd.printf("%d",p2);
tony63 3:f3e7caa1d402 120 wheel.reset();
tony63 3:f3e7caa1d402 121 wait_ms(5);
tony63 3:f3e7caa1d402 122 if(fire==0){
tony63 3:f3e7caa1d402 123 weld();
tony63 3:f3e7caa1d402 124 }
tony63 2:75153c8d2ef0 125 }
tony63 2:75153c8d2ef0 126 if(i==2){
tony63 2:75153c8d2ef0 127 lcd.locate(4,1);
tony63 3:f3e7caa1d402 128 lcd.printf(" ");
tony63 3:f3e7caa1d402 129 espera=espera+wheel.getPulses();
tony63 2:75153c8d2ef0 130 if(espera<0){
tony63 2:75153c8d2ef0 131 espera=0;
tony63 2:75153c8d2ef0 132 }
tony63 3:f3e7caa1d402 133 if(espera>999){
tony63 3:f3e7caa1d402 134 espera=999;
tony63 3:f3e7caa1d402 135 }
tony63 2:75153c8d2ef0 136 lcd.locate(4,1);
tony63 2:75153c8d2ef0 137 lcd.printf("%d",espera);
tony63 3:f3e7caa1d402 138 wheel.reset();
tony63 3:f3e7caa1d402 139 wait_ms(5);
tony63 3:f3e7caa1d402 140 if(fire==0){
tony63 3:f3e7caa1d402 141 weld();
tony63 3:f3e7caa1d402 142 }
hudakz 0:271d74b09d64 143
tony63 2:75153c8d2ef0 144 }
tony63 2:75153c8d2ef0 145 if(fire==0){
tony63 2:75153c8d2ef0 146 weld();
tony63 3:f3e7caa1d402 147 }
tony63 3:f3e7caa1d402 148 /*
tony63 3:f3e7caa1d402 149 lcd.cls();
tony63 2:75153c8d2ef0 150 lcd.printf("WELD-OK");
tony63 3:f3e7caa1d402 151 wait(3);
tony63 3:f3e7caa1d402 152 goto inicio;
tony63 3:f3e7caa1d402 153 */
tony63 3:f3e7caa1d402 154
tony63 2:75153c8d2ef0 155 }//while
tony63 2:75153c8d2ef0 156 }//main