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 CCS Technical Support

PIC12F510 question for ADC and I/O

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



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PIC12F510 question for ADC and I/O
PostPosted: Mon Nov 09, 2020 5:04 pm     Reply with quote

Hy,
I have my project to use ADC for AN0
I use
Code:

setup_adc_ports(AN0_AN2);

As I read data sheet for this 12F510 ADC setup can't use only for AN0.
My project want to use GP2 for output, but is still blocked I think by ADC.

Someone have a solution for this?

also I use

setup_comparator (NC_NC_NC_NC);

but didn't help.

Thank you.
temtronic



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

View user's profile Send private message

PostPosted: Mon Nov 09, 2020 5:26 pm     Reply with quote

The easy solution...

If you only need 1 analog input, configure the PIC to use AN2. According to the datasheet this should be possible.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 09, 2020 5:31 pm     Reply with quote

Or, if you must have AN0, then:

Change the PIC to a 12F1572. It's an 8-pin PIC. It has individual enables
for An0, An1, An2. It also uses the PCB compiler, the same as for 12F510.

Or, you change to a 12F1840. It's an 8-pin PIC for the PCM compiler.
It also has indivual enables for An0, An1, An2. It requires PicKit 3 to
program it. (or compatible ICD).
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Tue Nov 10, 2020 1:08 am     Reply with quote

Thank you Temtronic
Thank you PCM programmer

A this moment I have already 12F510 and old pickit1 programmer. Also project pcb is approved.

I think to switch manually An2 with An0 on all hardware pcb. But until I have confirmation that is no possibility to solve other way this problem...

If you have any viable solution I'm happy to hear it.

Best regards.
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Tue Nov 10, 2020 2:20 am     Reply with quote

A lot depends on what you want to do with GP2.
At the end of the day, the PIC you have is restricted on what it can do,
and it sounds as if the board was really laid out for a different PIC.
You can potentially only enable the ADC for a short moment to take a
reading, and then switch back to using the I/O, but for that moment, GP2
is going to be floating.
So:
Code:

   //Somewhere at the start of the code, setup the ADC clock
   //and the channel to '0'
 

   //Then when you actually want the reading
   setup_adc_ports(ANO_AN2); //at this moment GP2 will start to float
   delay_us(20); //The ADC on this chip doesn't specify Tacq. However it
   //is the same unit used on some other PIC's and these require 10 to
   //20uSec Tacq.
   val=read_adc();
   setup_adc_ports(NO_ANALOGS); //GP2 will now drive again.

Now assuming you set the adc clock to give a Tad of 1uSec, the GP2 pin will
be disconnected as an output for about 40uSec. Whether this is a problem
depends on what you are actually doing with the GP2 pin.
There is a separate 'issue', that GP0, may draw excessive current since
it will be sitting as a digital input, with an analog voltage applied, for
most of the time.

In all honestly replacing with a chip that allows AN0 to be selected on it's
own, is the better solution by far.
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Tue Nov 10, 2020 8:08 am     Reply with quote

Yes Ttelmah.
Your solution it may be work.
I try and come back with feedback.
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

[solved]
PostPosted: Wed Nov 11, 2020 12:22 pm     Reply with quote

yes Ttelmah, your solution is working.

I made some hardware "adjustments" for time that output is not in function with filter by RC.

Thank you for help.
All the best.
Ttelmah



Joined: 11 Mar 2010
Posts: 19550

View user's profile Send private message

PostPosted: Thu Nov 12, 2020 2:15 am     Reply with quote

Glad it is working. It is though a 'lesson', to always be careful checking the
actual chip capabilities before committing to a board.... Sad
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