Pallavi Burje
Junior Member level 1
- Joined
- Oct 29, 2013
- Messages
- 18
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 121
hi
I m doing project on PIC18f4680 microcontroller. In that i want to interface 3 different sensors to pic18f4680 microcontroller's ADC module using its channels. so i want to know, is this possible?? if yes, how to write a code... please help..
Mention details about your project like what you want to measure and what are the ranges of adc inputs you are giving to the different adc channels. Are you going to use Vref +/-? Post a circuit and mention the Compiler you are using and also Fosc.
Proteus has LM35 and pressure sensor. You can use them. For Gas Sensor you can use pot for simulation. LM35 max output for 150 deg C is 1.5V. If you set Vref+ to 1.6V say then it applies to all the channels. See if you can set Vref+ to 1.6V only when measuring LM35 sensor o/p and then disabling Vref+ when measuring o/ps of gas sensor and pressure sensor. You have to use ADCON0 to select ADC channels and ADCON1 to enable or disable Vref+. You can use Fosc of 4MHz. Mention pressure sensor you are going to use. I guess gas sensor modules analog o/p varies from 0 to 5V.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 // LCD module connections sbit LCD_RS at LATD0_bit; sbit LCD_EN at LATD1_bit; sbit LCD_D4 at LATD4_bit; sbit LCD_D5 at LATD5_bit; sbit LCD_D6 at LATD6_bit; sbit LCD_D7 at LATD7_bit; sbit LCD_RS_Direction at TRISD0_bit; sbit LCD_EN_Direction at TRISD1_bit; sbit LCD_D4_Direction at TRISD4_bit; sbit LCD_D5_Direction at TRISD5_bit; sbit LCD_D6_Direction at TRISD6_bit; sbit LCD_D7_Direction at TRISD7_bit; // End LCD module connections float adcVal; unsigned char lcdData[23]; void readADC() { ADCON0.GO = 1; //Start conversion while(ADCON0.GO); //Wait till conversion finishes adcVal = (ADRESH << 8) | ADRESL; //Read ADC result into adcVal } void main() { TRISA = 0xFF; TRISB = 0x00; TRISC = 0x00; TRISD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; LATA = 0x00; LATB = 0x00; LATC = 0x00; LATD = 0x00; CMCON = 0x07; CVRCON = 0x00; LCD_Init(); LCD_Cmd(_LCD_CURSOR_OFF); LCD_Cmd(_LCD_CLEAR); LCD_Out(1,1,"Multiple ADC"); while(1){ ADCON0 = 0b00000001; //Select AN0, LM35 ADCON1 = 0b00011010; //Vref+ used ADCON2 = 0b10101101; //12 TAD, 16 TOSC Delay_ms(10); //Delay for ADC stabilization readADC(); //Read ADC adcVal = adcVal / 6.413332; //Convert ADC value FloatToStr(adcVal, lcdData); //Convert to string LCD_Out(2,1,lcdData); //Display adc value on LCD ADCON0 = 0b00000101; //Select AN1, Load Cell ADCON1 = 0b00001010; //Vref disabled, AVdd and AVss are used ADCON2 = 0b10101101; //12 TAD, 16 TOSC Delay_ms(10); //Delay for ADC stabilization readADC(); //Read ADC adcVal = adcVal * 5.0 / 1023.0; //Convert ADC value FloatToStr(adcVal, lcdData); //Convert to string LCD_Out(3,1,lcdData); //Display adc value on LCD ADCON0 = 0b00001001; //Select AN2, MQ-6 ADCON1 = 0b00001010; //Vref disabled, AVDD and AVSS are used ADCON2 = 0b10101101; //12 TAD, 16 TOSC Delay_ms(10); //Delay for ADC stabilization readADC(); //Read ADC adcVal = adcVal * 5.0 / 1023.0; //Convert ADC value FloatToStr(adcVal, lcdData); //Convert to string LCD_Out(4,1,lcdData); //Display adc value on LCD } } /* //ADCON0 = 0b00000001; ADCON1 = 0b00011010; ADCON2 = 0b10101101; Delay_ms(10); adcVal = ADC_Read(0); adcVal = adcVal / 6.413332; FloatToStr(adcVal, lcdData); LCD_Out(2,1,lcdData); //ADCON0 = 0b00000101; ADCON1 = 0b00001010; ADCON2 = 0b10101101; Delay_ms(10); adcVal = ADC_Read(1); adcVal = adcVal * 5.0 / 1023.0; FloatToStr(adcVal, lcdData); LCD_Out(3,1,lcdData); //ADCON0 = 0b00001001; ADCON1 = 0b00001010; ADCON2 = 0b10101101; Delay_ms(10); adcVal = ADC_Read(2); adcVal = adcVal * 5.0 / 1023.0; FloatToStr(adcVal, lcdData); LCD_Out(4,1,lcdData); */
Code C - [expand] 1 CMCON = 0x07
Code C - [expand] 1 CVRCON = 0x00
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?