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

Using all pins on a 12f683

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



Joined: 19 May 2009
Posts: 60

View user's profile Send private message

Using all pins on a 12f683
PostPosted: Tue Sep 21, 2010 4:02 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Sep 21, 2010 4:19 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 22, 2010 1:17 am     Reply with quote

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: 19541

View user's profile Send private message

PostPosted: Wed Sep 22, 2010 4:28 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 22, 2010 5:41 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 22, 2010 6:56 am     Reply with quote

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: 19541

View user's profile Send private message

PostPosted: Wed Sep 22, 2010 7:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 22, 2010 7:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 30, 2010 8:48 am     Reply with quote

Ok everything is working now. All pins are now occupied, what a great little chip this is Cool
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