Bem-vindo, Visitante
Nome do utilizador: Senha: Memorizar
Eletronica Digital, Microcontroladores, Robótica e Automação

TÓPICO: Ajuda - mV para Fahrenheit

Ajuda - mV para Fahrenheit 20 Out. 2017 23:49 #1

Eae galera,estou tendo dificuldades no programa abaixo. Ele é um sistema de controle de temperatura com LM35 e o PIC18F4520, basicamente o que ele faz é registrar uma temperatura referência que é digitada a partir do KEYPAD e então manipula a lampada e o cooler para que a temperatura do ambiente atinja essa temperatura referência. O programa em si já funciona, o que queria saber é como converter a temperatura e os mV de Celsius para temperatura e mV de Fahrenheit.

Sendo mais especifico está nesta parte do código:
mV = temp * 5000.0/1024.0;       
     ActualTemp = mV/10.0 ;

O código por completo caso queiram analisar,etc...
// Keypad module connections
char  keypadPort at PORTD;
// End Keypad module connections

#include <built_in.h>

// LCD conexões no módulo
sbit LCD_RS at RC0_bit;
sbit LCD_EN at RC1_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;


sbit LCD_RS_Direction at TRISC0_bit;
sbit LCD_EN_Direction at TRISC1_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;


#define HEATER PORTC.RC2
#define FAN PORTC.RC3
#define ENTER 15
#define CLEAR 13
#define ON 1
#define OFF 0
#define BUZZER PORTB.RB0




 void buzzer()
 {
  Sound_Play(1000, 500);
  }


void main() {



  unsigned short kp,Txt[14];
  unsigned short Temp_Ref ;      //  Reference Temperature
  unsigned char inTemp;
  unsigned int temp, ANSELC, ANSELB, ANSELD;
  float mV, ActualTemp;

   if (Button(&PORTE,3,10,0)){
buzzer();
Sound_Init(&PORTB, 0);
  PORTB.F0 = 1;
}
if (Button(&PORTE,3,10,0))      
{
buzzer();                      
}
HEATER = OFF;
  FAN = OFF;

  Keypad_Init();                           // Initialize Keypad
  ANSELC = 0;                              // Configure PORTC as digital I/O
  ANSELB = 0;                              // Configure PORTB as digital I/O
  ANSELD = 0;                              // Configure PORTD as digital I/O
  TRISA0_bit = 1;                          //Configure AN0 (RA0) as input
  TRISC = 0;                               //PORTC are outputs (LCD)
  TRISD0_bit=0;                            //RD0 is output (Heater)
  TRISD1_bit=0;                            //RD1 is output (Fan)

  Lcd_Init();                              // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                     // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);                // Cursor off
  Lcd_Out(1, 5, "Iniciando...");
  Lcd_Out(2, 2, "Sistema de Controle de temperatura");
  Lcd_Out(3, 5, "com LM 35");
  Lcd_Out(4, 2, "...");
  delay_ms(1000);                          //2s delay

  HEATER = OFF;
  FAN = OFF;




  //ON startup, read the Referance Temperature from the Keypad
        START:
        HEATER = OFF;
  FAN = OFF;
       Lcd_Cmd(_LCD_CLEAR);                     // Clear display
       Lcd_Out(1, 1, "Digite a temperatura");
       Temp_Ref=0;
        Lcd_Out(3, 1, "Temp.Ref: ");
        while(1)
        {

         do
         kp = Keypad_Key_Click();             // Store key code in kp variable
         while (!kp);
         if ( kp == ENTER )break;
         if (kp > 3 && kp < 8) kp = kp-1;
         if (kp > 8 && kp < 12) kp = kp-2;
         if (kp ==14)kp = 0;
         if ( kp == CLEAR )goto START;
         Lcd_Chr_Cp(kp + '0');
         Temp_Ref =(10*Temp_Ref) + kp;


       }
      Lcd_Cmd(_LCD_CLEAR);                     // Clear display
      Lcd_Out(1, 1, "Temp. Ref: ");
      intToStr( Temp_Ref,Txt);         //Convert to String
      inTemp=Ltrim(Txt);
       Lcd_Out_CP(inTemp);                  //Display Ref Temp
      Lcd_Out(3, 1, "Press. Enter p/ continuar");
      //Wait until # is pressed
      kp =0;
      if (Temp_Ref >75 )  //If Temp Ref is equal to actual Temp, Switch OFF Fan and Heater
      {
     Lcd_Out(3, 1, "Temp. Invalida (+)");
     delay_ms(2000);
     kp == CLEAR;
     goto START;
      }
       if (Temp_Ref < 15 )  //If Temp Ref is equal to actual Temp, Switch OFF Fan and Heater
      {
     Lcd_Out(3, 1, "Temp. Invalida (-)");
     delay_ms(2000);
     kp == CLEAR;
     goto START;
      }
      while(kp!=ENTER)
      {
         do
           kp = Keypad_Key_Click();             // Store key code in kp variable
         while(!kp);
      }
       Lcd_Cmd(_LCD_CLEAR);              // Clear display

   Lcd_Out(1, 1, "Temp. Ref : ");
   Lcd_Chr(1,15,223);                  // Different LCD displays have different
                                     //   char code for degree
  Lcd_Chr(1,16,'C');                  // Display "C" for Celsius
   //Program loop
  while(1) {
     //Display Referance Temperature and Actual Temperature
     temp = ADC_Read(0);               //Read temperature from AN0
     mV = temp * 5000.0/1024.0;        //Convert to mV
     ActualTemp = mV/10.0 ;              // Convert to degrees Celcius
     intToStr( Temp_Ref,Txt);         //Convert to String
     inTemp=Ltrim(Txt);
     //Lcd_Out(1, 1, "Temp Ref: ");
     Lcd_Out(1, 11, inTemp);        //Display Ref Temp
     Lcd_Out(3, 1, "Temp = ");
     FloatToStr(ActualTemp,Txt);         //Convert to string
     Txt[4] = 0;
     Lcd_Out(3,7,Txt);
     Lcd_Out(2,12,"   ");


      if (Temp_Ref >  ActualTemp)
      {
      HEATER = ON,
      FAN = OFF;
      }
       if (Temp_Ref <  ActualTemp)
      {
      HEATER = OFF,
      FAN = ON;
      }
      if (Temp_Ref ==  ActualTemp)
      {
      HEATER = OFF,
      FAN = OFF;
      }
      Delay_ms(5000);
  }
}

Ajuda - mV para Fahrenheit 21 Out. 2017 00:33 #2

  • Rui
  • Avatar de Rui
  • DESLIGADO
  • adminmembro há mais de 12 anos top5 em número de mensagens
  • pt  
  • Mensagens: 5187
  • Agradecimentos 864
A formula de conversão é de Celsius to Fahrenheit é:
T(°F) = T(°C) × 9/5 + 32

Então apenas temos de converter
ActualTemp = mV/10.0*9/5 + 32

Ajuda - mV para Fahrenheit 21 Out. 2017 15:59 #3

Eae galera, to aqui de novo pedindo ajuda com um mesmo trabalho que estou fazendo, o sistema de controle de temperatura. Estou tendo dificuldades para arrumar a programação do MikroC para que no LCD após a temperatura ser escolhida fique:

Temp. Ref. : (Temperatura Escolhida)

Mas no caso esta ficando:

Temp. Ref. : (Alguma parte aleatória da programação)

Como mostra a imagem abaixo:

https://uploaddeimagens.com.br/imagens/erroproteus-png

Código:
// Keypad module connections
char  keypadPort at PORTD;
// End Keypad module connections

#include <built_in.h>

// LCD conexões no módulo
sbit LCD_RS at RC0_bit;
sbit LCD_EN at RC1_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;


sbit LCD_RS_Direction at TRISC0_bit;
sbit LCD_EN_Direction at TRISC1_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;


#define HEATER PORTC.RC2
#define FAN PORTC.RC3
#define ENTER 15
#define CLEAR 13
#define ON 1
#define OFF 0
#define BUZZER PORTB.RB0




 void buzzer()
 {
  Sound_Play(1000, 500);
  }


void main() {



  unsigned short kp,Txt[14];
  unsigned short Temp_Ref, Modo1;      //  Reference Temperature
  unsigned char inTemp, inModo1;
  unsigned int temp, ANSELC, ANSELB, ANSELD;
  float mV, ActualTemp;

   if (Button(&PORTE,3,10,0)){
buzzer();
Sound_Init(&PORTB, 0);
  PORTB.F0 = 1;
}
if (Button(&PORTE,3,10,0))
{
buzzer();
}
HEATER = OFF;
  FAN = OFF;

  Keypad_Init();                           // Initialize Keypad
  ANSELC = 0;                              // Configure PORTC as digital I/O
  ANSELB = 0;                              // Configure PORTB as digital I/O
  ANSELD = 0;                              // Configure PORTD as digital I/O
  TRISA0_bit = 1;                          //Configure AN0 (RA0) as input
  TRISC = 0;                               //PORTC are outputs (LCD)
  TRISD0_bit=0;                            //RD0 is output (Heater)
  TRISD1_bit=0;                            //RD1 is output (Fan)

  Lcd_Init();                              // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                     // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);                // Cursor off
  Lcd_Out(1, 5, "Iniciando...");
  Lcd_Out(2, 2, "Sistema de Controle de temperatura");
  Lcd_Out(3, 5, "com LM 35");
  Lcd_Out(4, 2, "...");
  delay_ms(100);                          //2s delay
  Lcd_Cmd(_LCD_CLEAR);
  HEATER = OFF;
  FAN = OFF;


          START:
         Lcd_Cmd(_LCD_CLEAR);                     // Clear display
       Lcd_Out(1, 1, "Digite modo");
       Temp_Ref=0;
        Lcd_Out(3, 1, "Modo: ");
        while(1)
        {

         do
         kp = Keypad_Key_Click();             // Store key code in kp variable
         while (!kp);
         if ( kp == ENTER )break;

         if ( kp == 1 )kp=1;
            if ( kp == 2 )kp=2;
                if ( kp == 3 )kp=3;
                  if ( kp == 4 ){         //TEMPERATURA CELSIUS
                  
      kp=51;
      Lcd_Cmd(_LCD_CLEAR);                     // Clear display
      Lcd_Out(1, 1, "Modo: C ");
        kp =0;
      while(kp!=ENTER)
      {
      Lcd_Out(3, 1, "Press ENTER p/ cont.");
         do
           kp = Keypad_Key_Click();             // Store key code in kp variable
         while(!kp);


}

        Lcd_Cmd(_LCD_CLEAR);                     // Clear display
       Lcd_Out(1, 1, "Insira temp. ref.");
       Temp_Ref = 0;
        Lcd_Out(3, 1, "Temp Ref: ");
        while(1)
        {
         do
         kp = Keypad_Key_Click();             // Store key code in kp variable
         while (!kp);
         if ( kp == ENTER )break;
         if (kp > 3 && kp < 8) kp = kp-1;
         if (kp > 8 && kp < 12) kp = kp-2;
         if (kp ==14)kp = 0;
         if ( kp == CLEAR )goto START;
         Lcd_Chr_Cp(kp + '0');
         Temp_Ref =(10*Temp_Ref) + kp;
       }
      Lcd_Cmd(_LCD_CLEAR);  


      intToStr( Temp_Ref,Txt);         //Convert to String
      inTemp=Ltrim(Txt);
       Lcd_Out_CP(inTemp);                  //Display Ref Temp


   Lcd_Out(1, 1, "Temp Ref : ");
   Lcd_Chr(1,15,223);                  // Different LCD displays have different
                                     //   char code for degree
  Lcd_Chr(1,16,'C');                  // Display "C" for Celsius
   //Program loop
  while(1) {
     //Display Referance Temperature and Actual Temperature
     temp = ADC_Read(0);               //Read temperature from AN0
     mV = temp * 5000.0/1024.0;        //Convert to mV
     ActualTemp = mV/10.0 ;              // Convert to degrees Celcius
     intToStr( Temp_Ref,Txt);         //Convert to String
     inTemp=Ltrim(Txt);
     //Lcd_Out(1, 1, "Temp Ref: ");
     Lcd_Out(1, 11, inTemp);        //Display Ref Temp
     Lcd_Out(3, 1, "Temp = ");
     FloatToStr(ActualTemp,Txt);         //Convert to string
     Txt[4] = 0;
     Lcd_Out(3,7,Txt);
     Lcd_Out(3,12,"   ");

      //Compare ref temp with actual emp
      if (Temp_Ref >  ActualTemp)  //If Temp Ref is less than actual Temp, Switch ON Heater
      {
      HEATER = ON,
      FAN = OFF;
      }
       if (Temp_Ref < ActualTemp)  //If Temp Ref is greater than actual Temp, Switch ON Fan
      {
      HEATER = OFF,
      FAN = ON;
      }
      if (Temp_Ref ==  ActualTemp)  //If Temp Ref is equal to actual Temp, Switch OFF Fan and Heater
      {
      HEATER = OFF,
      FAN = OFF;
      }
      Delay_ms(100);        //Wait 10 s then repeat

}

             
             
             
             }
                   if ( kp == 5 )kp= 4;
                       if ( kp == 6 )kp=5;
                          if ( kp == 7 )kp=6;
                              if ( kp == 8 ) {
                              kp=54;
Lcd_Cmd(_LCD_CLEAR);                     // Clear display
      Lcd_Out(1, 1, "Modo: F ");
        kp =0;
      while(kp!=ENTER)
      {
      Lcd_Out(3, 1, "Press ENTER p/ cont.");
         do
           kp = Keypad_Key_Click();             // Store key code in kp variable
         while(!kp);


}

        Lcd_Cmd(_LCD_CLEAR);                     // Clear display
       Lcd_Out(1, 1, "Insira temp. ref.");
       Temp_Ref = 0;
        Lcd_Out(3, 1, "Temp Ref: ");
        while(1)
        {
         do
         kp = Keypad_Key_Click();             // Store key code in kp variable
         while (!kp);
         if ( kp == ENTER )break;
         if (kp > 3 && kp < 8) kp = kp-1;
         if (kp > 8 && kp < 12) kp = kp-2;
         if (kp ==14)kp = 0;
         if ( kp == CLEAR )goto START;
         Lcd_Chr_Cp(kp + '0');
         Temp_Ref =(10*Temp_Ref) + kp;
       }
      Lcd_Cmd(_LCD_CLEAR);                     // Clear display

      intToStr( Temp_Ref,Txt);         //Convert to String
      inTemp=Ltrim(Txt);
       Lcd_Out_CP(inTemp);  



   Lcd_Out(1, 1, "Temp Ref : ");
   Lcd_Chr(1,15,223);                  // Different LCD displays have different
                                     //   char code for degree
  Lcd_Chr(1,16,'F');                  // Display "C" for Celsius
   //Program loop
  while(1) {
     //Display Referance Temperature and Actual Temperature
     temp = ADC_Read(0);               //Read temperature from AN0
     mV = temp * 5000.0/1024.0;        //Convert to mV
     ActualTemp = mV/10.0 ;              // Convert to degrees Celcius
     intToStr( Temp_Ref,Txt);         //Convert to String
     inTemp=Ltrim(Txt);
     //Lcd_Out(1, 1, "Temp Ref: ");
     Lcd_Out(1, 11, inTemp);        //Display Ref Temp
     Lcd_Out(3, 1, "Temp = ");
     FloatToStr(ActualTemp,Txt);         //Convert to string
     Txt[4] = 0;
     Lcd_Out(3,7,Txt);
     Lcd_Out(3,12,"   ");

      //Compare ref temp with actual emp
      if (Temp_Ref >  ActualTemp)  //If Temp Ref is less than actual Temp, Switch ON Heater
      {
      HEATER = ON,
      FAN = OFF;
      }
       if (Temp_Ref < ActualTemp)  //If Temp Ref is greater than actual Temp, Switch ON Fan
      {
      HEATER = OFF,
      FAN = ON;
      }
      if (Temp_Ref ==  ActualTemp)  //If Temp Ref is equal to actual Temp, Switch OFF Fan and Heater
      {
      HEATER = OFF,
      FAN = OFF;
      }
      Delay_ms(100);        //Wait 10 s then repeat
}
}
                                 if ( kp == 9 )kp=7;
                                     if ( kp == 10 )kp=8;
                                        if ( kp == 11 )kp=9;
                                            if ( kp == 12 ){
                                            
                                            kp=59;
     //TEMPERATURA CELSIUS

      kp=51;
      Lcd_Cmd(_LCD_CLEAR);                     // Clear display
      Lcd_Out(1, 1, "Modo: K ");
        kp =0;
      while(kp!=ENTER)
      {
      Lcd_Out(3, 1, "Press ENTER p/ cont.");
         do
           kp = Keypad_Key_Click();             // Store key code in kp variable
         while(!kp);


}

        Lcd_Cmd(_LCD_CLEAR);                     // Clear display
       Lcd_Out(1, 1, "Insira temp. ref.");
       Temp_Ref = 0;
        Lcd_Out(3, 1, "Temp Ref: ");
        while(1)
        {
         do
         kp = Keypad_Key_Click();             // Store key code in kp variable
         while (!kp);
         if ( kp == ENTER )break;
         if (kp > 3 && kp < 8) kp = kp-1;
         if (kp > 8 && kp < 12) kp = kp-2;
         if (kp ==14)kp = 0;
         if ( kp == CLEAR )goto START;
         Lcd_Chr_Cp(kp + '0');
         Temp_Ref =(10*Temp_Ref) + kp;
       }
      Lcd_Cmd(_LCD_CLEAR);                     // Clear display

      intToStr( Temp_Ref,Txt);         //Convert to String
      inTemp=Ltrim(Txt);
       Lcd_Out_CP(inTemp);  



   Lcd_Out(1, 1, "Temp Ref : ");
   Lcd_Chr(1,15,223);                  // Different LCD displays have different
                                     //   char code for degree
  Lcd_Chr(1,16,'K');                  // Display "C" for Celsius
   //Program loop
  while(1) {
     //Display Referance Temperature and Actual Temperature
     temp = ADC_Read(0);               //Read temperature from AN0
     mV = temp * 5000.0/1024.0;        //Convert to mV
     ActualTemp = mV/10.0 ;              // Convert to degrees Celcius
     intToStr( Temp_Ref,Txt);         //Convert to String
     inTemp=Ltrim(Txt);
     //Lcd_Out(1, 1, "Temp Ref: ");
     Lcd_Out(1, 11, inTemp);        //Display Ref Temp
     Lcd_Out(3, 1, "Temp = ");
     FloatToStr(ActualTemp,Txt);         //Convert to string
     Txt[4] = 0;
     Lcd_Out(3,7,Txt);
     Lcd_Out(3,12,"   ");

      //Compare ref temp with actual emp
      if (Temp_Ref >  ActualTemp)  //If Temp Ref is less than actual Temp, Switch ON Heater
      {
      HEATER = ON,
      FAN = OFF;
      }
       if (Temp_Ref < ActualTemp)  //If Temp Ref is greater than actual Temp, Switch ON Fan
      {
      HEATER = OFF,
      FAN = ON;
      }
      if (Temp_Ref ==  ActualTemp)  //If Temp Ref is equal to actual Temp, Switch OFF Fan and Heater
      {
      HEATER = OFF,
      FAN = OFF;
      }
      Delay_ms(100);        //Wait 10 s then repeat
} 
}                                                 if ( kp == 14 )kp=0;
                                                       if ( kp == 16 )kp=30;
         

         if ( kp == CLEAR )goto START;
         Lcd_Chr_Cp(kp + '0');
       }
}

Alguma ideia de como consertar?
Última Edição: 21 Out. 2017 16:01 por Júlio Cesar R..

Ajuda - mV para Fahrenheit 21 Out. 2017 16:44 #4

  • zurca1599
  • Avatar de zurca1599
  • DESLIGADO
  • membro com conhecimentos técnicos de electronicamembro há mais de 10 anos top5 em número de mensagens
  • pt  
  • Mensagens: 5833
  • Agradecimentos 1941

Ajuda - mV para Fahrenheit 21 Out. 2017 17:26 #5

Devo apagar este tópico e postar no outro então?

Ajuda - mV para Fahrenheit 21 Out. 2017 20:41 #6

  • zurca1599
  • Avatar de zurca1599
  • DESLIGADO
  • membro com conhecimentos técnicos de electronicamembro há mais de 10 anos top5 em número de mensagens
  • pt  
  • Mensagens: 5833
  • Agradecimentos 1941
Parece-me melhor usar só um tópico, pois ter vários tópicos com o mesmo assunto, só vai complicar.
O Rui vai tratar disso com certeza.

Pesquisar Esquemas | Dicas Defeito - Avarias | Equivalência Componentes | Modelo v Chassis | Service Mode |