Thứ Sáu, 14 tháng 12, 2018

DIY - Waveform Generator using AVR Microcontroller

To interface 8-bit DAC with AVR microcontroller ATMega32 and generate different waveforms like Square Wave, Sine Wave, Triangular Wave, Staircase Wave and Saw-tooth Wave.
Instruments
·         AVR Development Board
·         ADC – DAC card
·         Digital Storage Oscilloscope (DSO)
·         Power Supply
Apparatus
·         Connecting Wires
·         CRO Probes
·         General purpose PCB
Components
·         AVR Microcontroller - ATMega32
·         8-bit - DAC0808
·         Operational Amplifier – LM741
·         Push Button Switches
·         Resistors and Capacitors
Theory
To generate different Analog waveforms using AVR microcontroller it is required to interface a DAC that will convert the Digital inputs given by microcontroller into corresponding Analog outputs and thus it generates different analog waveforms. The DAC output is current equivalent of digital input. So to convert it in to voltage a current to voltage converter is required. This current to voltage converter is build using Op-Amp LM741.
Circuit Description
PORTA is used as input and PORTC is used as output. Four push button switches are connected to PORTA pins PA0 to PA3. Rest four pins PA4 to PA7 are connected to Vcc. PORTC is connected to input pins A1 to A8 of DAC0808. Vref pin of DAC0808 is connected to Vcc through 5 K Resistor to generate require output current Iref. –Vref pin is connected to ground through 5 K Resistor. The current output Iout of DAC0808 is connected to inverting input of Op-Amp LM741 that is used as current to voltage converter. A 5 K load Resistor is connected in the output of LM741 to generate voltage output. Complete circuit requires 3 different supplies +5 V, +12 V and -12 V. ATMega32 and DAC0808 require +5 V. DAC0808 require -12V for its Vee supply input. LM741 requires +12 V and -12 V for biasing. For detailed Circuit Diagram click on Circuit Diagram Tab
Here is the snap of circuit built using AVR Development Board, ADC-DAC card and Op-Amp
DIY - Waveform Generator using AVR Microcontroller
Fig. 1: Prototype of AVR ATMega32 based Waveform (Function) Generator

Circuit Operation & Software Program

Circuit Operation
To understand circuit operation we need to understand how microcontroller gives different data to DAC to generate require waveform
Square Wave –To generate Square Wave the microcontroller gives alternatively 00h (low) and FFh (high) outputs as an input to DAC after some delay. The DAC will generate corresponding alternate low and high Analog outputs through Op-Amp circuit as +12 V and -12 V that will generate Square Wave pattern.
Stair Case Wave –To generate Stair Case Wave the microcontroller first gives 00h (low) output and then after some delay it increases output in steps like 33h, 66h, 99h, CCh and FFh. The DAC will generate Analog output as per these inputs from microcontroller that looks like Stair Case Wave.
Sine Wave –To generate Sine Wave it is required to make a table of data that contains values calculated using equation
Value = 5 + 5sin(?)
for different angle values like 30o, 60o, 90o,....... of ?
Note: the value is Analog output value. The applied digital input must be corresponding to generate this Analog output
The values form this table are given to DAC. So DAC will generate corresponding Analog output that generates Sine Wave in output
Triangular Wave –To generate Triangular Wave the microcontroller first gives data from 00h to FFh and then from FFh to 00h. This will generate linearly increasing and decreasing output through Op-Amp that will generate Triangular Wave.
SawTooth Wave –Generating SawTooth is similar to generating Triangular Wave. The microcontroller gives data from 00h to FFh to generate positive ramp or gives data from FFh to 00h to generate negative ramp.
The given circuit generates all these different waveforms when any switch is pressed
Switch
Waveform
Switch 1
It generates Square Wave
Switch 2
It generates two types of Stairase Waveforms. When pressed even times generates rising and falling Staircase Wave and when pressed odd times it generates rising Staircase Wave
Switch 3
It generates Sine Wave
Switch 4
When it pressed first time it generates Triangular Wave
Second time it generates SawTooth Wave with positive ramp
And Third time it generates SawTooth Wave with negative ramp
Again it start from Triangular Wave
Software Program
For the Software Program Code click on Code Tab.The program is written in C language. It is compiled in AVR studio.  

Procedure:

1.      Connect push button switch inputs to port A
2.      Connect PORTC to data inputs of DAC0808
3.      Connect Output of DAC to Input of Op-Amp Circuit
4.      Connect Output of Op-Amp circuit to 1st channel of DSO using CRO probe
5.      Connect +12 V and -12 V supply to Op-Amp circuit and ADC-DAC card
6.      Give 5 V supply to AVR development board by connecting transformer to built in power supply
7.      Give 5 V supply to DAC through development board 5 V supply output
8.      Switch on all the supply
9.      Press any of the push button and observe output wave on DSO
Here are the images of circuit test setup
DIY - Waveform Generator using AVR Microcontroller
Fig. 2: Image showing AVR ATMega32 based Waveform Generator tested by an Oscilloscope
Result
Here are the images of different output waveforms on DSO 
DIY - Waveform Generator using AVR Microcontroller
Fig. 3: Image showing different AC Waveforms generated by AVR ATMega32 based Function Generator
DIY - Waveform Generator using AVR Microcontroller
Fig. 4: Image showing different Triangle Waveforms generated by AVR ATMega32 based Function Generator
Conclusion
The different waveforms like Square Wave, Triangular Wave, Sine Wave, Square Wave, SawTooth Wave can be generated by interfacing DAC with microcontroller.
.
Circuit:
Circuit Diagram of AVR ATMega32 and DAC0808 based Function Generator
Code:
#include <avr/io.h>
#include <util/delay.h>

unsigned int sine_value[13] = {128,192,238,255,238,192,128,64,17,0,17,64,128};

void square_wave()
  {
   while(PINA==0xF0)
   {
    PORTC = 0xFF;
  _delay_us(500);
  PORTC = 0x00;
  _delay_us(500);
   }
  }
void staircase_wave1()
  {
   while(PINA==0xF0)
   {
    PORTC = 0x00;
  _delay_us(200);
  PORTC = 0x33;
  _delay_us(200);
  PORTC = 0x66;
  _delay_us(200);
  PORTC = 0x99;
  _delay_us(200);
  PORTC = 0xCC;
  _delay_us(200);
  PORTC = 0xFF;
  _delay_us(200); 
   }
  }
void staircase_wave2()
  {
   while(PINA==0xF0)
   {
    PORTC = 0x00;
  _delay_us(100);
  PORTC = 0x33;
  _delay_us(100);
  PORTC = 0x66;
  _delay_us(100);
  PORTC = 0x99;
  _delay_us(100);
  PORTC = 0xCC;
  _delay_us(100);
  PORTC = 0xFF;
  _delay_us(100);
       PORTC = 0xCC;
  _delay_us(100);
  PORTC = 0x99;
  _delay_us(100);
  PORTC = 0x66;
  _delay_us(100);
  PORTC = 0x33;
  _delay_us(100);
   
   }
  }
void sine_wave()
  {
   int i;
while(PINA==0xF0) 
   {
  for(i=0;i<13;i++) 
    {
   PORTC = sine_value[i]; 
   _delay_us(20); 
      }
   }
  }
void tri_wave()
  {
   int t;
while(PINA==0xF0)
   {
    for(t=0;t<255;t++) PORTC = t;
  for(t=255;t>0;t--) PORTC = t;
       }
   }
void ramp1()
  {
   int t;
while(PINA==0xF0)
   {
    for(t=0;t<255;t++) {PORTC = t;_delay_us(2);}
   }
   }
void ramp2()
  {
   int t;
while(PINA==0xF0)
   {
    for(t=255;t>0;t--) {PORTC = t;_delay_us(2);}
   }
   }

int main(void)
{
   int c=0,c1=0;
   DDRC = 0xFF;
   PORTC = 0x00;
   while(PINA==0xF0);
loop:switch(PINA)
   {
    case 0xF1:
    _delay_ms(200);
    square_wave();
    break;
    case 0xF2:
    _delay_ms(200);
    c1++;
    if((c1%2)==0)staircase_wave1();
    else staircase_wave2();
    break;
    case 0xF4:
    _delay_ms(200);
    sine_wave();
     break;
    case 0xF8:
      _delay_ms(200);
    c++;
    if(c==1) tri_wave();
    else if(c==2) ramp1();
    else if(c==3) { ramp2();c=0; }
    break;
       }
   goto loop;
}

Không có nhận xét nào:

Đăng nhận xét

Bài đăng mới nhất

Hướng dẫn sử dụng Cân điện tử Fujihatsu FTC-01

Hướng dẫn sử dụng Cân điện tử Fujihatsu FTC-01 # candientu ,  # fujihatsu ,  # candientufujihatsu  #candientu,  # candientufujhatsu , #fuji...

Bài đăng phổ biến