View previous topic :: View next topic |
Author |
Message |
vtrx
Joined: 11 Oct 2017 Posts: 142
|
18F2550 ADC AN0,AN1 |
Posted: Fri May 03, 2019 6:47 am |
|
|
I need to use AN0 and AN1 with the ADC and A2 as input.
It seems to me that the code below does not work.
Code: | setup_adc_ports(AN0_to_AN1); |
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Fri May 03, 2019 7:36 am |
|
|
hmm..
Quote: | #define AN0_TO_AN1 0x0D // A0 A1 |
is what I have in the device header, so it 'should' work.
You need to post a small program that fails as well as the compiler version.
Jay |
|
![](templates/subSilver/images/spacer.gif) |
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Fri May 03, 2019 5:06 pm |
|
|
Solved, the microcontroller was faulty on pin4, it was probably when i reversed the ci in the test socket. |
|
![](templates/subSilver/images/spacer.gif) |
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Sun May 05, 2019 4:58 am |
|
|
Is it possible to use the ADC only on port B (AN11, AN12) and the other pins as input? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Sun May 05, 2019 5:07 am |
|
|
The answer lies in the 'device header' file ! PICtype.h.... In there will be all the combinations of valid ADC settings, along with everything else.....
You should also read the ADC chapter of the datasheet. Depending on application and I/O pins, there are 'tips and tricks' ,to using ADC pins.
One is that you can use any ADC pin for a digital input. Simply configure the ADC to read that pin, if the value is greater than 250( for 8 bits) then it's a '1' otherwise it's a '0'.
Jay |
|
![](templates/subSilver/images/spacer.gif) |
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Sun May 05, 2019 5:13 am |
|
|
Can I use fast_io() along with ADC?
If I use set_tris_a(0x11111111) the ADC does not work. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Sun May 05, 2019 7:18 am |
|
|
show us your code...
setting all of port A to inputs, reconfigures the pin with clko, which 'might' be a problem..it also eliminates Vref-,vref+, another potential problem.
we NEED to see your code to properly advise you.
Jay |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 05, 2019 11:04 am |
|
|
Here is a test program for the ADC on AN0 for the 18F4550:
Code: |
#include <18F4550.h>
#device adc=10
#fuses NOWDT, PUT, BROWNOUT, NOLVP
#use delay(internal=4M)
#use rs232(baud=9600, UART1, ERRORS)
//============================
void main()
{
int16 result;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_4); // See 18F4550 data sheet for divisor
set_adc_channel(0);
delay_us(3); // This delay is from 18F4550 data sheet
while(TRUE)
{
result = read_adc();
printf("%LX \n\r", result);
delay_ms(500);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
|