CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

18F2550 ADC AN0,AN1

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vtrx



Joined: 11 Oct 2017
Posts: 141

View user's profile Send private message

18F2550 ADC AN0,AN1
PostPosted: Fri May 03, 2019 6:47 am     Reply with quote

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);
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri May 03, 2019 7:36 am     Reply with quote

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
vtrx



Joined: 11 Oct 2017
Posts: 141

View user's profile Send private message

PostPosted: Fri May 03, 2019 5:06 pm     Reply with quote

Solved, the microcontroller was faulty on pin4, it was probably when i reversed the ci in the test socket.
vtrx



Joined: 11 Oct 2017
Posts: 141

View user's profile Send private message

PostPosted: Sun May 05, 2019 4:58 am     Reply with quote

Is it possible to use the ADC only on port B (AN11, AN12) and the other pins as input?
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun May 05, 2019 5:07 am     Reply with quote

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
vtrx



Joined: 11 Oct 2017
Posts: 141

View user's profile Send private message

PostPosted: Sun May 05, 2019 5:13 am     Reply with quote

Can I use fast_io() along with ADC?
If I use set_tris_a(0x11111111) the ADC does not work.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun May 05, 2019 7:18 am     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 05, 2019 11:04 am     Reply with quote

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);
  }

}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group