Multi One Wire Example

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

PINTO
Flowcode v5 User
Posts: 71
Joined: Fri Nov 03, 2006 2:28 pm
Location: RSA
Been thanked: 1 time
Contact:

Multi One Wire Example

Post by PINTO »

Hi Benj,

I' working with the Multi One Wire Example and can't read more than 2 devices.
Pic 877a, 8Mhz, Delay 2, 4*DS18B20.
Please see the attached code. Were did I go wrong.


Regards



Pinto
Attachments
Multiple One Wire Example.fcf
(11.5 KiB) Downloaded 1196 times

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: Multi One Wire Example

Post by Eric »

Hi,

I have the same problem: up to 2 devices are recognised, any additional device is not.
The function "GetDeviceCount" always returns 2 if more than 2 devices are connected.
5 X DS1820
PIC16F877A
8 Mhz
snap055.jpg
snap055.jpg (27.6 KiB) Viewed 24588 times
Please advice.

Eric

PINTO
Flowcode v5 User
Posts: 71
Joined: Fri Nov 03, 2006 2:28 pm
Location: RSA
Been thanked: 1 time
Contact:

Re: Multi One Wire Example

Post by PINTO »

Hi Eric,

Thanks for sharing your info.
Are you using a simulator or the real devices on your design?
I used a simulator. But I don't think the problem is on the simulator because I loaded a similar software from another compiler and detected 10 devices complete with serial no's, temps and alarm status report.
I think that the problem could be on the timing rotines on the Component software.
I'm wainting for the MM support team to comment on the subject.

Regards




Pinto

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Multi One Wire Example

Post by Sean »

Here is a new 1-Wire custom component with a possible fix for the scanbus() function, allowing more than two devices to be detected.
Custom_Code_OneWire.c
(16.88 KiB) Downloaded 962 times
We are not currently able to test this component, but if anyone wants to give it a try we would be interested to know the results. A tested version should be available in the next few days.

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: Multi One Wire Example

Post by Eric »

Hi Sean,

For your information: I tried your new custom_code on the Multiple One wire example in the beta components page on my develloper board.
Attached were 5 DS1820 sensors in parallel with all the data lines pulled up to 5 volt with 4k7.
Unfortunatly the result is the same: 2 devices detected.
snap025.jpg
snap025.jpg (9.84 KiB) Viewed 24348 times
I don't suspect the hardware because I compiled the same functionality with another compiler and there were all 5 sensors detected.

Regards,

Eric

PINTO
Flowcode v5 User
Posts: 71
Joined: Fri Nov 03, 2006 2:28 pm
Location: RSA
Been thanked: 1 time
Contact:

Re: Multi One Wire Example

Post by PINTO »

Hi Sean,
Thanks for your info.
I've tried it as well and only detected 2 devices.

Thanks


Pinto

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Multi One Wire Example

Post by Benj »

Hello

I have just tried the attached code with the Dallas DS1820 one wire sensors from Farnell code 972-4761.

The code is correctly detecting up to 4 devices (thats all I have) and then displaying the temperature of the devices.
Attachments
OneWire.zip
(6.85 KiB) Downloaded 1367 times

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: Multi One Wire Example

Post by Eric »

Hi Benj,

I tried your code, but now the result is always ERR255. Meaning 0 devices detected whatever how many devices are connected.
My devices are connected to portA, therefore I changed the customcode properties to portA.
But to eliminate errors, I also tried it on portB like you did, but the result is the same.
Please advice.

Regards,

Eric

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Multi One Wire Example

Post by Benj »

Hello

I was receiving the Err255 message when trying to use pin RA0, Therefore I moved to Pin RB0 and the one wire bus started working.

I have just retested the code using parasitic and non parasitic power and have been able to detect all 4 of my devices.

Please could you provide a little more info regarding your setup:

Processor - Eg 16F877A
Clock Speed - Eg 19.6608MHz
One Wire Pin - Eg RB0
Exact product code of one wire sensor - Eg DS1820
Data pull up resistance - Eg 4.7K
Parasitic / Normal power mode
Anything else you can think of

Also would you mind attaching your program to the forum post so I can use your exact hardware setup and your program to do the testing.

PINTO
Flowcode v5 User
Posts: 71
Joined: Fri Nov 03, 2006 2:28 pm
Location: RSA
Been thanked: 1 time
Contact:

Re: Multi One Wire Example

Post by PINTO »

Hi Ben,
If you want to use port A you should turn off the ADC and make the portA as a digital I/O.

ADCON1 = $07 'Turn PORTA as Digital IO.
ADCON0 = 0 'Turn off all A/D's

I'm still battling, trying to detect more than 3 devices.
One thing I noticed is that I don't see where you save the information from the OO's into EEprom?

Regards



Pinto

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: Multi One Wire Example

Post by Eric »

Hello Benj,

My hardware is a developper board from Mikroelektronika:
UNI-DS3, see http://www.mikroe.com/en/tools/unids3/
This board works fine for me. The only changes I have to make is to connect the lcd to portD instead of PortB.
snap033.jpg
snap033.jpg (10.82 KiB) Viewed 24071 times
My setup is this:

Processor: 16F877A
Clock Speed: 8.000000 MHz
One Wire Pin: RA0
One wire sensor: DS1820
Normal power mode
5 sensors in parallel with all datalines connected to +5 volt via 1 resistor of 4k7
Config word: 0x2007,0x3f3a


In my program I use this code to detect the number of sensors:
//Macro implementations

void FCM_Sensor_Init(char FCL_REQUIRED)
{
//Sensor Test and Initialisation

//Scan OW bus
//Call Component Macro: Custom(0)::oo_scanbus
FCD_Custom0_oo_scanbus();


//Get number of sensors
//Call Component Macro: Real_Sensor_Count=Custom(0)::oo_get_devicecount
FCV_REAL_SENSOR_COUNT = FCD_Custom0_oo_get_devicecount();


//Check if all sensors are online
//Decision: Real_Sensor_Count <> Required_Sensor_Count?
if (FCV_REAL_SENSOR_COUNT != FCV_REQUIRED_SENSOR_COUNT)
{
//Error 10
//Call Macro: Error(10)
FCM_Error(10);


}


}

I call the macro with the parameter "number of installed and required sensors" and compare the result with the " real found number of sensors".
REAL_SENSOR_COUNT is 0 if no sensor is detected, 1 if 1 sensor is present and 2 if 2 sensors are detected. From than on, the return is always 2 whatever sensors are added. If I change the customcode properties to portb and trisb and connect the sensors to portB, this still works.
If I use your code OneWire.zip from your last message on Wed Jul 30, 2008 11:11 am, I always get Error255 as return, whatever I connect it to portA or portB

I hope this helps.
Thanks for trying.

Eric

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: Multi One Wire Example

Post by Mikat »

At last i tested the code too..
The results was that the code works only the portb pin 0,i tried other pins on port b,but no success,and same results on port C,but i didnt test on pin 0 on other ports..
Guys,do you have any idea why?
The code dont report more than 2 devices...
The temp calc is probably on the ds18b20 device,but thats not problem,the only difference is the temp calc...
The devices what i use is ds1820,direct from maxim...

JCMB
Posts: 22
Joined: Wed Feb 08, 2006 3:15 pm
Location: St Etienne, France
Been thanked: 1 time
Contact:

Re: Multi One Wire Example

Post by JCMB »

J am french, sorry for my english.
After a lot of test, j found bugs in NEXT code.
Attached OneWireMultiDS.zip with: Custom_Code_1W_get_IDByte.c, that is custom_code.c modified with one macro added.
1WMultiDS.fcf for test.
OneWireMultiDS.zip
(10.23 KiB) Downloaded 861 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Multi One Wire Example

Post by Benj »

Hello JCMB

Please can I ask which bug you found and what you did to fix the problem. Does this relate to the multiple device detection problem. Also what does the function you added do to get around the problem.

JCMB
Posts: 22
Joined: Wed Feb 08, 2006 3:15 pm
Location: St Etienne, France
Been thanked: 1 time
Contact:

Re: Multi One Wire Example

Post by JCMB »

Hello Ben.
J used to read temps 8 x DS18 (5 x DS18S20 and 3 x DS18B20).
Only 2 to 4 DS18 were detected.It depend of wich DS18 were connected.
So j ad a macro called 1W_get_IDByte, 2 param (Num of the device and num of the byte to be return).
It return the byte of the lasered rom code stored in DevID.
J found that the pb was in macro oo_get_next_id()
"if (id[byte_index] && (1 << bit_index))".
This test always return 1 (id[byte_index] true, (1 << bit_index) true).
So j add a variable (char) bit_test and replace "if (id[byte_index] && (1 << bit_index))" by
bit_test = id[byte_index] >> bit_index;
if (bit_test & 0x01)
J also add 2 var : char lz_selected = 0; (Last zero selected)
char go_on = 0;

// use previous value
bit_test = id[byte_index] >> bit_index; //added JCMB 10/01/09
if (bit_test & 0x01)
{
val0 = 1;
}
else
{
val0 = 0;
lz_selected = counter; //added JCMB 10/01/09
go_on = 1; //added JCMB 10/01/09
}
After the end of the loop "for (byte_index = 0; byte_index < 8; byte_index++)" j add
if ((new_conflict == 0) && go_on) // (new_conflict == 0) AND go_on must be true
{
new_conflict = 1;
conflict = lz_selected ;
}

Now J detect 8 DS18, use the macro 1W_get_IDByte to read the FAMILY CODE, and so do automatic temps convert.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Multi One Wire Example

Post by Benj »

Hi

Ok thats great thanks for confirming the problem and providing the workaround. I will give it a go here and try and incorperate what you have done into the functionality of the one wire component.

JCMB
Posts: 22
Joined: Wed Feb 08, 2006 3:15 pm
Location: St Etienne, France
Been thanked: 1 time
Contact:

Re: Multi One Wire Example

Post by JCMB »

2 errors corrected in 1WMultiDS.fcf
Switch D0 erased (No use).
In macro TempToStr, bit 0 does'nt add 625 to rest.
Attachments
OneWireMultiDS.zip
(10.14 KiB) Downloaded 461 times

JCMB
Posts: 22
Joined: Wed Feb 08, 2006 3:15 pm
Location: St Etienne, France
Been thanked: 1 time
Contact:

Re: Multi One Wire Example

Post by JCMB »

Sorry J found an other bug in my 1WMultiDS.fcf.
In macro TempToStr, for DS18B20 and negative temperature, the resulte was
1 Β°C too low.
Attachments
OneWireMultiDS.zip
(10.2 KiB) Downloaded 532 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Multi One Wire Example

Post by Benj »

Great thanks for the updates. I will add your file to the main one wire example download if that is ok with you.

JCMB
Posts: 22
Joined: Wed Feb 08, 2006 3:15 pm
Location: St Etienne, France
Been thanked: 1 time
Contact:

Re: Multi One Wire Example

Post by JCMB »

Ok to add the file to the main one wire example download.
J made an other change in the macro TempToStr.
In the Custom_Code.c J rename CUSTOM_Dummy_Function() to ONEW_Dummy_Function() because of a conflict with other component.
Attachments
OneWireMultiDS.zip
(10.34 KiB) Downloaded 850 times

technoboy
Posts: 7
Joined: Tue Feb 15, 2011 3:51 pm
Contact:

Re: Multi One Wire Example

Post by technoboy »

how to read 64 bit rom code using 1 wire component oo_read_device ??
there is count variable and return byte.......how to store all 8 byte ?
plz help me......

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Multi One Wire Example

Post by Benj »

Hello,

This is from the one wire component help file.

oo_BusReset()
Resets all of the devices connected to the One Wire bus. Returns a 0 if succsessful and a 1 if no devices are present or reset.

oo_GetPadByte(byte index)
Returns a byte from the last read scratchpad at position index. The index byte can go from 0 - 8 to reference the 9 individual scratchpad bytes.

oo_Tx_Byte(byte data)
Transmits the byte data over the one wire bus.

oo_Rx_Byte()
Returns a byte from the one wire bus.

oo_ScanBus()
Scans the one wire bus for devices. Inserts the number of devices into a variable called num_devices. See Get_DeviceCount function. Returns a 0 if sucsessful and an error code if there was a problem.

oo_Get_DeviceCount()
Returns the number of devices connected to the one wire bus. Must be run after the ScanBus function.

oo_ReadDevice(byte Count)
Reads one of the devices detected using the ScanBus function. Loads the remote scratchpad from the device into the local buffer. See the GetPadByte function.

DS1820_Start_Conversion()
Specific to the DS1820 and DS18B20 devices. This function resets all of the one wire devices on the bus and then skips the ROM address and starts a temperature conversion. Returns a one if the devices time out without finishing the conversion.

DS1820_Read_Scratchpad()
Specific to the DS1820 and DS18B20 devices. This function must only be called if there is only one device on the bus as it skips the ROM address. If there is more then one device on the bus then the ScanBus and ReadDevice functions must be used. Loads the remote scratchpad from the device into the local buffer. See the GetPadByte function.

DS1820_Get_Temp()
Specific to the DS1820 and DS18B20 devices. This function returns the integer value representing the temperature which is stored in the local buffer. The value returned represents the temperature in levels of 0.0625 degrees Celcius. Therefore if you get a value of 400 then the temperature is equivalent to 25 degrees C. An easy way to convert this into a readable value is to either devide by 16 and have an integer number or use the 32 bit floating point plugin and devide by 16 to get the temperature to within 0.0625 of a degree.

technoboy
Posts: 7
Joined: Tue Feb 15, 2011 3:51 pm
Contact:

Re: Multi One Wire Example

Post by technoboy »

Thanks benj,
I am using ds1990a.......... i just want to read 64 bit rom code and have to compare with already stored code in pic.
So which function to use ? is it oo_readdevice & oo_getpadbyte functions ?


Regards,
tanveer

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Multi One Wire Example

Post by Benj »

Hello,

scan bus - scan bus for devices.

read device - reads scratchpad from a detected device.

get pad byte - reads back a byte from the scratchpad.

technoboy
Posts: 7
Joined: Tue Feb 15, 2011 3:51 pm
Contact:

Re: Multi One Wire Example

Post by technoboy »

hello Ben,
Thanks for the reply :) ...... I tried but i am not able to read romcode of ds1990a :( . I am using pic16f877a and a single 1wire device (ds1990a) . Can you please show me a flowcode example file to read romcode and display it in lcd ?
Thank you

Post Reply