View previous topic :: View next topic |
Author |
Message |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
Pin Switching |
Posted: Fri May 15, 2015 7:38 am |
|
|
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: 1934 Location: Norman, OK
|
|
Posted: Fri May 15, 2015 9:45 am |
|
|
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
|
|
Posted: Fri May 15, 2015 3:29 pm |
|
|
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: 19549
|
|
Posted: Sat May 16, 2015 1:07 pm |
|
|
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
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Sat May 16, 2015 4:39 pm |
|
|
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: 19549
|
|
Posted: Sun May 17, 2015 12:26 am |
|
|
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.
Sometimes the simplest solution is just to keep it simple. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun May 17, 2015 4:47 am |
|
|
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
|
|
Posted: Mon May 18, 2015 10:21 am |
|
|
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 |
|
|
|