View previous topic :: View next topic |
Author |
Message |
nailuy
Joined: 21 Sep 2010 Posts: 159
|
PIC12F510 question for ADC and I/O |
Posted: Mon Nov 09, 2020 5:04 pm |
|
|
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
|
|
Posted: Mon Nov 09, 2020 5:26 pm |
|
|
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
|
|
Posted: Mon Nov 09, 2020 5:31 pm |
|
|
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
|
|
Posted: Tue Nov 10, 2020 1:08 am |
|
|
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: 19551
|
|
Posted: Tue Nov 10, 2020 2:20 am |
|
|
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
|
|
Posted: Tue Nov 10, 2020 8:08 am |
|
|
Yes Ttelmah.
Your solution it may be work.
I try and come back with feedback. |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
[solved] |
Posted: Wed Nov 11, 2020 12:22 pm |
|
|
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: 19551
|
|
Posted: Thu Nov 12, 2020 2:15 am |
|
|
Glad it is working. It is though a 'lesson', to always be careful checking the
actual chip capabilities before committing to a board.... |
|
|
|