Flowcode and onewire temperarture sensor
Flowcode and onewire temperarture sensor
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.
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.
-
- Posts: 209
- Joined: Thu Oct 19, 2006 11:46 am
- Location: Bakewell, UK
- Has thanked: 20 times
- Been thanked: 16 times
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.
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.
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
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:
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"):
Once you have done this, you can access the functions using a 'C' icon, for example:
For a complete list of the available functions, see the "oo.h" file.
That may serve to get the ball rolling...
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"
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"
Code: Select all
oo_busreset();
FCV_DATA = oo_get_data();
That may serve to get the ball rolling...
-
- Posts: 258
- Joined: Wed Nov 29, 2006 6:32 pm
- Location: Finland
- Has thanked: 7 times
- Been thanked: 36 times
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...
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...
-
- Posts: 258
- Joined: Wed Nov 29, 2006 6:32 pm
- Location: Finland
- Has thanked: 7 times
- Been thanked: 36 times
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
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
-
- Posts: 258
- Joined: Wed Nov 29, 2006 6:32 pm
- Location: Finland
- Has thanked: 7 times
- Been thanked: 36 times
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..
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..
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 ?
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 ?
-
- Posts: 258
- Joined: Wed Nov 29, 2006 6:32 pm
- Location: Finland
- Has thanked: 7 times
- Been thanked: 36 times
Nope,at least i havent got the negative temps working with boostc...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 ?
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...
-
- Posts: 258
- Joined: Wed Nov 29, 2006 6:32 pm
- Location: Finland
- Has thanked: 7 times
- Been thanked: 36 times
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?
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?
- 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:
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 258
- Joined: Wed Nov 29, 2006 6:32 pm
- Location: Finland
- Has thanked: 7 times
- Been thanked: 36 times
Ok,ill sent the files for you when i get home.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).
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?
- 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:
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
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.
These are only partial routines which will need adaptation to FC3.
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.
Re: Flowcode and onewire temperarture sensor
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
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
- 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: Flowcode and onewire temperarture sensor
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel