A project from hell!

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

Moderator: Benj

Post Reply
407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

A project from hell!

Post by 407charles »

I need to develop a high temperature thermometer to supervised a steam generator process. I will need to use a thermocouple type K to display temperatures over 500 degrees, in order to get accuracy I will use the MAX6675 and atmega 328 microcontroller; the only problem I'm having is with the SPI and I2C communication protocol. unfortunately there is not and example in detail about this topic. Can somebody help me? I tried to use the digital temperature component in the simulator without success. I can not make the program to display the temperature. The way I'm trying is by reading the byte and manipulate it mathematically to display the temperature. This is the way the MAX6675 works, is a 12 bit digital temperature sensor with cold compensation and it works with the SPI communications protocol, the resolution is 0.25 C! how can I make this work? I will infinitely appreciate the help! Thanks a lot.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: A project from hell!

Post by LeighM »

I suggest that you use either the SPI Master or CAL SPI Flowcode component.
Write your own GetTemperature macro that will need to first use a port pin to set CS low, then call SPI GetChar twice.
The first byte is the high byte, the second is the low byte of the 16 bit result.
Shift this result 6 bits right to get the temperature in deg C.

407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Re: A project from hell!

Post by 407charles »

Thanks a lot for your reply. Could you built a small example? I'm not very familiar with programming and it's hard to picture what you said. I will appreciate your help.

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: A project from hell!

Post by Benj »

This blog post should help and has examples.

http://www.matrixtsl.com/blog/simplifie ... c-and-spi/

407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Re: A project from hell!

Post by 407charles »

Thanks For your reply. I did my first attempt and I got some results but there are not the right bits. I'm using the arduino uno. I connect all my hardware and I'm able to see some data read out in the display. I'm not sure of how to manipulate the variable to store the 16 bit data. The temperature data of 12 bits is stored form bit 3 to bit 14. the bit 15 is always zero (according with datasheet). I'm uploading my program and some information such as datasheet and C-code from hardware vendor. Could you help me please? Anything will help.
Attachments
Max6675code.txt
Here is a C code from manufacturer for testing.
(1.05 KiB) Downloaded 285 times
MAX6675.pdf
MAX6675 Datasheet
(130.01 KiB) Downloaded 326 times
SPI.fcfx
My first attempt.
(8.67 KiB) Downloaded 297 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: A project from hell!

Post by Benj »

Hello,

I have modified your program so that it should read in the temperature and display it as a raw value. The raw value is then converted to a temperature and shown separately.

You may need to check that your chip select pin is C0 as I have guessed. If it's not then you will need to change the pin connection in the read macro. If it is then it's probably a good idea to get rid of the output icons in the main.
SPI.fcfx
(9.18 KiB) Downloaded 364 times

407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Re: A project from hell!

Post by 407charles »

Thanks a lot Benj, the project's result was impressive. I did only 2 changes: to implement two time delays in tho the macro GetRawTemp to be able to read the SPI data. Looks like the scan time was faster than the MAX6675 response and the data was stuck in only one value and convert the RealTemo to F degrees by using RealTemp = RealTemp * 9/5 + CAL wich is a calibration variable which is 32 but it can be changed to match a thermometer; In my case, after done with the project I compared the result with an expensive Fluke hand held thermometer to check the final result and it was just two degrees of because of the difference in sensor manufacturers. The result was as good as a Fluke professional hand held thermometer. I could not achieve this without your expertise. I really appreciate your time and concern about this issue. I got a couple questions for you, I understand clearly how you manipulate the double word data in the macro, but this .Return | .MSB << 5 I did not. Could you explain? The second question is that bit 2 in the MAX6675 flags when the thermocouple is or not present, this is a good feature to let you know if the sensor is working. I need to get the value of bit two in a Boolean variable, 0 means not thermocouple attach and 1 is thermocouple present. Do you have an idea of how can I achieve this? Again, thanks a lot for implement your magic in my project! There is no doubt that Flowcode is amazing!
Attachments
Arduino Thermocouple SPI 2.fcfx
(9.54 KiB) Downloaded 369 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: A project from hell!

Post by Benj »

Hello,

Thanks for letting us know how your getting on, glad your having some good results.
.Return = .LSB >> 3
.Return = .Return | .MSB << 5
This code basically takes the lower 8 bits and shifts them down so that the data starts at bit 0 of the return variable.
The second line then adds the rest of the data from the second byte, as this data starts at bit 0 we need to shift it up so it correctly aligns with the least significant byte data. 8-3 = 5.

To read in the status of the thermocouple simply create a new global variable called ThermPresent and in the calculation at the end of the GetRawTemp macro add this line.

ThermPresent = (.LSB & 0x04) >> 2

This should give you the value 0 or 1 in the ThermPresent variable.

407charles
Posts: 122
Joined: Thu Jun 26, 2014 12:01 pm
Has thanked: 41 times
Been thanked: 19 times
Contact:

Re: A project from hell!

Post by 407charles »

Thanks a lot!

Post Reply