July 2012 | EMBEDDED AND ROBOTICS

Communication


Communication refers to the interaction between two devices in embedded system. It can be between computer and microcontroller or between two microcontrollers. 

Data Transfer

There are many techniques , different data transfer technique are used in different situations. Some example of data transfer is
Simple parallel transferUsed to transfer 8, 16, and 32 etc bits of data in the same time.
Asynchronous Serial Transfer (USART) –It is an old but still in use mode of serial communication uses only 2 lines (+1 additional line for GND).
SPI - Serial Peripheral Interface It is a standard mode of communication between different
ICs.
USB - A very advance, high speed and complicated serial Bus used in PCs to connect almost anything to it. 


Classification

Modes of Data Transfer can be divided into two types:
1. PARALLEL TRANSFER In this mode a number of bits (say 8,16 or 32) are transferred at a time. Thus they require as many electrical line as the number of bits to be transferred at once.

2. SERIAL TRANSFER In this mode only one bit is transfer at once. So to transfer 8 bits, 8 cycles are required.

Modes of Data Transfer can also be divided into
1. SYNCHRONOUS TRANSMISSION.
2. ASYNCHRONOUS TRANSMISSION

____________________________________________________________________________


Baud Rate
Baud Rate is a measurement of transmission speed in asynchronous communication. Devices that allow the communication must all agree on a single speed of information its unit is  'bits per second'.
 ____________________________________________________________________________

Summery

Transmission
Advantages
Disadvantages
Asynchronous
Simple & Inexpensive
High Overhead
Synchronous
Efficient
Complex and
Expensive


____________________________________________________________________________

Different Communication Techniques
Simplex : one sided communication like radio
Half duplex: like walkie talkie
Full duplex : video conferencing

Timers




Timer is an 8 bit register that keeps on increasing its value, so one of the basic conditions is the situation when timer register OVERFLOWS i.e. it has counted up to its maximum value (255 for 8 BIT timers) and rolled back to 0. In this situation timer can issue an interrupt and you must write an Interrupt Service Routine (ISR) to handle the event. There are three different timers available in Atmega16 and all the timers work in almost same way. They are TIMER0, TIMER1 and TIMER2.


TIMER MICROCONTROLLER 








Prescalar
The Prescalar is a mechanism for generating clock for timer by CPU clock.
Atmega has clocks of several frequencies such as 1 MHz, 8 MHz, 12 MHz, 16 MHz (max). The Prescalar is used to divide this clock frequency and produce a clock for TIMER. The Prescalarcan be set to produce the following types of clocks:
No Clock(Timer stop)
No prescaling (clock frequency = CPU frequency) FCPU/8
FCPU/64
FCPU/256
FCPU/1024
External clock


Timer Mode

Timers are usually used in one of the following modes:
Normal
CTC
Fast PWM
Phase correct PWM




Normal Mode

NORMAL MODE TIMERA timer running in normal mode will count up to its maximum value. When it reaches this maximum value, it issues an Overflow interrupt and resets the value of the timer to its original value.


In the above case, you can see that the time period is 256 times the time period of the clock. 255 clock cycles are required to attain the maximum value and one clock cycle to clear the timer value.
So, ftimer = fclock / 256
this mode has its limitations. We are confined to a very small set of values of frequency for the timer. This limitation is overcome by the compare mode.

CTC Mode
(clear timer on compare match)
Compare mode makes use of a register known as the Output Compare Register which stores a value of our choice. The timer continuously compares its current value with the value on the register and when the two values match, the timer resets itself to 0.
CTC mode timerIn that case, the output pin will remain high for one time period of the timer and will remain low for another time period. 





So,
tout = 2 * ttimer
From the normal case, we can draw an analogy to find out ttimer.
ttimer = tclock * (OCR + 1)
So, finally, we have the frequency as,
fout = fclock / (2 * (OCR + 1) )



Pulse Width Modulation (PWM) Mode
if you want to control the brightness of an LED (or any lamp), or the speed of DC motor, then digital on/off signals will not suffice. This situation is very smartly handled by a technique called as PWM or Pulse Width Modulation.

PWM is the technique used to generate analog signals from a digital device like a MCU.
In AVR microcontrollers, PWM signals are generated by timers. There are two methods by which you can generate PWM from timers:
1. Fast PWM
2. Phase Correct PWM


1.Fast PWM
Now for PWM generation from this count sequence OCR0 (Output Compare Register Zero) is used (Zero because it is for TIMER0 and there are more of these for TIMER1 & TIMER2). We can store any value between 0255 in OCR0, say we store
64 in OCR0 then it would appear in the graph as follows (the RED line).
Fast PWM timersWhen the TIMER0 is configured for fast PWM mode, then, while the timer is counting up, whenever the value of TIMER0 counter matches the value in the OCR0 register, an output PIN is pulled low (0) and when counting sequence begin again from 0 it is SET again (pulled high=VCC). This PIN is named OC0 and you can find it in the PIN configuration of ATmega
From the figure, you can see that a wave of duty cycle of 64/256 = 25% is produced by setting OCR0 to 64. You can set OCR0 to any value and get a PWM of duty cycle of (OCR0 / 256). When you set it to 0 you get a 0% duty cycle while setting it to 255 will give you a 100% duty cycle output. Thus by varying duty cycle you can get an analog voltage output from the OC0 PIN.
In the inverting mode the value of the OC0 pin is just the reverse of that in the above figure.


2.
Phase Correct PWM Mode
This mode is very similar to the Fast PWM mode except that whenever the value of the timer reaches its maximum value then instead of clearing the value of the timer it simply starts counting down.
 Phase Correct PWM Mode timer 


Overview of timers
timer 0 timer 1 timer 2 difference atmega


SETTING TIMERS IN CVAVR :

timer in cvavr

Assignment on ADC

MAKE PROGRAMS:


  1. GLOW LED ACCORDING TO  INPUT TO ADC
    0-99       1 LED
100-150      2LED
151-200      3 LED
200-255      4LED


2.  MAKE  DIGITAL VOLTMETER 
3.  MAKE DIGITAL WATTMETER




see answer here

ADC Analog to Digital convertor

What we have seen till now that the input given to uC was digital, i.e., either +5 V (logic 1) or 0V (logic 0). But what if we have an analog input, i.e., value varies over a range, say 0V to +5V? Then we require a tool that converts this analog voltage to discrete values. Analog to Digital Converter (ADC) is such a tool.


ADC is available at PORTA of Atmega16.
CLICK HERE FOR PIN DIAGRAM
Thus we have 8 pins available where we can apply analog voltage and get corresponding digital values. The ADC register is a 10 bit register, i.e., the digital value ranges from 0 to 1023. But we can also use only 8 bit out of it (0 to 255) as too much precision is not required.
Reference voltage is the voltage to which the ADC assigns the maximum value (255 in case of 8 bit and 1023 for 10 bit). Hence, the ADC of Atmega16 divides the input analog voltage range (0V to Reference Voltage) into 1024 or 256 equal parts, depending upon whether 10 bit or 8 bit ADC is used. For example, if the reference voltage is 5V and we use 10bit ADC, 0V has digital equivalent 0,
+5V is digitally 1023 and 2.5V is approximately equal to 512.

ADC =Vin x 255/Vref (8 bit)
ADC =Vin x 1023/Vref (10 bit)

Function:


read_adc()
This function returns the digital value of analog input at that pin of PORTA whose number is passed as parameter, e.g., if you want to know the digital value of voltage applied at PA3, and then just call the function as,
read_adc(3);
If the ADC is 8 bit, it will return a value from 0 to 255. Most probably you will need to print it on LCD. So, the code would be somewhat like


int a; char c[10]; // declare in the section of global variables
a=read_adc(3);
itoa(a,c);
lcd_puts(c);

SETTING UP ADC:
FOR OLDER VERSION OF CVAVR:

CVAVR ADC ANALOG TO DIGITAL CONVERTOR




FOR NEWER VERSION OF CVAVR:
CVAVR ADC ANALOG TO DIGITAL CONVERTOR

click here for projects on adc

Getting Started With Proteus : simulation software



PROTEUS ISIS adding components like microcontroller lcd and switchadding microcontroller

PROTEUS ISIS adding components like microcontroller lcd and switch
PROTEUS ISIS adding components like microcontroller lcd and switch


adding lcd
PROTEUS ISIS adding components like  lcd
PROTEUS ISIS adding components like  lcd



PROTEUS ISIS adding components like  lcd  makin connections



adding hex file in microcontroller using proteus







adding hex file in microcontroller using proteus

to add switch, search for "button"
setting adc with proteus
led pattern circuit with proteus

Assignment on Pograms for lcd





1) Print a character on lcd
2) Print your name
3) Print a to z
4) Blink a character on lcd
5) Print a b c d…z  on only 1 coordinate after delay of 100ms
6) Moving name
7) Print name on pressing switch
8)  Make clock
9) Make calendar: having condition of leap year and leap year of century, each month having appropriate days.


Getting Started With CVAVR





new embedded project using cvavr





new embedded project using cvavr using atmega




new embedded project using cvavr



programming using cvavr




if you want to interface lcd also:

lcd interfacing using cvavr



ASSIGNMENT 1 -CONTROLLING LEDs

questions:


  1. GLOW A SINGLE LED
  2. GLOW 8 LED OF A PORT
  3. BLINKING A SINGLE LED
  4. BLINKING  8 LED OF A PORT
  5. ALTERNATE GLOWING LED s 
  6. GLOWING LED IN INCREASING PATTERN
  7. GLOWING LED IN DECREASING PATTERN
  8. GLOWING LED IN CONVERGING PATTERN
  9. GLOWING LED IN DIVERGING PATTERN
  10. BOTH CONVERGING AND DIVERGING PATTERN
  11. INCREASING AND DECREASING PATTERN
  12. WITH A SWITCH GLOW 1 LED
  13. WITH A SWITCH GLOW ALL 8 LEDS
  14. WITH 4 DIFFERENT SWITCH GLOW 4 DIFFERENT PATTERN
  15. WITH 1 SWITCH GLOW 4 DIFFERENT PATTERN 

1ST TRY YOURSEELF
Related Posts Plugin for WordPress, Blogger...

Popular Posts