Dual Channel Temperature Logger

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Dual Channel Temperature Logger

Post by JohnCrow »

My latest project is a 2 channel temperature logger with rs232/USB connectivity
The LM35 is a 3 pin IC with 10mV/°C output. This application is usable over the range 0°C to 100°C

1.) Introduction.

This project was started to develop a temperature logging instrument based around a LM35 integrated circuit.
The hardware will be provided by using the Matrix Multimedia EB006 Multi-Programmer and associated E-Blocks.
A modular approach will be used to allow for future expansion on both hardware and software.

2.) Required Hardware.

1 x EB006 – Multi-Programmer (With 4MHz or 20MHz xtal)
1 x EB014 – Keypad Board
1 x EB016 – Prototyping Board
1 x EB037 – Card Reader Board
1 x EB039 – USB232 Board
1 x Custom Made 4x20 LCD Display Board
1 x Matrix Power Supply
2 x D-Type Ribbon Cables

2 x LM35 Integrated circuits
1 x 18F4550 PIC
1 x SD Memory Card

Connecting wires

3.) Design Brief.
The instrument will be designed to have the following functions.
• Simultaneous display of 2 independent temperatures.
• Record the temperatures to a SD card using a programmable interval.
• Ability to read the temperature outputs by PC, using the USB port and HyperTerminal.


4.) Hardware Setup.
The programmer and E-Blocks are connected as follows
Port A – Memory Card Reader Board
Port B - Custom LCD Display Board
Port C – USB232 Board
Port D Keypad Board
Port E Prototype Board with LM35 IC’s

Power is wired to the boards as required using thin coloured wire.

5.) Software.

The software will be developed using Flowcode 4.
The following will outline the operation of the various sections of the program.

The program has been developed using macros, this is to both simplify the program layout and to allow ease of future expansion.

Serial_Setup:

This sets up the HyperTerminal screen by clearing, and sending the cursor to the home position.

Serial:

Outputs data to the usb port using the USB232 board.
Normal ascii esc codes are used to format the data positions on the screen.

SD_Setup:

This sets up the SD card in the following way

Check if a card is present

Check if file already exists. If yes delete old data file, the set up a new file
Write header data to file.

Keypad:

Reads the delay value from the keypad.
Up to 3 digits can be entered. If less than 3 are needed, terminate entry with #

Set_Min_Max:

Takes a snapshot reading of ADC0 & ADC1 and sets min & max to these values before starting the main program loop. These are the start values which are used on reset.
Temp1:

Reads input from ADC0 (Port E - Bit 0)

Uses the ADC function to read the output of the LM35.
The output is 10mV / °C

Temperature is calculated as follows.
Read ADC0 as voltage (Float)
Temp1 = fmul(ADC0, 500)

This is then converted to a string value to allow both display on the LCD and to be sent top the USB port.

Temp1_s = FloatToString$(Temp1)

The data is then just sent to the LCD with normal Flowcode commands.
To display the degree sign print ascii 178 is used.
This may differ to different makes of display, and is in fact different to the standard Matrix 2x16 LCD E-Block.

Temp2:

Reads input from ADC1 (Port E - Bit 1)
Works in the same way as Temp1

Main:

This is the main part of the program.

Initialise Variables
Setup LCD
Call Serial_Setup
Call Keypad - Read in the delay needed. Enter in seconds. 0 if no delay
Call SD_Setup - Configures the SD card
Call Set_Max_Min - Sets start values for max & min temperature
Clear LCD

Main loop
Call Temp1
Call Temp2
Write temp values to data card
Call Serial
End Main Loop
On error function for data card error – Halts program executio


Hardware Configuration
Temp Sensor.jpg
Temp Sensor.jpg (50.22 KiB) Viewed 12024 times
Flowcode File
Dual Channel Logger V1 - 18F4550 - 20MHz.fcf
(42.66 KiB) Downloaded 854 times
Hope the attached text will explain how I tackled the programming.
Also I found the Type 4 SD cards set up quite a lot faster than the type 2 cards (Which is how it should be :) )
However i did initally have problems getting them to work, and had to add a delay statement in the FAT16 macro
See below

http://www.matrixmultimedia.com/mmforum ... f=2&t=7848

Further Enhancments

1. Adding the gLCD e-block would allow more information to be displayed, i.e. the max-min temps. However I dont have one of these at the moment, however it is on the list.

2. A 3rd sensor cound be added without too much difficulty, however again, the gLCD would be certainly be needed then to display all 3 temps together.

Im sure members could come up with ideas I have not thought about yet too, so suggestions will be welcomed.
1 in 10 people understand binary, the other one doesn't !

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

Re: Dual Channel Temperature Logger

Post by Eric »

Hello John,

Nice work, very interesting application.
I made a similar program some time ago and therefore I would like to ask you 2 questions on this.

1) Did you already tried to log your data over a prolongued period of time ( lets say 2 day's ?)
In the beginning I also used the "append to file" method to add data to the logfile, but after some time the main program gradually slowed down so hard that it almost came to a standstill.
I had to deviate to the "write sector" method, which is more complicated but which is much faster and cured the problem.

2) It turned out to me that neighter the "append to file" neighter the "write sektor" method is errorfree.
See my previous post: http://www.matrixmultimedia.com/mmforum ... =30&t=7888
Until now, I wasn't able to find a solution for this. Fat16 and FAT32 are producing different but reproducible errors: the data gets overwritten after a prolongued time of logging. Did you encountered the same errors?

Best regards,

Eric

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Dual Channel Temperature Logger

Post by JohnCrow »

Hi Eric

No I've not tried rubnning it for more than an hour or so.
This was the first time Ive used the SD card e-block, apart from a simple test program..

It would be interesting to try a long logging period as is, and the update the SD card routine to use the write sector method and see how it performs over the same period.
Thanks for the comments
1 in 10 people understand binary, the other one doesn't !

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: Dual Channel Temperature Logger

Post by Benj »

Hello,

Let me know how you get on. I was under the impression that my latest version of the component had fixed all the problems.

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

Re: Dual Channel Temperature Logger

Post by Eric »

Hello Ben,

Do you mean by last component the one mentioned in this post: viewtopic.php?f=29&t=7461&p=19498#p19450
or is there in the meantime a newer version?

Best regards,

Eric

Post Reply