Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LM35-->A/D Converter-->PIC 16F628

Status
Not open for further replies.

Pappee

New Member
Hi All!
I woluld like to connect (for example) an LM35 Thermo sensor to a PIC during an A/D converter. Can somebody tell me what kind of A/D converter could I use? Have sombody experience in this?How does PIC process the converted analog sign?
I have a circuit from a Czech web site(**broken link removed**), but the author did use a very-very expensive termistor, what includes A/D converter(SMT160-30).I tought that change it a simple thermistor & a cheap A/D converter. I get any help with pleasure!

http:\\attilapapp.uw.hu
 
Pappee said:
Hi All!
I woluld like to connect (for example) an LM35 Thermo sensor to a PIC during an A/D converter. Can somebody tell me what kind of A/D converter could I use? Have sombody experience in this?How does PIC process the converted analog sign?
I have a circuit from a Czech web site(**broken link removed**), but the author did use a very-very expensive termistor, what includes A/D converter(SMT160-30).I tought that change it a simple thermistor & a cheap A/D converter. I get any help with pleasure!

Far easier to choose a PIC with an internal A2D, try the 16F819 or 16F88, both are 18 pin like the 16F628.
 
Built in A/D

Hello!

If you had read the link I wrote, you would have seen that's a comlett project, and PIC doesn't handle the convertation. I wouldn't change the program, because, I never did the same. But if you can do this, and share the reason with me, I would be very indebted for you.

Special thanx!
 
Hi

I am a 16F84a working with a ADC0832 A/D converter (8 bits in serial stream output).

Code:
MAIn.c


#include <16f84a.h>
#use delay(clock=4000000)
#fuses XT,NOWDT,NOPROTECT
#use RS232(BAUD=9600, BITS=8, PARITY=N, XMIT=PIN_B2, RCV=PIN_B4, RESTART_WDT)
#include "adc0832.c"

float value;
void main() {
   //adc_init();
   set_adc(0);
   read_adc();
   printf("A/D Conversion using ADC0832 Chip\n\r");
   value=(adc_result/51);     // 0-5 volt scale
   putc(13);
   printf("adc_result=%X\n\r",adc_result);
   printf("Channel 0 Voltage = %01.2F\r",value);
}

Code:
adc0832.c


#define AD_CS pin_A0   // Chip Select
#define AD_CK pin_A1   // Clock
#define AD_DI pin_A2   // Data In (MUX Channel Selector)
#define AD_DO pin_A3   // Data Out

int adc_result;

void  delay() {
      delay_us(3);
}

void  Clock() {
      output_high(AD_CK);
      delay();
      output_low(AD_CK);
}

void  set_adc(short ch) {   //ch corresponde al canal a medir
      if(ch==0){
                            //ch=0 . Seleccionamos canal 0 del ADC
      output_high(AD_CS);   //Inicia transicion de habilitacion del ADC
      delay();              //Retardo necesario para no superar los 200 KHz de frecuencia del ADC
      output_low(AD_CS);    //Activa la linea /CS (chip select) sobre el ADC para iniciar conversion.
		delay();        	    //Debe estar asi durante toda la conversion,
                            //Ahora el chip espera un bit de partida y la palabra de asignacion MUX
      output_high(AD_DI);   //Pone en 1 el bit de partida DI del MUX de seleccion de puerto
      delay();
      Clock();              //Pasamos este bit de start hacia el MUX del ADC0832
                            //El dato DI es pasado al MUX en cada Rising Edge del Clock
      output_high(AD_DI);   //Con DI=SGL/DIF=1 seleccionamos "Single-Ended MUX mode"
      delay();              //Mantenemos en estado High bit DI
      Clock();              //pasamos el SGL/DIF al MUX del ADC0832
      output_low(AD_DI);    //Con DI=ODD/SIGN=0 seleccionamos el Channel 0.
      delay();
      Clock();              //Con este ultimo clock termina la asignacion del canal a conevertir
      }
      else {
                            //ch=1 . Seleccionamos canal 1 del ADC
      output_high(AD_CS);   //Inicia transicion de habilitacion del ADC
      delay();              //Retardo necesario para no superar los 200 KHz de frecuencia del ADC
      output_low(AD_CS);    //Activa la linea /CS (chip select) sobre el ADC para iniciar conversion.
		delay();        	    //Debe estar asi durante toda la conversion,
                            //Ahora el chip espera un bit de partida y la palabra de asignacion MUX
      output_high(AD_DI);   //Pone en 1 el bit de partida DI del MUX de seleccion de puerto
      delay();
      Clock();              //Pasamos este bit de start hacia el MUX del ADC0832
                            //El dato DI es pasado al MUX en cada Rising Edge del Clock
      output_high(AD_DI);   //Con DI=SGL/DIF=1 seleccionamos "Single-Ended MUX mode"
      delay();              //Mantenemos en estado High bit DI
      Clock();              //pasamos el SGL/DIF al MUX del ADC0832
      output_high(AD_DI);   //Con DI=ODD/SIGN=1 seleccionamos el Channel 1.
      delay();
      Clock();              //Con este ultimo clock termina la asignacion del canal a conevertir
      }
}

// Esta funcion debe llamarse despues de seleccionar el canal
// del ADC0832 a ser utilizado para conversion.
// CS debe estar activo (low)
// El ADC0832 entrega dos stream de salida en DO:
// - MSB first
// - LSB first
// Por tanto, leemos el MSB firts, lo desplazamos a la izquierda
// y una vez completado el byte, desechamos el stream LSB y deseleccionamos
// el ADC0832 haciendo CS=1 (high)

void read_adc() {
    int i;
    for (i=0;i<8;i++) {          // Lee el byte resultado de conversion desde el ADC0832
         Clock();                // y lo almacena en adc_result
         shift_left(&adc_result, 1, input(AD_DO));
         delay();
         }
         output_high(AD_CS);     //Despues de leido el byte completo, deseleccionamos el ADC0832
                                 //poninedo CS=1 (high).
                                 //Con esto termina la lectura del conversor A/D
}


Best regards
 
adc0832.c

Code:
// Please first read ADC0832 datasheet

#define AD_CS pin_A0   // Chip Select 
#define AD_CK pin_A1   // Clock 
#define AD_DI pin_A2   // Data In (MUX Channel Selector) 
#define AD_DO pin_A3   // Data Out 

int adc_result;             // Variable that stores the result of the conversion ( 8 bits  ==> int type)

void  delay() {             // Delay rutine
      delay_us(3); 
} 

void  Clock() {             //Signal Clock, to read or put data from/to ADC0832
      output_high(AD_CK); 
      delay(); 
      output_low(AD_CK); 
} 


// Set_adc();   ==> Rutine for set MUX word to send towards ADC0832 (measure mode and channel selected)

void  set_adc(short ch) {   //ch corresponds to the channel to measure, is a "short" data type. (one bit)
      if(ch==0){ 
                            //ch=0. We select channel 0 of the ADC.
      output_high(AD_CS);   //It initiates transition to enable ADC.
      delay();              //Necessary delay to not overcome 200 KHz of frequency of the ADC.
      output_low(AD_CS);    //It activates the line /CS (chip select) on the ADC to initiate conversion 
      delay();              //It must be like that during the whole conversion, 
                            //Now the chip waits for a "Start bit" and the "MUX word setting" bits ( two bits)
      output_high(AD_DI);   //It puts in 1 the bit of game SAY of the MUX of selection of port 
      delay(); 
      Clock();              //We put this start bit towards the MUX of the ADC0832
                            //The bit DI is put into MUX in every Rising Edge of the Clock 
                            
      output_high(AD_DI);   //DI=SGL/DIF=1 we select "Single-Ended MUX mode" 
      delay();              //We stay DI in high state (DI=1)
      Clock();              //we put SGL/DIF into MUX of ADC0832 
      output_low(AD_DI);    //With DI=ODD/SIGN=0 we select Channel 0. 
      delay(); 
      Clock();              //With the latter clock it finishes the allocation of the channel to convert
      } 
      else { 
                            //ch=1. we select channel 1 of ADC 
      output_high(AD_CS);   //It initiates transition to enable ADC
      delay();              //Necessary delay to not overcome 200 KHz of frequency of the ADC.
      output_low(AD_CS);    //It activates the line /CS (chip select) on the ADC to initiate conversion 
      delay();              //It must be like that during the whole conversion, 
                            //Now the chip waits for a "Start bit" and the "MUX word Setting" bits ( two bits)
      output_high(AD_DI);   //It puts in 1 the bit of game SAY of the MUX of selection of port 
      delay(); 
      Clock();              //We put this start bit towards the MUX of the ADC0832 
                            //The bit DI is put into MUX in every Rising Edge of the Clock 
      output_high(AD_DI);   //With DI=SGL/DIF=1 we select "Single-Ended MUX mode" 
      delay();              //We stay DI in high state (DI=1)
      Clock();              //we put SGL/DIF into MUX of ADC0832
      output_high(AD_DI);   //With DI=ODD/SIGN=1 we select Channel 1.  
      delay(); 
      Clock();              //With the last clock it finishes the allocation of the channel to convert 
      } 
} 

// This function must be called after selecting the channel 
// of the ADC0832 to be used for conversion. 
// CS must be active (low) 
// The ADC0832 delivers two stream out in DO: 
// - MSB first 
// - LSB first 
// Therefore, we read the MSB firts, shift it to the left side of adc_result
// and as soon as the byte was completed, we reject the stream LSB and disable
// the ADC0832 doing CS=1 (high)

void read_adc() { 
    int i; 
    for (i=0;i<8;i++) {          // Read the result buyte of ADC0832 conversion.
         Clock();                // and store it into adc_result 

         shift_left(&adc_result, 1, input(AD_DO)); 
         delay(); 
         } 
         output_high(AD_CS);     //After read the finished byte,disable ADC0832 
                                 //doing CS=1 (high). 
                                 //With this it finishes the reading of the ADC0832 out stream, 
                                 //and we can process the result in main.c 
}
 
Pappee said:
Hi All!
I woluld like to connect (for example) an LM35 Thermo sensor to a PIC during an A/D converter. Can somebody tell me what kind of A/D converter could I use? Have sombody experience in this?How does PIC process the converted analog sign?
I have a circuit from a Czech web site(**broken link removed**), but the author did use a very-very expensive termistor, what includes A/D converter(SMT160-30).I tought that change it a simple thermistor & a cheap A/D converter. I get any help with pleasure!

http:\\attilapapp.uw.hu
:D
hi,
the easiest and best way is to use inbuilt A/D convertor of pic
if you you are facing the problem you mail your project and i will do the coding for your aplication our i will suggest some more circuits and codes
for your application

dinesh_aurum@yahoo.com
 
NEED a circuit and program

can any one help me in my project? i have a project which is controlling the temperature and humidity. My problem what IC to be used in humidity. and also how can i build a circuit and program of temperature and humidity.

I hope any one can help me with my project..

here' s my email add.. please send me.

anaviso_candido@yahoo.com
 
Last edited:
candz12 said:
can any one help me in my project? i have a project which is controlling the temperature and humidity. My problem what IC to be used in humidity. and also how can i build a circuit and program of temperature and humidity.

I hope any one can help me with my project..

here' s my email add.. please send me.

anaviso_candido@yahoo.com

Don't hijack posts, start a new thread instead.

The humirel hs1101 has a schematic in its datasheet for a humidity sensor using a CMOS 555.
 
Status
Not open for further replies.

Latest threads

Back
Top