Introduction To TIMER Before Exp 3
Introduction To TIMER Before Exp 3
Implementation of a Traffic
Control System using Timer
BY NIRJHOR ROUF
2
Problem Statement
Make three LEDs blink and implement a traffic control system
while using Arduino system frequency (F_CPU) of 16 MHz
using timer to generate the delay without any application of
delay() function.
3
Problem Solution
We will change the code used for controlling the traffic lights
in experiment 1 by simply replacing the delay functions with
a function written by us that will use timer.
The
function will accept an input argument mentioning the
number of seconds of delay and run a nested if loop.
4
Previously used code in Exp. 1
To-do list:
• Initialize timer registers
• Write a new delay function using timer
• Change the marked lines
5
Timer Basics: Registers (Timer0)
Timer/Counter Control Register A for Timer0 – TCCR0A: The
bits WGM02 (from TCCR0B), WGM01 and WGM00 decide which
mode the timer will run on.
62.5 ns 62.5 ns
62.5 ns
62.5 ns 62.5 ns
62.5 ns
𝑅𝑒𝑞𝑢𝑖𝑟𝑒𝑑 𝑑𝑒𝑙𝑎𝑦
𝑇𝑖𝑚𝑒𝑟 𝑐𝑜𝑢𝑛𝑡 = −1
𝑇𝑖𝑚𝑒𝑟 𝑐𝑙𝑜𝑐𝑘 𝑝𝑒𝑟𝑖𝑜𝑑
References
ATMega328 manual
https://www.avrfreaks.net/forum/tut-c-newbies-guide-avr-timers
http://maxembedded.com/2011/06/avr-timers-timer0/
24
Thanks for attending….