![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hello everyone, I have encountered the problem of using dual/multiple ADC inputs into PIC. I am using 2 ADC channels and outputting the result onto a LCD. The output that I receive is always that for the PORT with the higher pin (eg. If I am using pin RA1 & RA0, only the conversion of RA1 is received in my LCD display) There seems to be an overwrite of the RA1 over RA0. This problem persist when I am using different input pins. The below mentioned is the code for ADC reading and initialisation. : Thank you for your help. void ADC_init() // for init of ADC { ADCON1=0x82; TRISA=0xff; } int read_ADC_channel(unsigned int channel_number) // for reading { int value; switch(channel_number) { case 0: ADCON0 = 0b01000011; case 1: ADCON0 = 0b01001011; default:; } DelayMs(1); ADGO=1; //start AD conversion while(ADGO) //wait for conversion to finish {}; value=(ADRESH<<8)+ADRESL; //read the values in the registers return(value); } | |
| |
| | (permalink) |
| You might try reading my tutorial about the ADC, it explains a number of potential problems - in particular that of the source impedance that's feeding the ADC - in your case you're not allowing much time for the sample and hold to charge/discharge, so you better have a really low source impedance?. | |
| |
| | (permalink) | |
| Quote:
Code: switch(channel_number)
{
case 0:
ADCON0 = 0b01000011;
break;
case 1:
ADCON0 = 0b01001011;
break;
// ... | ||
| |
| | (permalink) |
| Hi, thank you for all your prompt reply, I did actually included a break in between: DelayMs(1); This will delay for 1 ms which I think should be more than sufficient for anything, I even try up to 10 sec and it's still the same. As for impedance, I have measured it and its aound 1kohm, so not that high too. Last edited by andyto; 24th September 2007 at 12:46 PM. | |
| |
| | (permalink) | |
| Quote:
You have to place a break after each case. | ||
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) | |
| Quote:
I use a mulitmeter one end to my LDR and the other end to gnd, not sure if it is the correct way of doing it. | ||
| |
| | (permalink) | |
| Quote:
And why are you trying to read it every millisecond?. | ||
| |
| | (permalink) |
| I have it on 2 inputs. Will they sort of cross interferw with each other? | |
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) | |
| Quote:
Last edited by eng1; 24th September 2007 at 01:58 PM. | ||
| |
| | (permalink) | |
| The type of LDR I have is a 3 pin type (1 to gnd, 1 to Vcc and the other is the Vout) acts like a potentiometer. Eng1's break statement has helped me solve one wierd problem which is why the value duplicates, my mistake in programming. However, another problem surfaced. Now, input 1 RA0 works perfectly fine. But I am getting no reading from RA1, which has the same input circuit as RA0, even if I unplug and plug it into the RA0 circuit the reading is still 0. Below is my full code. Your help is greatly appreicated. Quote:
| ||
| |
| | (permalink) |
| Somehow I got it solved, simply by using RA2 instead of RA1. I am not sure why is this happening. Anyone has similar experience before? | |
| |
| | (permalink) |
| I remember on the 876A that if you were using multiple porta pins for analog or digital I/O that some combinations of analog and/or digital I/O on certain pins was not possible. Basically they gave you 5 bits in a register to set what all 8 pins were (A or D). 5 not enough | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| 16F877 Timer0 Interrupt Affecting ADC | sebana | Micro Controllers | 13 | 12th September 2007 10:43 AM |
| PIC16F877 general purpose RAM problem | mysteyboyk | Micro Controllers | 13 | 10th July 2007 04:37 PM |
| multiple touch switch problem | sstimuluss | Electronic Projects Design/Ideas/Reviews | 3 | 15th January 2007 03:03 AM |
| pic16f877 ram problem | osmandemirci | General Electronics Chat | 1 | 28th November 2006 04:11 PM |
| PIC16F877 ADC Problem All values the same | Theodoros | Micro Controllers | 10 | 2nd June 2005 07:33 AM |