TODOPIC

Microcontroladores PIC => Todo en microcontroladores PIC => Mensaje iniciado por: elmonje en 31 de Enero de 2013, 10:42:45

Título: Placa MC GSM. Problema envio de temperatura
Publicado por: elmonje en 31 de Enero de 2013, 10:42:45
Hola
Hace un tiempo atras compre un kit GSM a mcelectronics, la cual contiene un pic 18f14k50 y un sim900. A esta altura ya es claro que la gente de mcelectronics no responde a mis pedidos de auxilio. Leyendo el foro veo que esta es una situacion normal. Pero mas alla de mis quejas y arrepentimientos, quiero hacerles unas consultas.
Dentro de todo lo que vengo rescatando, arme un programa en C, para medir dos temperaturas y luego enviarlas por mje de texto a un celular cualquiera. El codigo es el siguiente:
Código: C
  1. [/
  2.  
  3. #include "GSM.h"
  4. #define PIN_ON  output_high
  5. #define PIN_OFF output_low
  6. #define RELAY1  PIN_C0
  7. #define RELAY2  PIN_C1
  8. #define PULSADOR1  PIN_C2
  9. #define PULSADOR2  PIN_C3
  10. #define PULSADOR3  PIN_B6
  11. #define PWM_LED  PIN_C5
  12. #define LED1  PIN_C6
  13. #define LED2  PIN_C7
  14. #define TEMP1 PIN_B4
  15. #define TEMP2 PIN_C0
  16.  
  17. #define POWERKEYGSM  PIN_C4
  18. #define TEMP_ADCC0  4
  19. #define TEMP_ADCB4  10
  20.  
  21.   //*************************************************************************************************************************************
  22. //--------------------------------------variables globales
  23. //*************************************************************************************************************************************
  24.  
  25. long lm35, temperature;
  26. float volt_lm35, g_lm35, volt_temp, grados;
  27. char string_g_y[20], string_temp[20];
  28.  
  29. //*************************************************************************************************************************************
  30. //--------------------------------------FUNCIONES
  31. //*************************************************************************************************************************************
  32.  
  33. float conver_volt(long adc);
  34. float conver_lm35(float lm35);
  35. float conver_grados(float volt_adc);
  36.  
  37. void inicializacionSIM900(void)
  38. {
  39.    int cont;
  40.    delay_ms(1000);
  41.    puts("A",SERIAL_SIM900); //para sincronizar el baudrate del SIM 900
  42.    delay_ms(300);
  43.    putchar(0x0d,SERIAL_SIM900);
  44.    delay_ms(1000);
  45.    for(cont=0;cont<5;cont++)              // mando varios AT para el autobauding
  46.          {
  47.          puts("AT",SERIAL_SIM900);
  48.          delay_ms(200);
  49.          putchar(0x0d,SERIAL_SIM900);
  50.          delay_ms(200);
  51.          PIN_ON(LED1);
  52.          delay_ms(200);
  53.          PIN_OFF(LED1);
  54.          }
  55. //-----------------------------------seteos de configuracion del SIM900------------------------
  56.    puts("AT+CMGF=1\r",SERIAL_SIM900);                  // configuro para que trabaje en modo texto y no PDU
  57.    delay_ms(200);
  58.    putchar(0x0d,SERIAL_SIM900);
  59.    delay_ms(200);
  60.    puts("AT+CNMI=2,2,0,0,0\r",SERIAL_SIM900);                  // configuro para que en cuanto llegue un mensaje lo envie el modulo gsm por el puerto serie
  61.    delay_ms(200);
  62.    putchar(0x0d,SERIAL_SIM900);
  63.    delay_ms(200);
  64.    puts("ATS0=1\r",SERIAL_SIM900);                  // configuro para que atienda en el segundo llamado
  65.    delay_ms(200);
  66.    putchar(0x0d,SERIAL_SIM900);
  67.    delay_ms(200);
  68.    return;
  69. }
  70.  
  71. void main() {
  72.    set_tris_b(0b00001100);  //0b00001100
  73.    set_tris_c(0b01110001); //SEGUN LA TEORIA RC0-RC3
  74.    PIN_OFF(RELAY1);
  75.    PIN_OFF(RELAY2);
  76.    PIN_OFF(LED1);
  77.    PIN_OFF(LED2);
  78.    PIN_OFF(POWERKEYGSM);    //Enciendo modulo GSM
  79.    delay_ms(1200);
  80.    PIN_ON(POWERKEYGSM);
  81.    inicializacionSIM900();     //Inicializo el SIM900
  82.    setup_adc_ports(sAN4|sAN10|VSS_VDD);
  83.    setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);
  84.    setup_wdt(WDT_OFF);
  85.    setup_vref(FALSE);
  86.    
  87.  
  88.  
  89.  
  90.   while (true)                   // bucle infinito
  91.    {
  92.          set_adc_channel(TEMP_ADCC0);
  93.          delay_ms(1);
  94.          lm35=read_adc();
  95.          set_adc_channel(TEMP_ADCB4);
  96.          delay_ms(1);
  97.          temperature=read_adc();
  98.  
  99.          //Convertir datos:
  100.  
  101.          volt_lm35=conver_volt(lm35);
  102.          g_lm35=conver_lm35(volt_lm35);
  103.          
  104.          volt_temp=conver_volt(temperature);
  105.          grados=conver_grados(volt_temp);
  106.  
  107.          if(input(PULSADOR1)==0)
  108.          {
  109.             PIN_ON(LED1);
  110.             while(input(PULSADOR1)==0);
  111.             PIN_OFF(LED1);
  112.          }
  113.  
  114.          if(input(PULSADOR3)==0)
  115.          {
  116.             PIN_ON(LED2);
  117.             while(input(PULSADOR3)==0);
  118.             PIN_OFF(LED2);
  119.          }
  120.  
  121.          if(input(PULSADOR2)==0)                                  // Si presiono el boton manda un SMS
  122.          {
  123.             sprintf(string_g_y,"T2=%1.1f GRADOS   ",g_lm35);
  124.             sprintf(string_temp,"Temp1=%1.1f GRADOS  ",grados);
  125.             fprintf(SERIAL_SIM900,"AT+CMGS=\"154048xxx\"\r"); // aca poner el numero de celular que recibe el SMS
  126.             delay_ms(200);
  127.             fprintf(SERIAL_SIM900,"    ELECTRO HPN \r");
  128.             fputs(string_g_y,SERIAL_SIM900);
  129.             fputs(string_temp,SERIAL_SIM900);
  130.             delay_ms(100);
  131.             fprintf(SERIAL_SIM900,"%c",0x1a);
  132.             output_high(LED2);
  133.             delay_ms(1000);
  134.             output_low(LED2);
  135.          }
  136.  
  137.    }
  138.  
  139. }
  140.  
  141.  
  142. float conver_volt(long adc)
  143. {
  144.    float volt;
  145.    volt=(float)((adc/1024.0)*3.3);
  146.    return(volt);
  147. }
  148.  
  149. float conver_lm35(float lm35)
  150. {
  151.    float value;
  152.    value=(float)((lm35)/0.01);
  153.    return(value);
  154. }
  155.  
  156. float conver_grados(float volt_adc)
  157. {
  158.    float grados;
  159.    grados=(float)((volt_adc-0.5)/0.01);
  160.    return(grados);
  161. }]
  162. [code=c]
El archivo GSM.h es:
Código: C
  1. [/
  2. #include <18F14K50.h>
  3. #device adc=10
  4.  
  5. #FUSES NOWDT                    //No Watch Dog Timer
  6. #FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
  7. #FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
  8. #FUSES FCMEN                    //Fail-safe clock monitor enabled
  9. #FUSES NOBROWNOUT               //No brownout reset
  10. #FUSES BORV19                
  11. #FUSES NOPUT                    //No Power Up Timer
  12. //#FUSES NOCPD                    //No EE protection
  13. #FUSES STVREN                   //Stack full/underflow will cause reset
  14. #FUSES NODEBUG                  //No Debug mode for ICD
  15. #FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
  16. //#FUSES NOWRT                    //Program memory not write protected
  17. #FUSES NOWRTD                   //Data EEPROM not write protected
  18. #FUSES NOWRTC                   //configuration not registers write protected
  19. #FUSES IESO                     //Internal External Switch Over mode enabled
  20. #FUSES NOEBTR                   //Memory not protected from table reads
  21. #FUSES NOEBTRB                  //Boot block not protected from table reads
  22. #FUSES MCLR                     //Master Clear pin enabled
  23. //#FUSES NOPROTECT                //Code not protected from reading
  24. #FUSES NOCPB                    //No Boot Block code protection
  25. #FUSES NOWRTB                   //Boot block not write protected
  26. #FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
  27. #FUSES HFOFST                
  28. #FUSES NOWRT0                
  29. #FUSES NOWRT1                
  30. #FUSES USBDIV1              
  31. #FUSES BBSIZ2K                  //2K words Boot Block size
  32. #FUSES PLLEN                
  33. #FUSES CPUDIV4                  //System Clock by 4
  34. #FUSES PCLKEN                
  35.  
  36. #use delay(clock=12000000)
  37.  
  38. #use rs232(baud=9600,parity=N,xmit=PIN_B7,rcv=PIN_B5,bits=8,stream=SERIAL_SIM900)
  39. ]
  40. [code=c]
La placa tiene un sensor TC1047 en RB4 (AN10), y le conecté un LM35 en RC0(AN4); El TC1047 lo lee bien, y da un valor coherente, el LM35 no. Pero lo peor de todo es que si SUBO la temperatura de los sensores...estos decrementan el valor enviado por sms en lugar de incrementarlos.
Alguien me puede dar una mano? ya que a pesar de hice un curso online por mcelectronics no han respondido a mis consultas. Son obvias las disculpas por mi conocimiento basico. Muchas gracias.[/code][/code]
Título: Re: Placa MC GSM. Problema envio de temperatura
Publicado por: Suky en 31 de Enero de 2013, 11:15:16
Porque restas 0.5 ? Si la conexión es directa, según recuerdo, al tener 100 ºC la tensión de salida del LM35 sera ~1 V.


Saludos!
Título: Re: Placa MC GSM. Problema envio de temperatura
Publicado por: elmonje en 31 de Enero de 2013, 11:54:34
Porque restas 0.5 ? Si la conexión es directa, según recuerdo, al tener 100 ºC la tensión de salida del LM35 sera ~1 V.


Saludos!

Hola. Le quite el 0,5.  Igual el problema del "sentido" de variacion de la temperatura se mantiene.. Muchas gracias