Monday, January 28, 2013

BASIC ELECTRONICS PROJECT 6- MAKING AN IR SENSOR



Hi..friends ,welcome back……!! This time I am here with some discussion on INFRA RED sensors. IR sensors are most widely used in many electronics and robotics project , so have a look how to make a IR sensors and how to use them.??

INTRODUCTION

IR SENSORS circuit is very important circuit to detect the presence of any object or to distinguish between black and white colors these sensors are most widely used in making a black or white line follower robots. IR emitter detector circuit is very easy to implement and it can be easily used in object detection, motion detection or color sensing.



IR reflective sensors have emitter (IR LED) and receiver (PhotoTransistor or photo diode). If white surface is present beneath the IR LED or if there is any object, IR rays are reflected and are sensed by the receiver, while in case of no object receiver does not sense IR rays and same is in case of black surface as light gets absorbed and hence receiver does not sense IR rays.

IR SENSOR CIRCUIT 

Here is the circuit which we have to implement for making our IR sensor module just implement circuit and calibrate your circuit with the help of variable resistor for proper result.



now this sensor circuit can be used in so many electronics and robotics projects. In our other posts we will discuss about use of IR sensors in so many projects.

For making a line follower robot with IR sensors just go to this link   ROBOTICS PROJECT 1- MAKING A LINE FOLLOWER ROBOT WITHOUT USING MICROCONTROLLER

I hope this article was useful for you guys..!! 

In case of any doubt, query or critical view just leave a comment. I am waiting for your comments.

 

EMBEDDED SYSTEMS TUTORIAL10- TIMERS IN AVR -TIMER1


Hi friends..!! welcome back this time I am here with some discussion on second part of TIMERS  in avr , this time we are going to discuss about TIMER1. I hope that you have read and understood the previous posts:
Now we are aware with the concepts of AVR so we are moving towards TIMER1. TIMER1 is more or less like TIMER0 so without wasting much time we will simply go through problem statementwe .Once we are done with this, we can proceed to the CTC and PWM modes of operations in subsequent posts.

Problem Statement

This time our task is to flash an LED every 2 seconds, i.e. at a frequency of 0.5 Hz. We have an XTAL of 16 MHz.

Using prescaler and interrupt

So here is the formula.

                TIMER COUNT  = (REQUIRED DELAY/CLOCK TIME PERIOD ) - 1

Given that we have a CPU Clock Frequency of 16 MHz. At this frequency, and using a 16-bit timer (MAX = 65535), the maximum delay is 4.096 ms. It’s quite low. Upon using a prescaler of 8, the timer frequency reduces to 2 MHz, thus giving a maximum delay of 32.768 ms. Now we need a delay of 2 s. Thus, 2 s ÷ 32.768 ms = 61.035 ≈ 61. This means that the timer should overflow 61 times to give a delay of approximately 2 s.
Now it’s time for you to get introduced to the TIMER1 registers (ATMEGA16/32). We will discuss only those registers and bits which are required as of now. More will be discussed as and when necessary.

TCCR1B Register

The Timer/Counter1 Control Register B- TCCR1B Register is as follows.

TCCR1B Register

Right now, only the highlighted bits concern us. The bit 2:0 – CS12:10 are the Clock Select Bits of TIMER1. Their selection is as follows.


Clock Select Bits Description
Since we need a prescaler of 8, we choose the third option (010).

TCNT1 Register

The Timer/Counter1 - TCNT1 Register is as follows.

TCNT1 Register


 It is 16 bits wide since the TIMER1 is a 16-bit register. TCNT1H represents the HIGH byte whereas TCNT1L represents the LOW byte. The timer/counter value is stored in these bytes.

TIMSK Register

The Timer/Counter Interrupt Mask Register – TIMSK Register is as follows.

TIMSK Register


As we have discussed earlier, this is a common register for all the timers. The bits associated with other timers are greyed out. Bits 5:2 correspond to TIMER1. Right now, we are interested in the yellow bit only. Other bits are related to CTC mode which we will discuss later. Bit 2 – TOIE1 – Timer/Counter1 Overflow Interrupt Enable bit enables the overflow interrupt of TIMER1. We enable the overflow interrupt as we are making the timer overflow 61 times (refer to the methodology section above).

TIFR Register

The Timer/Counter Interrupt Flag Register – TIFR is as follows.

TIFR Register


Once again, just like TIMSK, TIFR is also a register common to all the timers. The greyed out bits correspond to different timers. Only Bits 5:2 are related to TIMER1. Of these, we are interested in Bit 2 – TOV1 – Timer/Counter1 Overflow Flag. This bit is set to ’1′ whenever the timer overflows. It is cleared (to zero) automatically as soon as the corresponding Interrupt Service Routine (ISR) is executed. Alternatively, if there is no ISR to execute, we can clear it by writing ’1′ to it.

Code


Now its time for coding its too easy like TIMER0, if you have not gone through TIMER0 please read TIMER0 tutorial first otherwise it will be a bit tough for you.


/*
 * TIMER1.c
 *
 * Created: 1/28/2013 1:59:29 AM
 *  Author: ABHILASH
 */


       #include <avr/io.h>
       #include <avr/interrupt.h>

       // global variable to count the number of overflows
       volatile uint8_t timer_overflow;

       // initialize timer, interrupt and variable
       void timer1_init()
       {
                 // set up timer with prescaler = 8
                 TCCR1B |= (1 << CS11);
      
                 // initialize counter
                 TCNT1 = 0;
      
                 // enable overflow interrupt
                 TIMSK |= (1 << TOIE1);
      
                 // enable global interrupts
                 sei();
      
                 // initialize overflow counter variable
                 timer_overflow = 0;
       }

       // TIMER1 overflow interrupt service routine
       // called whenever TCNT1 overflows
       ISR(TIMER1_OVF_vect)
       {
                 // keep a track of number of overflows
                 timer_overflow++;
      
                 // check for number of overflows here itself
                 // 61 overflows = 2 seconds delay (approx.)
                 if (timer_overflow >= 61) // NOTE: '>=' used instead of '=='
                 {
                     PORTC ^= (1 << 0);  // toggles the led
                     // no timer reset required here as the timer
                            // is reset every time it overflows
            
                            timer_overflow = 0;   // reset overflow counter
                 }
       }

       int main(void)
       {
                 // connect led to pin PC0
                 DDRC |= (1 << 0);
      
                 // initialize timer
                 timer1_init();
      
                 // loop forever
                 while(1)
                 {
                            // do nothing
                            // comparison is done in the ISR itself
                 }
       }



So friends it was all about TIMER1 in AVR , in case of any query doubt or critical view just leave a comment here . in our next tutorial we will discuss about TIMER2 , till then bye…!!


THNX...:)

Tuesday, January 22, 2013

EMBEDDED SYSTEMS TUTORIAL 9- INTERFACING 128X64 GRAPHICAL LCD WITH AVR

 Hi friends this time I am here with a very interesting embedded systems tutorial, as in last tutorials we learnt about 16x2 LCD interfacing but some times it seems vey difficult to display a huge amount of data on such a small space provided by 16x2 LCD , so there is the solution a powerful 128x64 GRAPHICAL LCD, with a lot of space and facility to display graphics along with alphanumeric data, in this tutorial we are going to learn how to interface a GRAPHICAL LCD with AVR. We  are going to discuss about a ks0108 based LCD interfacing.






What is required??

I am using a HQM1286404 LCD it’s a pretty old one and please don’t be mistaken with newer versions of LCD, if you are using any other version you have to find its datasheet for wiring connections because wiring connections may be different from version to version. I will provide connections for  HQM1286404 LCD only and its pretty hard to get accurate wiring connection , so better consult your datasheet and internet as well. Except this you will need a AVR MCU, I am using ATMEGA 8 here and of course an LCD library  you can find o many libraries on internet but I am giving a best link to download a very nice library written by Mr. Fabian Maximilian Thiele , thanx to him the link for this library is GLCD_LIBRARY

LCD PIN-OUT CONNECTIONS

Here is the correct pin-out of LCD:
1 Vcc
2 GND
3 VCON
4-11 DB0-DB7
12 CS2
13 CS1
14 RESET
15 R/W
16 D/I
17 EN
18 Vee out
19 LED Anode
20 LED Kathode
     

NOTE:- in some cases you will found that your LCD screen is swapped into two halves in such cases just swap the chip select pins and problem will be corrected...:)

LIBRARY USE

The library , which you have downloaded contains to files ks0108.c and ks0108.h  you have to copy these files and have to paste in the same folder wher .c file of your main program is contained and you have to add corresponding header files in the beginning of the program too like

#include "ks0108.h"
#include "ks0108.c"

the .h files contains the information about pin connection and commands you can easily change the connection pin and ports from there .
Getting familiar with commands is just a learning by doing thig more you do more you learn. Just go through  the library to know more about the command its self explaining.

Along with these library files some font files are also provided these fonts must be added by adding corresponding header file in beginning of the program.except these font you can fetch your windows font with the help of this java program GLCDFontCreator2

SOURCE CODE

here is an interesting source code to start with 

#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "ks0108.h"
#include "ks0108.c"
#include "arial_bold_14.h"
int main(void) {
                   
                    // Wait a little while the display starts up
                    for(volatile uint16_t i=0; i<15000; i++);
                   
                    // Initialize the LCD
                    ks0108Init(0);
                   
                    // Select a font
                    ks0108SelectFont(Arial_Bold_14, ks0108ReadFontData, BLACK);
                    // Set a position
                    ks0108GotoXY(15,10);
                    // Print some text
                    ks0108Puts_P(PSTR("Tech_strong"));
                    // two little circles
                    ks0108DrawCircle(30, 30, 5, BLACK);
                    ks0108DrawCircle(90, 30, 5, BLACK);
                    // again some text
                    ks0108GotoXY(29,38);
                    ks0108Puts_P(PSTR("Tutorials"));

                    // a loading bar
                    for(int x=0;x<128;x++)
                    {
                                        ks0108GotoXY(x,50);
                                        ks0108DrawRect(x, 50, 80, 10, BLACK);
                    }

                    while(1);
}


CIRCUIT DIAGRAM

now just implement this easy circuit burn your MCU with corresponding .hex file and enjoy your GRAPHICAL lcd.


NOTE:- In my program I have changed data port of LCD from PORTA to PORTD so be careful if you are using this circuit connection you will have to change PORTA to PORTD in ks0108.h file of library be careful ….!!

I think it was a useful article for you all in case of any query, doubt or critical view just leave a comment in next tutorial we will discuss about displaying an image on this LCD,… till then bye…!

THNX..:)

Tuesday, January 15, 2013

MATLAB TUTORIALS

EMBEDDED SYSTEMS TUTORIALS

THESE ARE THE LINKS FOR EMBEDDED SYSTEMS TUTORIALS WHICH I HAVE POSTED ON THE BLOG TILL NOW....:)

EMBEDDED SYSTEMS TUTORIAL 1- SELECTING A SUITABLE MICROCONTROLLER

EMBEDDE SYSTEMS TUTORIAL2- REQUIREMENTS 

EMBEDDED SYSTEMS TUTORIAL3- MAKING OUR FIRST PROJECT -PART1

EMBEDDED SYSTEMS TUTORIAL3- MAKING OUR FIRST PROJECT -PART2

EMBEDDED SYSTEMS TUTORIAL4- SIMULATING OUR FIRST PROJECT ON PROTEUS

EMBEDDED SYSTEMS TUTORIAL 5- GPIO IN AVR

EMBEDDED SYSTEMS TUTORIAL6- INTERFACING 7 SEGMENT DISPLAY WITH AVR

EMBEDDED SYSTEMS TUTORIAL7- TIMERs IN AVR PART-1

EMBEDDED SYSTEMS TUTORIAL8 - INTERFACING 16X2 ALPHANUMERIC LCD WITH AVR PART 1

EMBEDDED SYSTEMS TUTORIAL 8- INTERFACING 16X2 LCD WITH AVR PART-2

EMBEDDED SYSTEMS TUTORIAL 9- INTERFACING 128X64 GRAPHICAL LCD WITH AVR

EMBEDDED SYSTEMS TUTORIAL10- TIMERS IN AVR -TIMER1

EMBEDDED SYSTEMS TUTORIAL11 - CONTROLLING DC MOTORS WITH AVR  

BASIC ELECTRONICS TUTORIALS