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

FAST_IO vs STANDARD_IO with pins used as output?

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



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

FAST_IO vs STANDARD_IO with pins used as output?
PostPosted: Sun Mar 16, 2014 3:21 pm     Reply with quote

After much searching and reading the manual, it is still not quite clear to me what format to use. Compiler 4.141, 12F1822 RA4 and RA5 drive LED's through 220 ohm resistors. I want to use the PWM on RA2 (pin 5). Simple blink leds program works fine using "OUTPUT_LOW()" and "OUTPUT_HIGH()" calls (this is with the default STANDARD_IO). My question is how to set the RA2 pin to output mode since it is never set from the compiler with an "output" call. Is it better to use the "OUTPUT_DRIVE()" at the top to set it to output (and will the compiler mess with it during the other output instructions to the other pins?) or is it better to use FAST_IO and set the three pins with either "OUTPUT_DRIVE()" or a set_TRIS call ?

I realize for STANDARD_IO, the compiler controls TRIS and for FAST_IO, the user is responsible for setting the TRIS correctly, it is just not clear to me what interaction happens if I am using STANDARD_IO but then control the TRIS on a pin that is the PWM output (or does setup_ccp1(CCP_PWM) configure the pin correctly?)

I should add that I currently have the two LEDS blinking as expected, I am just not sure on configuring the PWM bit correctly ( I am using the default pin for the PWM, not the alternate assignment for that function).

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Sun Mar 16, 2014 3:43 pm     Reply with quote

Depends on your chip.

If you have a standard UART, or standard PWM, then the compiler automatically sets the TRIS on this pin for you, unless you specifically override it.
Where it can fail (depending on the compiler version), is on chips with 're-mappable' peripherals. On these the compiler often won't control the TRIS if the function is on the alternate location.
On your chip, the default location for the PWM, is RA2 if you have an 8pin device (your part number is for an 8pin device). So you'd need to set the CCP1SEL pin, and the TRIS manually. #BIT CCP1SEL=getenv("BIT:CCP1SEL") and then set CCP1SEL=TRUE; and 'output_drive' on the pin.

Best Wishes
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Sun Mar 16, 2014 4:14 pm     Reply with quote

So, the compiler "should" set the TRIS bit for me correctly since I am using the default (RA2), but just to be safe, I should use the "OUTPUT_DRIVE(RA2)" call is what you are saying (using the default STANDARD_IO)? In my case, CCP1SEL is "0" which selects the default (RA2) (1 would put the PWM on RA5 as the alternate - which I am not doing).

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

PostPosted: Mon Mar 17, 2014 1:03 am     Reply with quote

Yes, with standard_io.
With fast_io, all TRIS control becomes _your_ responsibility.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon Mar 17, 2014 8:28 am     Reply with quote

Thanks Ttelmah. I'll stick with the default STANDARD_IO but use the OUTPUT_DRIVE(RA2) for the PWM just to make sure it is correctly set (since just because it works by "default" with this compiler version doesn't mean it will with the next version Wink )

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Mar 18, 2014 8:15 am     Reply with quote

Quote:

TRIS control becomes _your_ responsibility.


the same as for the proper functioning of the whole program in
it's totality.

and is why i have been using fastio for every register in the pic,
always...... Very Happy Very Happy Very Happy Very Happy Very Happy
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Tue Mar 18, 2014 9:38 am     Reply with quote

Thanks asmboy - I had come across your comments in the thread on "FAST_IO general question" ( http://www.ccsinfo.com/forum/viewtopic.php?t=48100 ) and that was part of the reason for my initial post. What you had said did make sense and I am always suspicious when either the compiler or windows "helps" me in life Laughing When I install windows, one of the first things I do is turn OFF the option to "hide extensions of known file types" since windows only *thinks* it knows what they are and it causes nothing but confusion from my viewpoint.

My interpretation from reading the manual I have is that if I specify "FAST_IO" then the "OUTPUT_LOW()" call will leave the TRIS alone while if I were to use "STANDARD_IO" then the same call would modify the TRIS as needed for output (the manual page for "OUTPUT_LOW()" says " ... The method of I/O used is dependent on the last USE *_IO directive" )

mikey

_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Mar 18, 2014 11:17 am     Reply with quote

my "attitude" comes from being too weak minded to keep up with conditional instructs - hidden in the background by 'yee compiler, and habits from earlier pic by ASM programming.

if its going to go bad- i won't have to peer at as much of the LST file to get to the problem.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Tue Mar 18, 2014 12:38 pm     Reply with quote

Hey, I come from hand assembling (in octal since that makes the most sense) 8080 code. I even had a little cardboard "slide rule" type gadget for figuring out the assembler code for that processor. I can still remember (or figure out in my head) probably 80% of the instructions for those processors. And I thought the 8080 had a limited set of registers to work with Laughing (remember when you could buy a 2mhz Z-80 AND the instruction book for it for $149? )

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
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