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

Pin Switching

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



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

Pin Switching
PostPosted: Fri May 15, 2015 7:38 am     Reply with quote

Hi Guys, Simple question:

This driver: http://www.ccsinfo.com/forum/viewtopic.php?t=28425

Has a #Define for the pin that will be used by the 1Wire code.

Id like to have multiple Sensors, so what can i do to reassign pins on the fly?

PIC18F87J50 Compiler Ver. on signature.

Thanks,
G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri May 15, 2015 9:45 am     Reply with quote

If they are all OneWire (OW) you don't have to change anything. You can have a
large number of OW sensors on the same bus.
_________________
Google and Forum Search are some of your best tools!!!!
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri May 15, 2015 3:29 pm     Reply with quote

It was just easier for me to switch pins rather than write a ROM search routine.
I have alot of extra pins but not much time to work on this.

in any case, pin switching to allow multiple pins to use a single function is something im still interested in knowing how to do.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19469

View user's profile Send private message

PostPosted: Sat May 16, 2015 1:07 pm     Reply with quote

The output_high, output_low, and output_float functions can all use a variable or a fixed name (provided you are using a reasonably recent compiler).
So just declare a variable - something like One_Wire_Pin. Make it global, and change the functions in the routines, to use this variable, rather than a fixed pin name. Then just set the variable to the pin you want to use, and call the functions.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 16, 2015 1:34 pm     Reply with quote

The one-wire timing can be thrown way off if you use a variable for the
pin number. It expands to many more instructions. See this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=40106&start=20
temtronic



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

View user's profile Send private message

PostPosted: Sat May 16, 2015 4:39 pm     Reply with quote

You can 'cheat' like I did, just 'double' the One Wire driver functions. Yes, it takes up a bit of extra code space, but like you I had lots of pins and physically wiring the sensors (temperature, in my case) was easier using 2 conductor cable (parasitic mode).
Each OW driver was specific to a pin/device. Since the original code was stable (no timing problems), the second driver worked just as well !

Pics seem to have LOTS of memory so it was easier to do it this way. 5 years later it still works.....


Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19469

View user's profile Send private message

PostPosted: Sun May 17, 2015 12:26 am     Reply with quote

It's also worth being aware that a simple 'output_high' instruction, expands about twenty times in size when a variable is used. This is why it is slower (PCM_programmer's warning), but also means that if the code is a simple sequence of a dozen highs/lows, it is often _smaller_ to just duplicate/triplicate the code.... Temtronic's suggestion.

I was going to give warning about timings and size , but decided to let you 'see' where the problems were yourself. Twisted Evil

Sometimes the simplest solution is just to keep it simple. Smile
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun May 17, 2015 4:47 am     Reply with quote

You can get a bit of both worlds by changing the 1-wire functions into macro's. This way you have to write every defined function only once which makes for easier maintenance. The compiler will expand each macro into duplicates with proven timing.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon May 18, 2015 10:21 am     Reply with quote

Hi all,
Thanks for the suggestions.

Thanks for the timing explanations on pin switching.
I was about to go with Temtronics suggestion until i read ckielstra's response.

I have no prior experience writing macros, if you guys have a link to a post showing how to do this, i can dig into it on my own. ive tried looking for it, but i dont really know what im looking for!

Thanks!
_________________
CCS PCM 5.078 & CCS PCH 5.093
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