Page 1 of 1

A project from hell!

Posted: Fri Jul 17, 2015 1:07 am
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.

Re: A project from hell!

Posted: Fri Jul 17, 2015 8:36 am
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.

Re: A project from hell!

Posted: Mon Jul 20, 2015 6:09 pm
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.

Re: A project from hell!

Posted: Tue Jul 21, 2015 12:03 pm
by Benj
This blog post should help and has examples.

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

Re: A project from hell!

Posted: Wed Jul 22, 2015 7:35 pm
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.

Re: A project from hell!

Posted: Thu Jul 23, 2015 9:56 am
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 371 times

Re: A project from hell!

Posted: Sat Jul 25, 2015 4:12 pm
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!

Re: A project from hell!

Posted: Mon Jul 27, 2015 10:11 am
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.

Re: A project from hell!

Posted: Mon Aug 03, 2015 7:06 pm
by 407charles
Thanks a lot!