View previous topic :: View next topic |
Author |
Message |
Skirmitt
Joined: 19 May 2009 Posts: 60
|
Using all pins on a 12f683 |
Posted: Tue Sep 21, 2010 4:02 pm |
|
|
For my next project I need a small pin count chip. I chose the 12f683, it's good available and is cheap.
I do have a question with this chip. The chip has 6 data lines available but I do not know how to lay out my pins.
pwm output on ccp (obvious)
relay - digital output
led - digital output
switch - digital input with interrupt
digital input channel
analog input - analog adc channel
That are 6 channels, is this possible ? How can I configure GP3 and GP5 to be usable ? Can I still do ICSP when everything is connected ?
Can I still read the analog voltage and have IOC on the digital input ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 21, 2010 4:19 pm |
|
|
Quote: | How can I configure GP3 and GP5 to be usable ?
|
Use NOMCLR to make GP3 usable. But remember, it's only available as
an input-only pin. For GP5, use the internal oscillator, and configure the
oscillator pins to be available for normal i/o with this fuse: INTRC_IO
Quote: | Can I still do ICSP when everything is connected ?
|
See this previous thread on the topic:
http://www.ccsinfo.com/forum/viewtopic.php?t=41028 |
|
|
Skirmitt
Joined: 19 May 2009 Posts: 60
|
|
Posted: Wed Sep 22, 2010 1:17 am |
|
|
Thanks for the information. I have some more questions.
GP0 = A0
GP1 = A1
GP2 = A2
GP4 = A3 , how can I call GP5 and GP3 in my program ?
The header file shows me to use A0 -> A5.
And do I have to respect some order to combine the analog pin with the other digital pins / interrupt pin ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Wed Sep 22, 2010 4:28 am |
|
|
The data sheet should be your starting point.
From this you get:
Code: |
Digital pin Directions Analog name
GP0 I/O AN0
GP1 I/O AN1/Vref
GP2 I/O AN2
GP3 I
GP4 I/O AN3
GP5 I/O
|
So two things immediately leap out. GP3, is _digital input only_.
GP5, does not support analog I/O.
Then look at the A/D converter section. On a lot of chips, with more ADC channels, there is a specific 'order' that these can be used. So you may find that to have just one ADC channel, this has to be on AN0. However on this ship, there is no such restriction, with the four inputs being individually selectable. So the selection of which pin to use, for the analog input from GP0, GP1, GP2, or GP4, will come down to which are already used for other things, and board criteria.
So, stepping on, we now have:
PWM output = GP2 (hardware limitation)
one digital input = GP3 (since this is the only 'job' this pin can do).
Now you have the question of the interrupt. Unfortunately, the only pin with a definable interrupt, is GP2, which is already in use. Hence, you are going to have to use the 'interrupt on change' feature. This is available on all the GPIO pins, _but_ means that the code is going to have to test which edge is occurring.
The remaining pins are 'down to you', but a couple of comments then apply.
You already have a PWM, on GP2. This is potentially a source of noise, which should be kept away from the analog input. The same applies to a larger extent to the relay drive in particular, and the LED output. Hence, it make good 'electrical' sense to keep these down one side of the chip. So, GP0/GP1 = relay/LED GP2=PWM. GP3/5=digital input/switch, and GP4=analog input.
Best Wishes |
|
|
Skirmitt
Joined: 19 May 2009 Posts: 60
|
|
Posted: Wed Sep 22, 2010 5:41 am |
|
|
Thanks for your very useful input.
Although this remains:
Code: |
GP3 I xxx
GP4 I/O AN3
GP5 I/O xxx
|
Where I filled in xxx, is GP3 = A4 and GP5 = A5 ?
I know I can find this with trial and error but the chip is on its way to me and I am already preparing the code for it. |
|
|
Skirmitt
Joined: 19 May 2009 Posts: 60
|
|
Posted: Wed Sep 22, 2010 6:56 am |
|
|
I made this schematic. I don't think I made a mistake with the ICSP lines here.
Throttle is a digital input. GP0 should give the interrupt. The analog input is where I read Vbat.
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Wed Sep 22, 2010 7:20 am |
|
|
Skirmitt wrote: | Thanks for your very useful input.
Although this remains:
Code: |
GP3 I xxx
GP4 I/O AN3
GP5 I/O xxx
|
Where I filled in xxx, is GP3 = A4 and GP5 = A5 ?
I know I can find this with trial and error but the chip is on its way to me and I am already preparing the code for it. |
No.
GP3, and GP5, _are not available for analog I/O_, so have no 'analog name'. Hence the column is blank. This function is 'not available' on these pins.
Best Wishes |
|
|
Skirmitt
Joined: 19 May 2009 Posts: 60
|
|
Posted: Wed Sep 22, 2010 7:24 am |
|
|
Sorry I asked my question wrong. What I mean is, what alias can I use to make that pin high and low ?
output_high(PIN_GP3) doesn't work obviously. |
|
|
Skirmitt
Joined: 19 May 2009 Posts: 60
|
|
Posted: Thu Sep 30, 2010 8:48 am |
|
|
Ok everything is working now. All pins are now occupied, what a great little chip this is |
|
|
|