Saturday, January 02, 2016

IR (Infrared) Communication Between Two Microcontrollers -Step By Step Tutorial : Part-3



PART 1 : Basic Introduction 

PART 2 : Interrupt 

PART 3 : Timer

PART 4 : Calculation

PART 5 : LED Switching Project [END

 

Timer :Part-3


 

 

Microcontroller Clock tutorial

Microcontroller Clock tutorial



Today I will discuss about Timer. It's very important part of microcontroller . Basically Timer is used to measuring time. Microcontroller performs time related operations using timer . As we need to measure the time of each falling edge of IR-Signal .In this tutorial we will use timer0 of pic18f2550 and we will use 8bit mode. You may use 16bit mode, but first time skip complexity. Both TMROL and TMROH registers works with 16bit mode.
PIC 18f2550 microcontroller has 4 timer modules. Timer0,Timer1,Timer2 and Timer3 . I will only describe about Timer0 and i will try to make it easy so that you can make it by yourself . 

Generally Timer0 is controlled by T0CON register of pic18f2550 and TMR0L is Timer0 register low byte . In 16bit mode both TMR0L(8bit) and TMR0H(8bit) works. But in 8bit mode we can use only TMR0L. This timer0 register is incremented for each pulse comes to it and can count from 0 to 255 (0xFF).


Now we need to take a look about Timer0's control register and some necessary information . Next we will see how timer works and that will be good for us . 

Read all information carefully provided on these images!!



IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-3
IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-3
IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-3
IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-3
IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-3
IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-3
IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-3
IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-3

Just keep in your mind , all those given in previous steps.We will need those in source code .

Now we will see how timer works 

IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-3
IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-3


Generally We connect crystal clock with microconteroller so that it can work with time. Consider that we are using 12MHz clock. So, that means 12000000 pulses are passing to the microcontroller . Is that clear ?

Prescalar:


Prescalar is used to measuring frequency. Look at the picture named ratio. When (fosc/4) or (12/4=3MHz) frequency pulse comes to the the microcontroller we need make this smaller to make the calculation easy. So at this stage we need prescalar . Alright! 
There is another scaler "Postscalar" . Postscalar works after signal has come to the microcontroller .It isn't very necessary in this tutorial.


On that picture clock cycle  represents (Clock/4) or (12/4=3MHz) frequency . If we use 1:2 to scale , then 2 pulses is considered as 1 pulse . In 1:4 , 4 pulses is considered as one pulse. For 1:8 , eight pulses will be considered as one pulse.

Working of Timer0




Note:To Understand Clearly about Timer0 . You have to keep this picture in your memory . All we see in that part are the details of this Picture and save the Picture .

For Clock frequency we could use T0CKL pin (External Source) but Crystal frequency (12 MHz Crystal Clock) is good for us .

When we connect a crystal (we are using 12MHz Crystal Clock) with our microcontroller , microcotnroller receives pulse continuously. At this case we know the frequency and we can calculate the time period of each pulse from (T=1/f). So if we know how many pulse are received, we can calculate time by multiplying. We will see this later .
Generally , Crystal clock frequency divided by 4. It's a rule. That means first time clock frequency prescaled by 4. Look at the picture and you can see that "clock/4" or "System Clock"

IR (Infrared) Communication Between Two Microcontroller -Step By Step Tutorial : Part-3
IR (Infrared) Communication Between Two Microcontroller -Step By Step Tutorial : Part-3
After this stage signal comes to prescalar. In this tutorial we will use 1:4 prescalar. That means we are dividing the system clock by 4. So, it means when 4 system clock pulse comes to prescalar, it sends out 1 pulse to Timer0 register . In this way timer0 register is being incremented .

Basically, when one pulse enters into the  Timer0 register, TMR0L  register is incremented by 1. The capacity of this register is 0 to 255. So when TMR0L will count 255, there will be an  overflow interrupt. In the interrupt function routine we will reset TMR0L register and we will increase (int count variable) by 1. We need this variable to remember that how many times interrupt occurred. When we perform [count * TMR0L], we get the total number of pulses. From this information we can measure time of "1" and "0"


We will create a project  in Calculation(4th Part)

Setup Timer0 Register :

Bit 0 to 2 are used to select prescalar. As we are using 1:4 prescalar , we need to set 001

Now set 3rd bit to 0 . So bit comes 0001.

Now set 4th bit to 0 and  we get   00001.

Now set 5th bit to 0 and we get   000001

Now set 6th bit to 1 , because we are using 8 bit mode . You may use 16bit mode. and  we get      1000001

Now set 7th bit to  1, because we need to start timer . Finally we get : 11000001 or 0xc1 (hexadecimal).


IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-3
IR (Infrared) Remote Controlled Communication Between Two Microcontroller -Step By Step Tutorial : Part-3

 Setup Timer0 overflow flag :

When overflow happens timer overflow interrupt flag bit becomes 1. When Overflow Register flag bit becomes 1 and microcontroller understand that interrupt occurred. So microcontroller goes to perform timer interrupt routine. When flag becomes 0 , microcontroller understand that everything is fine and there is no interrupt.
To enable overflow interrupt we need to set that enable. Unless the overflow interrupt will not work.

So first set INTCON.TMR0IE=1;

Note: you can find INTCON register on Interrupt section in Datasheet or in Interrupt tutorial i had described about INTCON register.


We set INTCON.TMR0IF bit to 0 and that sets the Flag as 0 .

First we need to enter on the INTCON register and then set TMR0IF=0;


 >>Continue to 4th PART<<

17 comments:

  1. thanks for your kind information. visit our website and check our guide about imensions of a 75 inch tv

    ReplyDelete
  2. Thanks for this amazing post
    https://g.page/r/CWM1UWDOsjZeEBA

    ReplyDelete
  3. We provides the best services, amenities and private apartment homes for independent and assisted living lifestyles. check our website and get Bellevue retirement community service

    ReplyDelete
  4. All of the nail art is fun, but simple pink and nude manicures are still very on trend for 2022. (And they're so much easier to do on your own.) Likewise, you can never go wrong with a pop of neon for summer. check also summer dip nail ideas

    ReplyDelete
  5. If you are looking for contact information for QuickBooks, then be sure to give them a call at Quickbooks Customer Service +1 866-669-5068.

    ReplyDelete
  6. Weed online kaufen, Marihuana online bestellen, Weed online kaufen in Deutschland

    Cannabis online bestellen bei Geasherr.com ist schnell und einfach
    Sie können ganz einfach professionell angebautes Weed in unserem Online-Weedshop kaufen und es sich nach Hause oder an eine beliebige Adresse liefern lassen.

    Wählen Sie Ihr Cannabis aus und legen Sie es in Ihren Warenkorb. Wir verschicken unser Marihuana diskret mit den besten Express-Versandmethoden per Post oder DHL.
    https://grasherr.com/

    ReplyDelete
  7. I’m really happy to say it was an interesting post to read. I learned new information from your article on amity project synopsis
    , you are doing a great job

    ReplyDelete
  8. I read your blog its nice i like content its very useful for me
    I am Amara William I am always ready to learn new things and resolve problem regarding.
    I am a help you to resolve your quick book error, I am independent expert last 5 year to solve all error of quick book QuickBooks , working dedicatedly with the reliable QuickBooks support provider for resolving QuickBooks errors efficiently.
    Fix QuickBooks Error Code 15101

    ReplyDelete
  9. I read your blog its nice i like content its very useful for me
    QuickBooks error support helps to resolve yours problem regarding QuickBooks support .Our Company have l15 year experience to solve all QuickBooks error. Our team very hardworking.
    ND files in QuickBooks desktop

    ReplyDelete
  10. I am Amara William I read your blog it's nice I learn new things and keep writing. I am always ready to learn new things and resolve problems.
    I am helping you to fix your quick book error, I am an independent expert last 5 years in solving all errors of quick book QuickBooks, working dedicatedly with the reliable QuickBooks support provider for the system
    Quickbooks error code 1612

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. I have a pending report on IR communications and their frequencies can anyone tell me that dissertation writing service can help in in writing or need someone else?

    ReplyDelete
  13. Olive Branch Medical Services is provided by a Nurse Practitioner who has experience managing patients and providing the best possible outcomes. This helps build an efficient management protocol for our patients.
    Olive Branch Medical Service

    Olive Branch Medical Services - Primary Health Care, Women Health, Children Health, Longview, Texas
    https://olivebranchmedicalservices.com

    ReplyDelete
  14. I’m really happy to say it was an interesting post to read. I learned new information from your article on amity project synopsis
    , you are doing a great job
    digital marketing agency

    ReplyDelete
  15. check Cryptoanime for all types of anime reviews.

    ReplyDelete

  16. Looking for the perfect Naruto Hoodie online? We have collected the best Naruto Hoodies on the market to help you become the next Hokage of the world! These awesome Naruto hooded sweatshirts, Akatsuki hoodies, kakashi hoodie are designed for extreme comfort, whatever your body size. You will surely find these Naruto cosplay hoodies super dope. Choose from white, pink, black, orange, and more Naruto sweatshirts with your favorite Naruto characters like Sasuke, Kakashi, PAIN, Kyuubi, Hinata, Itachi, Akatsuki etc. Our Naruto Anime hooded sweatshirts are perfect for men and women! Shop now! https://shippudo.com/product-category/fashion-acceesories/hoodies/

    ReplyDelete
  17. This tutorial provides a step-by-step guide for implementing IR communication between two microcontrollers. With the help of this coursework help service, anyone can learn the basics of IR communication and have a better understanding of how it works. This tutorial is an excellent resource for those looking to get started with IR communication.

    ReplyDelete

Ain't getting any visitors!
Please Share and Bookmark posts.

Tags

: (1) 18F2550 (1) 36KHz (3) and (1) arduino (1) Based (1) battery (1) Bipolar (1) Blinking (1) blinks (1) Bluetooth (1) bluetooth device interfacing (1) bluetooth module (1) button (1) circuit (1) clock (1) control (1) crystal oscillator (3) Db9 (1) DC Motor (2) digital (2) Digital Voting Machine (1) digital voting machine using pic (1) display (2) DS1307 (1) electronic (1) embedded c programming tutorial (11) embedded c tutorial (11) experiment kit (4) external interrupt (4) flash (1) flashing (1) Gas Leakage detector (1) HC-06 (1) home (1) how (1) How to (10) i2c tutorial (1) in (1) indicator (1) infrared Connection (3) interface (8) interfacing (3) Interrupt (3) Introduction (1) IR Connection (3) IR Receiver (4) IR Transmitter (4) key pad (1) keyboard (1) keypad (1) lavel (1) Lcd 16x2 (2) lcd 2x16 (2) led (1) lm35 (2) LPG (1) machine (1) make (1) Make bootloader (1) making (1) matrix (1) max232 (1) membrane keyboard (2) meter (2) Micocontroller (1) microchip (4) microchip pic (2) microchips (3) microcontroller (9) microcontroller based (3) microcontroller programming (3) Microcontroller Project (4) Microcontroller Projects (1) microcontroller_project (2) microcontrollers (4) Microprocessor (2) mikroC (5) mikroc code to start and stopstart and stop dc motor (1) mikroc pro for pic (2) Motion detector (1) MQ-9 Gas Sensor (1) musical (1) NEC Protocol (4) pcb (5) PIC (3) pic controller (11) pic microcontroller (11) pic microcontroller tutorial (11) pic programming (1) pic programming in c (12) pic proteus (1) Pic Tutorial (12) pic18 (2) pic18f2550 (11) picmicrocontroller (4) picRFモジュール (1) PIR Motion Sensor (1) printed circuit board (1) proteus (6) pulse width modulation (1) push (1) push button (1) PWM (1) real (1) rf transmitter (3) Rs 232 (1) Rs232 (1) scroll (1) scrolling (1) Serial communication (1) Serial Connection (1) Serial Port (1) serial port rs232 (1) Servo Motembedded c programming tutorial (1) simulation (2) Soil Moisture Meter (1) speed control (1) step by step (7) step bystep (1) Stepper Motor (2) text (2) Thief Detector (1) time (1) timer (4) timer0 (4) tone (1) TSOP38236 Receiver (4) tutorial (2) Unipolar (1) USART Connection (1) USB (1) usb 1.0 (1) USB bootloadere (1) USB HID (1) using (9) voltmeter (1) voting (1) water level indicator (3) with (2) work (1)

Traffic Feed


Live Traffic Feed
Visitor Tracking

Leave Your Message Here

Name

Email *

Message *

Like on Facebook