Autor Tema: ¿Driver o libreria max6675?  (Leído 4919 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Desconectado Thulsa Doom

  • PIC24F
  • *****
  • Mensajes: 771
    • https://electronicadicto.wordpress.com/
¿Driver o libreria max6675?
« en: 02 de Julio de 2010, 21:33:10 »
Hola a todos, estoy intentando desarrollar un control de temperatura utilizando un max6675 y estoy buscando el driver o librería para ese componente para el compilador CCS C.

Ruego me disculpen si la petición pueda ofender a alguien de la manera que la he expuesto.

un saludo y gracias
« Última modificación: 03 de Julio de 2010, 07:32:51 por Thulsa Doom »
Más códigos y desarrollos en https://electronicadicto.wordpress.com/ date una vuelta y curiosea un rato...

Desconectado danfa42

  • PIC10
  • *
  • Mensajes: 4
Re: ¿Driver o libreria max6675?
« Respuesta #1 en: 27 de Marzo de 2011, 17:53:13 »
Hola llego medio tarde con la respuesta, pero estoy en el mismo tema y encontre en el foro de ccs la siguiente libreria
/**************************************************************************************
*   max6675.c - communicates with a MAX6675 thermcouple interface chip                *
*   Copyright Jimbob's Ma 2006                                                        *
*                                                                                     *
*   This program is free software; you can redistribute it and/or                     *
*   modify it under the terms of the GNU General Public License                       *
*   as published by the Free Software Foundation version 2                            *
*   of the License.                                                                   *
*                                                                                     *
*   This program is distributed in the hope that it will be useful,                   *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of                    *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                     *
*   GNU General Public License for more details.                                      *
*                                                                                     *
*   You should have received a copy of the GNU General Public License                 *
*   along with this program; if not, write to the Free Software                       *
*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.   *
**************************************************************************************/

/*
This is a diver for the MAX6675 K-type thermocouple interface chip. It implements an SPI
bus without the need for dedicated hardware (aka a bit-banged interface). The result from
toFloat_TC() is the temperature in degrees celcius of the thermocouple tip. The rest should
be self-evident. Have a look at the end of the file for example usage.
*/

#ifndef TC_CLK
   #define TC_CLK               PIN_B1            //edit these pins as necessary
#endif

#ifndef TC_CS
   #define TC_CS               PIN_B2
#endif

#ifndef TC_DATA
   #define TC_DATA               PIN_B3
#endif


int1 thermocouple_error;         //a handy dandy global error flag to tell you if a thermocouple is connected or not

void init_TC(void)
{
   output_low(TC_CLK);
   output_low(TC_DATA);
   output_high(TC_CS);            //if we idle high, the chip keeps doing conversions. Change this if you like
}

int16 read_TC(void)               //It takes 200ms (ish) for the MAX6675 to perform a conversion
{
   int8 i;
   int16 data;

   output_low(TC_CS);            //stop any conversion processes
   delay_us(1);               //and give it some time to power up (not very much, admittedly)

   for (i=0;i<16;i++){
      shift_left(&data,2,input(TC_DATA));      //reads in 2 bytes to data from the pin TC_DATA
      output_high(TC_CLK);
      output_low(TC_CLK);
   }

   thermocouple_error=bit_test(data,2);      //this is the thermocouple status bit
       
   output_high(TC_CS);
   return(data);
}

int16 sortout(int16 raw)
{
    return(0x0FFF & (raw>>3));      //returns only the bits converning temperature
}

float toFloat_TC(int16 tmp)
{
   return((float)tmp/4.0);      //adjusts data to floating point format, and accounts for the decimal point
}

float do_everything(void)
{
   init_TC();
   delay_ms(200);               //200ms is a long time to be doing nothing. use a timer interrupt to avoid wasting time here
   return(toFloat_TC(sortout(read_TC())));
}


/*

//example program

#define TC_CLK               PIN_B2
#define TC_CS               PIN_B2
#define TC_DATA               PIN_B1

#include "max6675.c"

void main()
{
   char msg[32];
   delay_ms(50);      //allow oscillator to stabilise

   while(1){
      delay_ms(800);
      sprintf(msg,"%01.2f%cC\r\n",do_everything(),0xB0);
       
      if(thermocouple_error)
         printf("Thermocouple not connected\r\n");   
      else
         printf("%s",msg);
   }
}

*/


Espero te sea util siaún no la conseguiste. Un abrazo

Desconectado Thulsa Doom

  • PIC24F
  • *****
  • Mensajes: 771
    • https://electronicadicto.wordpress.com/
Re: ¿Driver o libreria max6675?
« Respuesta #2 en: 23 de Abril de 2011, 13:17:29 »
Pues yo llego más tarde que tú,
ese driver no vale.
la razón es que si te fijas en el datasheet del max6675, dice que la lectura la hace por el protocolo SPI y el dato del max es una palabra de 16 bit,
Si implementamos el protocolo SPI por hardware, solo permite capturar datos en cadenas de 8bits (1bite), con lo que tendremos que leer dos veces seguidas en el puerto del protocolo para poder tener los 16bits de esta manera:

output_low(PIN_A1);
valor1=spi_read();
valor2=spi_read();
output_high(PIN_A1);
delay(200ms);

donde valor1 es la variable donde se guarda los primeros 8 bits de la palabra y valos2 es la variable donde se guardan los segundos 8 bits

en el código que pones, no respeta nada de eso y si lo pruebas no te funcionará (lo he probado  :))
Más códigos y desarrollos en https://electronicadicto.wordpress.com/ date una vuelta y curiosea un rato...


 

anything