Autor Tema: Problemas con un DS18B20  (Leído 5336 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado The_Chosen

  • PIC12
  • **
  • Mensajes: 51
Problemas con un DS18B20
« en: 16 de Abril de 2010, 19:36:51 »
Hola amigos, estoy haciendo una librería 1Wire para un atmega16 y tengo un 90% de la librería terminada, ya tengo la mayoría de las instrucciones comunes implementadas. Para probarla he estado usando un Ds18B20, un sensor maravilloso que tiene una gran resolución y exactitud. Sin embargo he estado chocando con algo. Este sensor se alimenta de dos maneras: a través de su PIN Vcc, típico de todos los integrados; y en forma parásita. Para los que no lo saben los sensores 1Wire se alimentan recolectando carga con un condensador que tienen en su interior, así cada vez que mandamos una instrucción este condensador se carga permitiendo que el dispositivo 1 wire responda sin estar conectado permanentemente a una fuente de energía.
Ahora, mi problema es que al alimentarlo en modo parásito, en el momento de enviarle la instrucción de conversión de temperatura para luego consultar el registro de temperatura, lo único que encuentro son 85°C  :D, siendo que cuando lo estoy alimentando a través de su pin Vcc la conversión resulta y me sale por ejemplo 25,0675 °C que sería la temperatura ambiental de mi habitación.

Ojalá puedan ayudarme con buenas ideas  :mrgreen:

Desconectado The_Chosen

  • PIC12
  • **
  • Mensajes: 51
Re: Problemas con un DS18B20
« Respuesta #1 en: 18 de Abril de 2010, 18:28:53 »
Bueno, como nadie me ha respondido, pues me respondo sólo  :mrgreen:.
Sólo colocando un delay de 750 ms después de enviar la instrucción de conversión de temperatura solucionaba todo  :P.

Desconectado luresago

  • PIC10
  • *
  • Mensajes: 1
Re: Problemas con un DS18B20
« Respuesta #2 en: 07 de Diciembre de 2010, 05:01:32 »
Estaba buscando eso.

Pues estoy realizando físicamente un termometro digital con el DS18B20 y solo me marca 27.9ºC. Y ya no cambia.

Espero que agregando este retardo me sirva.

Gracias.

Desconectado blackburne44

  • PIC10
  • *
  • Mensajes: 13
Re: Problemas con un DS18B20
« Respuesta #3 en: 05 de Noviembre de 2011, 19:49:31 »
Hola amigo. A mi me pasa lo mismo cuando lo hago en forma practica (me marca 85 °C, pero no probe alimentandolo con Vcc). Cuando lo simulo me anda perfecto!!! Estoy utilizando este codigo, no sabrias que tendria que cambiar?:

1wire:

Citar
// (C) copyright 2003 j.d.sandoz / jds-pic !at! losdos.dyndns.org

// released under the GNU GENERAL PUBLIC LICENSE (GPL)
// refer to http://www.gnu.org/licenses/gpl.txt

// 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; either version 2 of the License, or
// (at your option) any later version.

// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

/***********************1Wire Class***********************/
/*Description: This class handles all communication */
/* between the processor and the 1wire */
/* sensors.
/*********************************************************/

/*-------1-wire definitions-------*/
#define ONE_WIRE_PIN PIN_C2

/*******************1-wire communication functions********************/

/************onewire_reset*************************************************/
/*This function initiates the 1wire bus */
/* */
/*PARAMETERS: */
/*RETURNS: */
/*********************************************************************/

void onewire_reset()  // OK if just using a single permanently connected device
{
 output_low(ONE_WIRE_PIN);
 delay_us( 750 ); // pull 1-wire low for reset pulse
 output_float(ONE_WIRE_PIN); // float 1-wire high
 delay_us( 750 ); // wait-out remaining initialisation window.
 output_float(ONE_WIRE_PIN);
}

/*********************** onewire_write() ********************************/
/*This function writes a byte to the sensor.*/
/* */
/*Parameters: byte - the byte to be written to the 1-wire */
/*Returns: */
/*********************************************************************/

void onewire_write(int data)
{
 int count;

 for (count=0; count<8; ++count)
 {
  output_low(ONE_WIRE_PIN);
  delay_us( 2 ); // pull 1-wire low to initiate write time-slot.
  output_bit(ONE_WIRE_PIN, shift_right(&data,1,0)); // set output bit on 1-wire
  delay_us( 60 ); // wait until end of write slot.
  output_float(ONE_WIRE_PIN); // set 1-wire high again,
  delay_us( 2 ); // for more than 1us minimum.
 }
}

/*********************** read1wire() *********************************/
/*This function reads the 8 -bit data via the 1-wire sensor. */
/* */
/*Parameters: */
/*Returns: 8-bit (1-byte) data from sensor */
/*********************************************************************/

int onewire_read()
{
 int count, data;

 for (count=0; count<8; ++count)
 {
  output_low(ONE_WIRE_PIN);
  delay_us( 2 ); // pull 1-wire low to initiate read time-slot.
  output_float(ONE_WIRE_PIN); // now let 1-wire float high,
  delay_us( 8 ); // let device state stabilise,
  shift_right(&data,1,input(ONE_WIRE_PIN)); // and load result.
  delay_us( 120 ); // wait until end of read slot.
 }

 return( data );
}

ds18b20:

Citar
float ds1820_read()
{
 int8 busy=0, temp1, temp2;
 signed int16 temp3;
 float result;

 onewire_reset();
 onewire_write(0xCC);
 onewire_write(0x44);

 while (busy == 0)
  busy = onewire_read();

 onewire_reset();
 onewire_write(0xCC);
 onewire_write(0xBE);
 temp1 = onewire_read();
 temp2 = onewire_read();
 temp3 = make16(temp2, temp1);
 
//result = (float) temp3 / 2.0;   //Calculation for DS18S20 with 0.5 deg C resolution
 result = (float) temp3 / 16.0;  //Calculation for DS18B20 with 0.1 deg C resolution
 
 delay_ms(750);
 return(result);
}


 

anything