data logger

27
Chapter 1 Abstract “MicroSD Atmega32 Data-logger” ABSTRACT Aim of this project is to present a way to store a large quantity of data into microSD card in files with FAT32 format. Here, ATmega32 is used for data collection and microSD interface. The data is received from in-build 8-channel ADC of ATmega32. One channel is used for reading temperature from

Upload: ridham-patel

Post on 27-Nov-2014

264 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Data Logger

Chapter 1Abstract

“MicroSD Atmega32 Data-logger”

ABSTRACT

Aim of this project is to present a way to store a large quantity of data

into microSD card in files with FAT32 format. Here, ATmega32 is used for data collection

and microSD interface. The data is received from in-build 8-channel ADC of ATmega32.

One channel is used for reading temperature from LM35 sensor and remaining

channels are used for simply reading voltages and storing them.

Page 2: Data Logger

This project can be used to interface 8 different sensors with ADC of ATmega32, similar

to the LM35 used here. The data is stored in CSV (comma separated values) format,

which can be read using a PC/Laptop with Microsoft Excel or other compatible software.

Chapter 2

Data-logger

Page 3: Data Logger

What is Data Logging?

The process of using a computer to collect data through sensors, analyze the data and

save it.

Data logging is commonly used in scientific experiments and in monitoring systems

where there is the need to collect information faster than a human can possibly collect

the information and in cases where accuracy is essential. Examples of the types of

information a data logging system can collect include temperatures, sound frequencies,

vibrations, times, light intensities, electrical currents, pressure and changes in states of

matter.

Applicaton of data-logging

Data logging is used in a broad spectrum of applications. Chemists record data such as

temperature, pH, and pressure when performing experiments in a lab. Design engineers

log performance parameters such as vibration, temperature, and battery level to

Page 4: Data Logger

evaluate product designs. Civil engineers record strain and load on bridges over time to

evaluate safety. Geologists use data logging to determine mineral formations when

drilling for oil. Breweries log the conditions of their storage and brewing facilities to

maintain quality. The list of applications for data logging goes on and on, but all of these

applications have similar common requirements.

How does data-logger work?

A data logger works with sensors to convert physical phenomena and stimuli into

electronic signals such as voltage or current. These electronic signals are then

converted or digitized into binary data. The binary data is then easily analyzed by

software and stored on a PC hard drive or on other storage media such as memory

cards and CDs.

[+] Enlarge Image

Figure 2. How does a data logger work?

Block Diagram of Data-logger

Page 5: Data Logger

Explanation of Block Diagram

1) SENSOR ONE: This is first sensor which uses to sense parameter one.

This can be temperature sensor, say LM35. The sensor will be placed on the

front panel. One can use LCD display to read the temperature.

2) SENSOR TWO: This is second sensor which uses to sense parameter two.

This can be Humidity sensor, say LDR. The sensor will be placed on the front

panel.

3) AMPLIFIER: We are going to use LM324 which is having 4 inbuilt

amplifiers. Since we have two sensors, we have used this Amplifier.

4) ADC: We are going to use ADC 0808 which is 8 bit and 8 channel ADC.

Since we have two inputs for ADC, we have used this ADC.

5) LCD: Liquid Crystal Display which is commonly known as LCD is an

Alphanumeric Display it means that it can display Alphabets, Numbers as

well as special symbols thus LCD is a user friendly Display device which can

be used for displaying various messages unlike seven segment display which

can display only numbers and some of the alphabets. The only disadvantage

of LCD over seven segment is that seven segment is robust display and be

visualized from a longer distance as compared to LCD. Here WE have used

16 x 2 Alphanumeric Display which means on this display WE can display two

lines with maximum of 16 characters in one line.

6) EEPROM: We need to store the parameter values in some device. We

have chosen EEPROM for this purpose as since it is a non-volatile memory

Page 6: Data Logger

and can hold data after power-off. We can use AT24C02/ AT24C04/ AT24C08/

AT24C16 depending on the memory size requirement.

7) Keypad: We need to display the previous records. So we are going to use

a Keypad for this purpose. This keypad can perform various actions like

a) Display previous records

b) Erase previous records

c) Set periodic interval time

d) Send data to PC

e) Set date and time

8) PC Interfacing: We are going to use MAX 232 for the purpose of PC

interfacing, using this module, we can send various data like temperature,

Humidity if the water to the PC.

Page 7: Data Logger

Chapter 3

Interfacing MicroSD Card to Micro controller

TO interface the MicroSD card to micro controller we must first under stand the pin

diagram of MicroSD card

MicroSD cards are available very cheap nowadays, a great option for having a huge

memory in any embedded system project. It is compatible with SPI bus, so the

interfacing is easy. SD card adapters are also easily available in market, one can easily

make a bread-board adapter by soldering few pins on it. Following figures show the SD

card pin-out & the bread-board adapter design by soldering 7-pins of a breakout header

Page 8: Data Logger

on the microSD adapter 

The following table describe the pin outs

Pin # Pin Name Signal Function

1 CS SPI !Chip-Select

2 Data In SPI Master Out-Slave In

(MOSI)

3 VSS Ground

4 VDD Voltage Supply In (2.7v-

3.6v)

5 CLK SPI Clock Signal

6 VSS Ground

7 Data Out SPI Master In-Slave Out

(MISO)

8 RSV Reserved

9 RSV Reserved

Wiring an SD card to your microcontroller's SPI interface is a fairly straightforward

process, however there are a couple things to look out for...

First, all SD cards operate between 2.7V-3.6V (preferably 3.3V) while most micro-

Controllers have 5v logic outputs. If your micro-Controller has 5v level logic outputs, you

must lower the voltage coming into your SD card to 3.3V from your micro-Controllers 5V

logic outputs. On your SD card these are the CS, Data In, CLK pins (see Card Wiring

tables for SD Card pin numbers.) This can be done with a simple voltage divider circuit

(see diagram below) or with a level shifter IC such as an MM74HC. This is of no

concern for the Data Out (MISO) pin coming into our micro-Controller from the SD Card

because the logic HIGH voltage level coming from the SD card is 3.3V which is above

the threshold for logic HIGH on our 5V micro-Controller.

Second, you must power your SD card with a clean 3.3V source. Most SD cards

Page 9: Data Logger

consume between 20mA and 150mA depending on the size of the card. Most cards

below 2GB consume 20mA (or less).

Ckt to interface MicroSD Card with Atmega32

Page 10: Data Logger

Chapter 4

Main ckt of the project

Ckt implemented on zero bread board

Page 11: Data Logger

Ckt diagram

Steps to operate the ckt and working

For setting RTC date/time (or for debugging mode):

• Connect the microSD module, insert the microSD card

• Connect the RS232 cable with the circuit. Set-up hyper terminal with 19200

baud, no parity, 8-bit data, 1 stop-bit and flow-control as 'None'

• Connect the power cable and power on the circuit while keeping the push-

button pressed

• Green LED will glow in the circuit board

• A menu will be displayed on the Hyper terminal as shown in the figure below.

Select desired option and follow the displayed instructions

• When date/time is set or debugging done, select option '0' to come out of the

menu and start functioning a s data-logger

• At this point, the RS232 cable can be removed

Page 12: Data Logger

Operation as Data-Logger:

• Connect the power cable and power on the circuit

• Green LED will glow

• Whenever the data-logging is required, press the push-button

• Red LED will glow, indicating that the recording has started

• To stop recording, press the push-button again, recording will stop and red LED

will turn off

• Files stored in the card can be read using a PC card-reader or using hyper-

terminal with the circuit started in debugging mode

Chapter 5

Explanation of various ICs and Components used in the main ckt diagram

Page 13: Data Logger

• Rs232 cable

in our project we have used Rs232 cable to

connect our hardware to pc

• IC MAX232

When communicating with various micro processors one needs to convert the

RS232 levels down to lower levels, typically 3.3 or 5.0 Volts. Serial RS-232

(V.24) communication works with voltages -15V to +15V for high and low. On

the other hand, TTL logic operates between 0V and +5V . Thus the RS-232

signal levels are far high than TTL electronics, and the negative RS-232

voltage for high can’t be handled at all by computer logic. To receive serial

data from an RS-232 interface the voltage has to be reduced. Also the low

and high voltage level has to be inverted. This level converter uses a Max232

and five capacitors.

• IC DS1307

Page 14: Data Logger

The DS1307 serial real-time clock (RTC) is a low-power, full binary-coded decimal

(BCD) clock/calendar .The clock/calendar provides seconds, minutes, hours, day, date,

month, and year information. The end of the month date is automatically adjusted for

months with fewer than 31 days, including corrections for leap year. The clock operates

in either the 24-hour or 12-hour format with AM/PM indicator. The DS1307 has a built-in

power-sense circuit that detects power failures and automatically switches to the

backup supply. Timekeeping operation continues while the part operates from the

backup supply.

• LED Two LEDs are used here

Green LED indicates that the ckt is in working condition and red led glows when the

recording starts

• Push button

we have used a push button to start and stop the recording of

data-logging

• MicroSD module

it is used to interface MicroSD card with the controller

• Adc connector

Atmega32 has in built ADC , to connect varios sensors to the ADC channel of

ATMGA we use the ADCconnector

• AVR_ISP

In 89c51 type of micro controller we generrayy have to remove the controller

from the hardware to burn the program in it,but in ATMEGA there is a facility

Page 15: Data Logger

of in_system programmer.using this ISP we can connect the hardware to PC

and then load the program our Micro Controller with out removing it.

• IC7805

It is the voltage regulator IC. ATMEGA controller works on 5v. so to

provide 5v to the controller we use this IC

CHAPTER 6

SOFTWARE

Page 16: Data Logger

//*******************************************************************

// **** MAIN routine for microSD Data-Logger ****

//*******************************************************************

//Controller : ATmega32 (Clock: 8 Mhz-internal)

//Compiler : AVR-GCC (winAVR with AVRStudio-4)

//*******************************************************************

#define F_CPU 8000000 //freq 8 MHz

#include <avr/io.h>

#include <avr/pgmspace.h>

#include <avr/interrupt.h>

#include "UART_routines.h"

#include "ADC_routines.h"

#include "FAT32.h"

Page 17: Data Logger

#define KEY_PRESSED (!(PINC & 0x80))

#define GREEN_LED_ON PORTC |= 0x20

#define RED_LED_ON PORTC |= 0x40

#define RED_LED_OFF PORTC &= ~0x40

void port_init(void)

{

PORTB = 0000; //used as o/p port

PORTA = FFFF; // used as i/p port

}

//call this routine to initialize all peripherals

void init_devices(void)

{

cli(); //all interrupts disabled

port_init();

uart0_init();

ADC_init()

//all peripherals are now initialized

}

Page 18: Data Logger

//function to blink LED in case of any error

void blinkRedLED(void)

{

while(1) //blink red LED continuously, if error

{

RED_LED_ON;

_delay_ms(400);

RED_LED_OFF;

_delay_ms(400);

}

}

//*************************** MAIN *******************************//

int main(void)

{

GREEN_LED_ON; //turn on green LED to indicate power on

RED_LED_OFF; //keep red LED off for now

}

Page 19: Data Logger

cardType = 0;

if(error)

{

if(error == 1) transmitString_F(PSTR("SD card not detected.."));

if(error == 2) transmitString_F(PSTR("Card Initialization failed.."));

blinkRedLED();

}

switch (cardType)

{

case 1:transmitString_F(PSTR("Standard Capacity Card (Ver 1.x) Detected!"));

break;

case 2:transmitString_F(PSTR("High Capacity Card Detected!"));

break;

case 3:transmitString_F(PSTR("Standard Capacity Card (Ver 2.x) Detected!"));

break;

default:transmitString_F(PSTR("Unknown SD Card Detected!"));

break;

}

{

//For displaying menu on hyper terminal, the key (psh-button) must be kept pressed

Page 20: Data Logger

while

//powering ON or while reset. If key is not kept pressed, the program will not display

menu and it will

//simply wait for start recording command (i.e. pressing of key afterwards)

if(KEY_PRESSED)

while(1)

{

transmitString_F(PSTR("\n\r\n\r> 0 : Exit the Menu"));

transmitString_F(PSTR("\n\r> 1 : Display current Date/Time"));

transmitString_F(PSTR("\n\r> 2 : Update Date"));

transmitString_F(PSTR("\n\r> 3 : Update Time"));

transmitString_F(PSTR("\n\r> 4 : Get file list"));

transmitString_F(PSTR("\n\r> 5 : Read File"));

transmitString_F(PSTR("\n\r> 6 : Delete File"));

transmitString_F(PSTR("\n\r\n\r> Enter the option:"));

option = receiveByte();

transmitByte(option);

//RECORDING//

Page 21: Data Logger

while(1)

{

while(!KEY_PRESSED); //wait here for key-press, recording starts when key is

pressed

_delay_ms(40); //key debounce delay

if(!KEY_PRESSED) continue;

RED_LED_ON; //turn on red LED to indicate that recording has started

}

while(1)

{

fileName[ ] = 'C';’S’,’V’

//From here onwards, gather data by appending strings in dataString

//dataString is declared in FAT32.h

//make sure dataString doesn't exceed its MAX_STRING_SIZE, defined in

FAT32.h

//Also, end the data string with '\r' & '\n' characters to maintain CSV format

readTemperature(0); //read temperature from adc channel-0

Page 22: Data Logger

for(channel=1; channel<8; channel++) //read voltages from ADC channel

1 to 7

{

dataString[i++] = ',';

readVoltage(channel);

}

dataString[i++] = '\r';

dataString[i] = '\n'; //always end the string with these two characters,

if(error) blinkRedLED();

if(KEY_PRESSED)

{

while(KEY_PRESSED); //wait here for key-depress

_delay_ms(40); //key debounce

goto STOP;

}

Page 23: Data Logger

}//end of while(1)

STOP:

RED_LED_OFF; //recording stopped

}//end of while(1)

}//end of main

//********** END ************************

Chapter 7

Appendix

Page 24: Data Logger

CHAPTER 8

CONCLUSION AND BIBLOGRAPHY

Page 25: Data Logger

CONCLUSION

After completing this project we conclude that we understood about the Atmega32

controller,we learned to interface MicroSD card to controller and also got complete idea

about the Data-logging

BIBLOGRAPHY

Reference for this project is given by following books-

• Digital magazine

• Electronics for you

Reference for this project is given by following websites-

• www.projectframe.com

• www.electronicsproject.com