ppperez
Newbie level 5
- Joined
- Jul 31, 2014
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 84
Hello Masters.
I am studding the PIC18F452, I am reading a lot of examples and tutorials of ADC module.
I am using the C18, I read the microchips libraries pdf file, where if I use the adc.h the code is the following:
I understand the code but I read into another examples that the above code only read once. I need that the PIC is converting every time, Why? I will have a sensor of input, What sensor? any sensor, I will have the input of 0-5V analog of course.
I read another link that the code that they used to read the input was the following:
**************************************************************
That code is for the PIC18f4520 and I understand that it has ADCON0, ADCON1 and ADCON2 and the PIC that I am using is the PIC18F452 with ADCON0 and ADCON1
anyway, I don't understand the first line:
I think that ADCON0 = 0xC3, is this correct?
ch<<2 what this means? I found that this select analog channel, but could someone explain me with another words?
Thanks in advance
I am studding the PIC18F452, I am reading a lot of examples and tutorials of ADC module.
I am using the C18, I read the microchips libraries pdf file, where if I use the adc.h the code is the following:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include <p18C452.h> #include <adc.h> #include <stdlib.h> #include <delays.h> int result; void main( void ) { // configure A/D convertor OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_8ANA_0REF, ADC_CH0 & ADC_INT_OFF ); Delay10TCYx( 5 ); // Delay for 50TCY ConvertADC(); // Start conversion while( BusyADC() ); // Wait for completion result = ReadADC(); // Read result CloseADC(); // Disable A/D converter }
I understand the code but I read into another examples that the above code only read once. I need that the PIC is converting every time, Why? I will have a sensor of input, What sensor? any sensor, I will have the input of 0-5V analog of course.
I read another link that the code that they used to read the input was the following:
**************************************************************
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 #define select_ADC(ch) { ADCON0 &= 0b11000011; ADCON0 += (ch<<2); } uint16 ADC_read(uint8 ch) { uint16 res; select_ADC(ch); ADCON0bits.GO=1; while(ADCON0bits.GO); res = ADRESH; res=(res<<8)+ ADRESL; return res; } ***************************************************************
That code is for the PIC18f4520 and I understand that it has ADCON0, ADCON1 and ADCON2 and the PIC that I am using is the PIC18F452 with ADCON0 and ADCON1
anyway, I don't understand the first line:
Code:
#define select_ADC(ch) { ADCON0 &= 0b11000011; ADCON0 += (ch<<2); }
ch<<2 what this means? I found that this select analog channel, but could someone explain me with another words?
Thanks in advance
Last edited by a moderator: