|
|
View previous topic :: View next topic |
Author |
Message |
Jody
Joined: 08 Sep 2006 Posts: 182
|
PIN definitions. |
Posted: Fri Aug 31, 2018 1:21 am |
|
|
Hello,
I have a something and don't know how to solve it.
What I want: 24 DS18B20 devices on their own I/O pin (demand from the customer).
One DS18B20 on a pin I can communicate with.
But when I want to use the same function to talk to another one, by changing the definition from the pin, this doesn't work.
What I have done (example is for 8 connections):
Code: |
typedef enum
{
PINA1 = PIN_A1,
PINB1 = PIN_B1,
PINB2 = PIN_B2,
PINB3 = PIN_B3,
PINB4 = PIN_B4,
PINB5 = PIN_B5,
PINB6 = PIN_B6,
PINB7 = PIN_B7
} ONE_WIRE_PINNEGIE;
ONE_WIRE_PINNEGIE ONE_WIRE_PIN; |
And make the selection to use like this:
Code: |
void set_onewire_pin_port(int port, int pin)
{
if(port == 0)
{
if(pin ==0)
{
ONE_WIRE_PIN = PINA1;
}
if(pin ==1)
{
ONE_WIRE_PIN = PINB1;
}
if(pin ==2)
{
ONE_WIRE_PIN = PINB2;
}
if(pin ==3)
{
ONE_WIRE_PIN = PINB3;
}
if(pin ==4)
{
ONE_WIRE_PIN = PINB4;
}
if(pin ==5)
{
ONE_WIRE_PIN = PINB5;
}
if(pin ==6)
{
ONE_WIRE_PIN = PINB6;
}
if(pin ==7)
{
ONE_WIRE_PIN = PINB7;
}
}
|
But this don't give me the results I expected. I see (on scope) that there is some communication, (pin toggles) but I never get something useful.
Is this method something the compiler doesn't know how to handle??
Or made I made a boohoo?
best regards,
Jody |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Fri Aug 31, 2018 1:55 am |
|
|
I haven't looked at your code, but it is not going to work.
You have to understand, that a input/output to a fixed pin, is basically a single instruction. Doing the same to a pin that is controlled by a variable, involves dozens of instructions. The compiler has to add the code to calculate the register address involved, and the bit involved. Result enormous loss of speed....
There have been several threads here in the past about using variables to control pin selection for one wire devices. The timing does not work when this is done. Instead you have to setup a one wire driver using a fixed pin number for each pin you want to use, then call these based on the selection:
<http://www.ccsinfo.com/forum/viewtopic.php?t=55325&highlight=one+wire+variable+pin>
A search here will find lots of other examples. |
|
|
Jody
Joined: 08 Sep 2006 Posts: 182
|
|
Posted: Fri Aug 31, 2018 2:31 am |
|
|
Ttelmah!!
Thanks... I was looking at the signals in both way's and I noticed that the timing was way off...
I am going to modify the code you used in the link you send...
my sensors are located at 3 ports....
Thanks again......!!!!!!!!!!!!! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9247 Location: Greensville,Ontario
|
|
Posted: Fri Aug 31, 2018 4:58 am |
|
|
comment.
I had one product with 4 DS18B20. The simple, easy, solid solution was to have a copy of the driver for each sensor. Yes, it takes up some extra codespace, but today's PICs have LOTS of memory ! Yes, it took time for me to type/cut/paste/search/replace the driver expecially with my bum finger,but the code is stable, timing is bang on. I understand the client's want for 1 sensor, 1 pin. It allows for easy wiring, a 3 terminal block per sensor, or just 2 if used in parasitic mode. It also makes field repairs easy and if one sensor fails it won't take out the whole system!
Jay |
|
|
|
|
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
|