Flowcode and onewire temperarture sensor

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

Moderators: Benj, Mods

titi
Posts: 14
Joined: Mon Dec 04, 2006 7:27 am
Location: FRANCE
Contact:

Flowcode and onewire temperarture sensor

Postby titi » Mon Dec 04, 2006 2:27 pm

Hello, i would like to make a simple thermometer, using a DALLAS Onewire temperature sensor DS18s20 connected to RA5 on a Pic 16F877A and to display temperature on a 2X16 LCD connected to port B using Flowcode and eventualy c code inserted.

Thank you a lot if someone can help in this project because i don't know anything in c code and i am sure flowcode can do this.

Mark
Posts: 209
Joined: Thu Oct 19, 2006 11:46 am
Location: Bakewell, UK
Has thanked: 20 times
Been thanked: 16 times
Contact:

Postby Mark » Mon Dec 04, 2006 3:34 pm

Bonjour,

I like your choice of device, I have just looked up the data sheet and an effectively two wire connection is interesting (one wire if common earth chassis). However, I would not (personally) write the routines in Flowcode (good as it is) as its serial data handling is not that well documented. The communications protocols for the device look complex with a 9 bit digital temperature value and a 48 bit unique identifier code.

Flowcode (v2 anyway) 'expects' temperature data to come in as an analog signal for 10 bit resolutuoin ADC conversion.
Go with the Flow.

User avatar
Steve
Matrix Staff
Posts: 3073
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 87 times
Been thanked: 387 times
Contact:

Postby Steve » Mon Dec 04, 2006 4:19 pm

I'm keen to get a one-wire interface available within Flowcode, so watch this space... But we are committed to a number of other projects at the moment, so it is not imminent.

(if anyone has code and/or suggestions for a one-wire interface, please email me).

User avatar
Steve
Matrix Staff
Posts: 3073
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 87 times
Been thanked: 387 times
Contact:

Postby Steve » Tue Dec 19, 2006 11:18 am

I know of two Flowcode users who are attempting to interface with this device, and I think it would be great for all of our users if they shared their findings via this forum.

We also plan to create some Flowcode code (or even a component) that allows control of 1-wire interface devices - we'll be looking into this soon after Xmas.

Until then, this is one way. Flowcode V3 uses the C compiler BoostC, and this compiler comes with a number of libraries - including a 1-wire library. To use this, you need to include the appropriate header file (the best place is in the "definitions" part of the "supplementary code" window) and add the library file to the parameters line of the linker (in the "compiler options" window).

Put something like the following into the "definitions" section of the "supplementary code" window:

Code: Select all

//definition for the OO port and pin
#define OO_PORT PORTB
#define OO_TRIS TRISB
#define OO_PIN  6

volatile bit oo_bus      @ OO_PORT . OO_PIN;
volatile bit oo_bus_tris @ OO_TRIS . OO_PIN;

#include "D:\Program Files\SourceBoost\include\oo.h"


Then add the oo.lib file reference to the "parameters" box of the "linker" section in the "compiler options" window. My parameters are as follows (the only change from the default is the addition of "oo.pic16.lib"):

Code: Select all

-ld "D:\Program Files\SourceBoost\lib" libc.pic18.lib flowcode.pic18.lib oo.pic16.lib "%f.obj" -t PIC%p -d "%d" -p "%f"


Once you have done this, you can access the functions using a 'C' icon, for example:

Code: Select all

oo_busreset();
FCV_DATA = oo_get_data();


For a complete list of the available functions, see the "oo.h" file.

That may serve to get the ball rolling...

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

Postby Mikat » Tue Dec 19, 2006 8:15 pm

The 1-wire library works,i have it tested today,but i dont know yet how it handles the negative temperature values,maybe it works if the data variable in in int value...
The DS1820 sends data in two bytes,first indicates is the temp negative or positive and last is the temp valueX2.
And at least in slow clock frequencys,the code need edit in the read macro,there is too long delay between the pin release for hi impedance and the port read.
The delay is 20Βµs,but Maxim datasheet says timeslot max value 15Βµs,and at 4MHz code does not work untill i lower that value to 10Βµs,maybe it work ok higher clock...

There is example in change in asm code..
--------------------------------------------------------------------------------
oo_rx_byte_00000
; { oo_rx_byte ; function begin
BCF STATUS, RP0
BCF STATUS, RP1
CLRF oo_rx_byte_00000_1_counter
CLRF oo_rx_byte_00000_1_data
label268437722
MOVLW 0x08
SUBWF oo_rx_byte_00000_1_counter, W
BTFSC STATUS,C
GOTO label268437723
BCF gbl_oo_bus,0
BSF STATUS, RP0
BCF gbl_oo_bus_tris,0
NOP
NOP
NOP
NOP
BSF gbl_oo_bus_tris,0
MOVLW 0x01 <----------------------- that is 2 in original code,need to change 1 at least in 4MHz
BCF STATUS, RP0
MOVWF delay_10us_00000_arg_del
CALL delay_10us_00000
MOVF oo_rx_byte_00000_1_data, W
MOVWF CompTempVar353
BCF STATUS,C
RRF CompTempVar353, W
MOVWF oo_rx_byte_00000_1_data
BTFSC gbl_oo_bus,0
BSF oo_rx_byte_00000_1_data,7
INCF oo_rx_byte_00000_1_counter, F
GOTO label268437722
label268437723
MOVF oo_rx_byte_00000_1_data, W
; VAR_LIFETIME_BEGIN:$ret Id:0x100008D7
MOVWF CompTempVarRet352
RETURN
; } oo_rx_byte function end
----------------------------------------------------------------------------

The commands goes

oo_start_conversion(); ----------------Gives the skiprom and convert t commands,the sensor starts conversion
Delay like 500ms --------- Could probably be lot shorter,havent tested
oo_read_scratchpad(); --------------Reads seconnd (and first?) bytes in scratchpad
FCV_DATA = oo_get_data(); -----------Moves the data to flowcode DATA variable.
oo_busreset(); -----------Resets the sensor

And thats it...
If anybody have anything question,you can mail me,i am pretty novice myself,but if i can i help,i make the little code,that reads the temp on ds1820 chip and show it in lcd display,hopefully a get it ready at this week,if somebody is interested the mail me and i sent the code...

User avatar
Steve
Matrix Staff
Posts: 3073
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 87 times
Been thanked: 387 times
Contact:

Postby Steve » Thu Dec 21, 2006 9:43 am

That's great, Mika.

We have ordered some of these chips (plus a few other 1-wire devices) and will have a play with them after Xmas. We will look into why the code doesn't work at 4MHz.

Please send the code to me - it will be helpful for us.

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

Postby Mikat » Thu Dec 21, 2006 3:44 pm

Sounds nice...
Are you planning to do the component/code that there is possible to use multiple sensors,both ways,in the same data bus and the different data bus?

I played little more of the code what the boostc library does,and unfotunnetly seems that it reads only the first byte on the scratchpad,witch means that it wont read the sign byte,so there is no way you can tell is the temp value positive,or negative...
Or at least i cant get it reading the second byte.
I have little code,witch read the data on ds1820,and shows the temperature on lcd display,but it cant tell is the temp - or +.
Steve,would you still like to have it?
The reason why the code does not work at 4MHz,is that the delay after the datapin is released in hi impedance state,its too long,the read slot is 15Βµs after the pin is released,and there is 20Βµs delay after the goes hi...
It might work like 20MHz because the other commands take 5 times less time,so the whole read "slot" is shorter

User avatar
Steve
Matrix Staff
Posts: 3073
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 87 times
Been thanked: 387 times
Contact:

Postby Steve » Thu Dec 21, 2006 3:53 pm

I'm not sure what the component or code will be capable of until we have had a play. And yes, please send the code you have.

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

Postby Mikat » Thu Dec 21, 2006 4:21 pm

Ok,ill sent the code for you..
Multiple devices in same datapin is pretty simple,you just have to sent the 48 bit unique rom code beside the skiprom command..
But if i have understand right,the code need to be read at the device first..
But i hope that the code allows multiple devices in one pic,so its possible measure more than one temperature at one pic...


titi:
Ill send you my code,you just need to change the port and pin defines,in the supplementary code,and edit the asm code,as i showed above,at least if you use low clock frequencys,but the problem is that at least yet,i havent figured hiw to read the sign byte..
If you have some question,send private message,i am not home,so i cant read my e-mail..

titi
Posts: 14
Joined: Mon Dec 04, 2006 7:27 am
Location: FRANCE
Contact:

Postby titi » Mon Dec 25, 2006 8:37 pm

Hello Mikat, very good, i am trying your file under FC2 so i will tell you more very soon.
I wait to have FC3 to see what is possible with boost c.

titi
Posts: 14
Joined: Mon Dec 04, 2006 7:27 am
Location: FRANCE
Contact:

Postby titi » Wed Dec 27, 2006 1:13 pm

Hello everybody, i have tried and adapt the work of Mikat to my project under Fc2 and it works fine. So thank you again Mikat.
I am still waiting to receive Fc3. So i will try the work of Mikat under Fc3 later. Using Fc3 and boostc, is it ok with the sign for negative temps ?
If one of you has progressed in this way, please post in this forum or in private message.
Thank you a lot everyone for helping in this project.

Ps: Steve, What about a onewire component in Fc3 ?

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

Postby Mikat » Thu Dec 28, 2006 8:14 pm

titi wrote:Hello everybody, i have tried and adapt the work of Mikat to my project under Fc2 and it works fine. So thank you again Mikat.
I am still waiting to receive Fc3. So i will try the work of Mikat under Fc3 later. Using Fc3 and boostc, is it ok with the sign for negative temps ?
If one of you has progressed in this way, please post in this forum or in private message.
Thank you a lot everyone for helping in this project.

Ps: Steve, What about a onewire component in Fc3 ?


Nope,at least i havent got the negative temps working with boostc...
And the fc2 file dont work with boostc compiler..
And i dont have time to work with the 1-wire now,so maybe we had to wait that steve makes some code witch works..

By the way,have anybody else notice the problem with 4MHz settin with fc3,when i use 16f877A and 4MHz xtal,i cant get the lcd display working on 4MHz chip settings,on 3,2768MHz and 8MHz settings the display works fine,but not on 4MHz...

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

Postby Mikat » Sat Jan 06, 2007 9:50 am

Hi all..

Thanks to great help of Steve,i finally have a working 1-wire code for flowcode3,at the moment it works only the ds1820 temp sensor,but it should be possible to get work in other devices...
The code uses pretty direct the boostc compiler libraries,witch can be found in http://www.lika.be/content/category/5/14/30/
Just small editing,and copied in flowcode supplementary code,and then the fc3 program,witch show the temp in lcd display...
At the moment the program works only 1 sensor,but it should be possible to get it work multiple sensors in same bus,but i dont have time for that now,but i tried to get code work multiple devices in different data pin...
I havent tested the code other than 4MHz freq,but it should work at least in 8MHz,faster freq it might need to adjust the "nop":s in c code..



So if anybody needs 1-wire temp sensor code for fc3,please send me pm...
Steve,would you like have the code,it uses c language,so it might help you for the 1-wire component?
And once again for great help Steve.

Some update..
I play little more about that code,and get it working with 2 sensors,connected in portb bit 0 and 1...
So it seems pretty easy to get work in multiple sensors,in different pins..
There is probably easier way to get those multiple sensors in different pins working,but i leave i to Steve...
By the way steve,when i put in the code the print ACSII and on the character box Β° (degrees) sign,it simulates fine in flowcode,but in harware it prints -.
Is that bug in flowcode,or my lcd display?

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

Postby Benj » Mon Jan 08, 2007 10:33 am

The anomaly with your ascii character is probably due to the fact that the LC-Displays use a similar but different ascii character set then that of windows. To display your degrees symbol you have to use the hex value 0xDF.

User avatar
Steve
Matrix Staff
Posts: 3073
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 87 times
Been thanked: 387 times
Contact:

Postby Steve » Mon Jan 08, 2007 11:07 am

Great work, Mika. And yes, please send the code to me (although it will be a while until I can devote any time to creating a component within Flowcode).

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

Postby Mikat » Mon Jan 08, 2007 11:33 am

steve wrote:Great work, Mika. And yes, please send the code to me (although it will be a while until I can devote any time to creating a component within Flowcode).

Ok,ill sent the files for you when i get home.
At least i dont have hurry about the component,the code is pretty easy to use,just couple macros in c-block..
But i could be easier to "create" the code,now all the macros are written in supplementary code,and need to copy/paste every new program...

And with multiple sensor i just change everything in macro,oo to oa,and add the oa macros in supplementary code in same way like the oo macros,so there is probably easier way to read different pin in same code,every variable etc. probably dont need to rename,and waste code and memory...

Ben said that i had to use hex 0xDF,on my problem with lcd,how can i use it and other character,on character map,is it macro->lcd display-> command and the character value,or how?

And you guys are talking about fc3.1,is it just a bugfix,or is there some new properties?

titi
Posts: 14
Joined: Mon Dec 04, 2006 7:27 am
Location: FRANCE
Contact:

Postby titi » Tue Jan 09, 2007 8:50 pm

hello mikat, to print the sign degree, use print ASCII '223', i have tried and it works fine.

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

Postby Benj » Wed Jan 10, 2007 10:58 am

The latest Flowcode V3 update is a crutial update as it fixes a lot of bugs and also provides a base for future updates to patch into. The current release is not capable of being patched.

kalain
Posts: 4
Joined: Mon Nov 27, 2006 10:22 pm
Contact:

Postby kalain » Sun Mar 11, 2007 5:40 pm

Hi,

I have tried FC3.1.0.31, thinking to find a DS1820 device instead of analog thermometer. :cry:
Is it planned to add a DS1820 component for next update ?
Or do I have to add some code as suggested below ?

Best regards

User avatar
Steve
Matrix Staff
Posts: 3073
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 87 times
Been thanked: 387 times
Contact:

Postby Steve » Mon Mar 12, 2007 10:34 am

We currently have no plans for a DS1820 component. We may offer a "one-wire" component in the future, but we are currently committed to some other projects.

echase
Posts: 426
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times
Contact:

Postby echase » Tue Jun 12, 2007 4:32 pm

I presume you know already but Maxim's website contains a number of software routines for reading a one wire interface, such as http://www.maxim-ic.com/appnotes.cfm/ap ... umber/2420

These are only partial routines which will need adaptation to FC3.

echase
Posts: 426
Joined: Mon Jun 11, 2007 11:55 am
Has thanked: 49 times
Contact:

Postby echase » Wed Jun 20, 2007 6:23 pm

http://www.microchipc.com/sourcecode/#ds1821 contains some circuits and C code for DS1821 sensors. Not sure how similar to the DS 1820 they are. Mine are DS18B20.

User avatar
Steve
Matrix Staff
Posts: 3073
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 87 times
Been thanked: 387 times
Contact:

Postby Steve » Thu Jun 21, 2007 8:35 am

We will soon have a 1-wire component, which will probably include functions specific to reading this sensor.

majerv
Posts: 17
Joined: Mon Aug 27, 2007 4:27 pm
Contact:

Re: Flowcode and onewire temperarture sensor

Postby majerv » Mon Aug 04, 2008 12:12 am

Hi All!

I would use a DS1821 temp sensor with a 16F877a PIC. I've downloaded the onewire beta component example to the PIC, but it doesn't work. I know there are differencies in the DS temperature sensors, but I couldn't find how to solve the problem.
Has anybody any idea?

Thanx, gustaw

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

Re: Flowcode and onewire temperarture sensor

Postby Benj » Mon Aug 04, 2008 9:18 am

Hi Gustaw

Try using a different I/O pin, When testing with pin RA0 with a 16F877A I could not get the one wire functions to work but as soon as I changed the I/O pin to RB0 the code started working. You can change the connections using the custom component properties.