Xp4fp Merged

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

RAJSHAHI UNIVERSITY OF ENGINEERING & TECHNOLOGY

Course No. : EEE 4210

Course Title : Embedded System Design Sessional

Experiment No. : 04

Experiment Name: Study of Different Signals Generations Based On R-2R


Ladder DAC Using Microcontroller

Submitted To:
Md. Razon Chowdhury
Assistant Professor,
Dept. of EEE,
RUET
Submitted By:
Name: Nafis Hasan Alif
Roll: 1801015
Dept.: EEE
Sec.: A
Experiment No.: 04
4.1 Experiment Name: Study of Different Signals Generations Based On R-2R Ladder DAC
Using Microcontroller
4.2 Objectives:
 To know about digital to analog converting process.
 To know about R-2R ladder DAC.
 To know the Arduino code for different signal generation.

4.3 Theory:
R-2R Digital-to-Analogue Converter, or DAC, is a data converter which use two precision resistor
to convert a digital binary number into an analogue output signal proportional to the value of the
digital number. The R-2R ladder DAC is a type of digital-to-analog converter that uses a resistive
ladder network. The resistive value of 2R is always twice the value of the base resistor, R. This
makes it easier to maintain the required accuracy of the resistors along the ladder network
compared to the previous weighted resistor DAC. The basic 2 bit R-2R ladder DAC circuit using
an op-amp requires only two values of resistors, R and 2R, and the number of digits per binary
word is assumed to be two. The typical value of feedback resistor is Rf = 2R, and the resistance R
is normally selected any value between 2.5 k to 10 k.

Figure 4.1: R-2R ladder circuit


4.4 Required Apparatus:
1. Op-amp (741)
2. Resistors- (1K – 7 pieces) and (2K – 8 pieces)
3. Arduino
4. Programming Device (computer)
5. Capacitor (0.1 micro-F)
6. Push Buttons (2 pieces)
7. Connecting Wires
8. USB cables
9. Oscilloscope
10. Supply Voltage

4.5 Experimental Setup:

Figure 4.2: Setup


4.6 Arduino Codes for Different Waveform Generations:

Arduino Code for Sinusoidal Waveform Generations:

int ang=0; void


setup() {
DDRD=B11111111;
} void loop() { int
value=(255*sin(3.1416*ang/180)+255)/2;
ang=ang+10;
//delay(1);
if (ang>360)
ang=0;
PORTD=value;
}
Arduino Code for Triangular Waveform Generations:

int i = 0; void
setup() {
DDRD = B11111111;
} void loop() {
if (i < 255)
{PORTD = i;}
else
{PORTD=255*2-i;}
if (i>= 255*2) {i=0;}
i=i+1;
}

Arduino Code for Sawtooth Waveform Generations:

int i = 0; void
setup() {
DDRD = B11111111;
} void loop()
{ PORTD =
i; i=i+1; if
(i > 255)
{i = 0;
}
}
Arduino Code for changing frequency of a signal:
int ang=0; int i=0;
int butt8_st_new=0;
int butt8_st_old=0;
int butt9_st_new=0;
int butt9_st_old=0;
void setup(){
DDRD=B11111111;
pinMode(8,INPUT); pinMode(9,INPUT);
} void loop() { int
butt8_st_new=digitalRead(8); if
(butt8_st_old==0 && butt8_st_new==1)
{i=i+20;}
butt8_st_old=butt8_st_new; int
butt9_st_new=digitalRead(9); if
(butt9_st_old==0 &&
butt9_st_new==1)
{i=i-20;
if (i<0)
{i=0;}
}
butt9_st_old=butt9_st_new; int
value=(255*sin(3.1416*ang/180)+255)/2;
ang=ang+10; if (ang>360) {ang=0;}
PORTD=value;
delayMicroseconds(i);
}

4.7 Generated Waveforms:

Figure 4.3: Sine wave

Figure 4.4: Triangular wave


Figure 4.5: Sawtooth wave

Figure 4.6: Sinusoidal waveform with increasing frequency (left) and sinusoidal waveform
with decreasing frequency (right), frequency controlled by pressing push buttons

4.8 Conclusion:
In this experiment digital to analog conversion was done using R-2R ladder circuit. The
connection was made carefully and the code for Arduino was given correctly. As a result we
get our desired analog sinusoidal, triangular and sawtooth signal.
RAJSHAHI UNIVERSITY OF ENGINEERING & TECHNOLOGY

Course No. : EEE 4210

Course Title : Embedded System Design Sessional

Experiment No. : 03

Experiment Name: Experimental study of 8-bit timer/counter with PWM


using ATmega328 microcontroller

Submitted To:
Md. Razon Chowdhury
Assistant Professor,
Dept. of EEE,
RUET
Submitted By:
Name: Nafis Hasan Alif
Roll: 1801015
Dept.: EEE
Sec.: A
Experiment No.:03

3.1 Name of the experiment: Experimental study of 8-bit timer/counter with PWM using
ATmega328 microcontroller

3.2 Objectives:
• To understand the principles of Pulse Width Modulation (PWM) in
microcontrollers.
• To explore and compare two different modes of operation: Fast PWM and Phase
Correct PWM
• To observe and analyze the timing diagram of the timer/counter using an
oscilloscope.
• To gain hands-on experience in programming ATmega328 microcontroller with
Arduino for PWM generation.

3.3 Theory:
Pulse Width Modulation is a technique used in microcontrollers to generate analog-like signals
through digital means. PWM is achieved by varying the duty cycle of a square wave signal. The
ATmega328 microcontroller, commonly used in Arduino boards, features an 8-bit Timer/Counter
which can be configured for PWM generation. Fast PWM and Phase Correct PWM are two
modes of operation for PWM generation.
In Fast PWM mode, the timer/counter counts up to a specified value (255 for an 8-bit timer),
resets to zero, and then generates a PWM signal. The control word configuration for Fast PWM
involves setting specific bits in the Timer/Counter Control Register A (TCCR0A). For example,
the control word for Fast PWM can be expressed as follows:
TCCR0A = _BV(WGM00) | _BV(WGM01) |_BV(COM0A1)
That means the 0th bit, 1st bit, and the 7th bit will be high and the rest of the bit of the control
word will be zero.
Contrary to Fast PWM, Phase Correct PWM mode involves the counter counting up and then
counting down, creating a symmetric PWM signal. In this mode, the control word is configured
to produce a waveform with a symmetrical duty cycle. For example, the control word for Phase
Correct PWM is defined as:
TCCR0A = _BV(WGM00) | _BV(WGM01) |_BV(COM0A1) | _BV(COM0B1) |
_BV(COM0B0) ;
That means the 0th bit, 1st bit, 4th bit, 5th bit, and 7th bit will be high and the rest of the bit of
the control word will be zero.
3.4 Required Apparatus:
1. Arduino Uno (for ATmega328 microcontroller)
2. Oscilloscope
3. jumper wires
4. Laptop
5. Power supply

3.5 Experimental Setup:

Figure 3.1: Experimental setup for making microcontroller-based timer

3.6 Arduino Code:


3.6.1 For fast PWM mode:

void setup() {
pinMode(6, OUTPUT);

TCCR0A = _BV(WGM00) | _BV(WGM01) |_BV(COM0A1)


OCR0A = 100;
}
void loop() {
}
3.6.2 For phase correct mode:
void setup() {
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);

TCCR0A = _BV(WGM00) | _BV(WGM01) |_BV(COM0A1) | _BV(COM0B1) |


_BV(COM0B0) ;
TCCR0B = _BV(CS00);
OCR0A = 100;
OCR0B = 100;
}
void loop() {

3.7 Output Waveshape:

Figure 3.2: Timing diagram for fast PWM mode (Non – inverting)
Figure 3.3: Timing diagram for fast PWM mode (Inverting)

Figure 3.4: Timing diagram for phase correct PWM mode

3.8 Conclusion:
Using the ATmega328 microcontroller and Arduino, we successfully investigated and contrasted
two forms of PWM functioning in this experiment. A symmetrical waveform is produced by the
Phase Correct PWM mode, but a waveform with a quick rise time is produced by the Fast PWM
mode. We were able to understand how the timer/counter behaved in order to generate PWM
signals by looking at the timing diagrams on the oscilloscope.
Our experiment was successful since the timing diagram we saw was what we anticipated to see.
RAJSHAHI UNIVERSITY OF ENGINEERING & TECHNOLOGY

Course No. : EEE 4210

Course Title : Embedded System Design Sessional

Experiment No. : 05

Experiment Name: Single-phase Half-bridge inverter designing and


implementation

Submitted To:
Md. Razon Chowdhury
Assistant Professor,
Dept. of EEE,
RUET
Submitted By:
Name: Nafis Hasan Alif
Roll: 1801015
Dept.: EEE
Sec.: A
Experiment No. 05
5.1 Project Name Single-phase Half-bridge inverter designing and implementation
5.2 Objectives
 To understand the principles of Half-Bridge inverter circuit
 To implement the circuit in lab
5.3 Required Apparatus
1. 1.A3120 Optocoupler driver (2 pieces)
2. MOSFET IRF 240N (2 pieces)
3. One pair of two-pin connectors
4. Two three-pin connectors
5. Two eight-pin integrated circuit holders
6. LED (two pieces)
7. Diode (two pieces)
8. Capacitor (2 pieces,100uF);
9. Resistor (470Ω 2 pieces; 1kΩ 4 pieces)
10. Connecting wires
5.4 Experimental Setup

Fig.5.1. Experimental Setup of the project


Fig.5.2. PCB layout
5.5 Arduino Code
int ang =0; int
d=10; void setup()
{
pinMode(10, OUTPUT); pinMode(9,
OUTPUT);
TCCR2A = B10110001;
TCCR2B = B00000101;
TIMSK2 = B00000001;
}
ISR(TIMER2_OVF_vect)
{
int duty = (255*sin(ang*3.1416/180)+255)/2;
OCR2A = duty; if (duty==0)
{d=0; }
else {d=10;
} int y= duty+d; if
(y>=255) {y=255;
} else {y=y;
}
OCR2B=y; ang
=ang+5; if (ang>360)
{ ang =0;
} } void
loop()
{
}
5.6 Working Principle
1. Utilizing the Arduino microcontroller, a bipolar AC signal was generated.
2. The pair of printed circuit boards (PCBs) incorporated an optocoupler driver circuit, which,
assisted by an external source, transformed the low-voltage signal into 18 V DC. This
setup also facilitated the supply of Arduino signals to the MOSFET gate.
3. The MOSFET gate played a pivotal role in regulating the current flow from the 36 V
connected to the collector to the ground linked to the emitter terminal.
4. Illustrated in Fig. 1, the combination of the two PCBs (acting as a switch) resulted in the
production of an AC signal across the load.
5.7 Output waveform

Fig.5.3. Output Waveform of the Project


5.8 Result

The signal frequency was, 𝑓 = 1= 1 = 5.15 Hz


𝑇 194𝑚𝑆

5.9 Discussion & Conclusion


The voltage rating of 110V AC, which the induction motor used in this experiment, was
substantially higher than the RMS voltage of 29 V. There were modifications to the frequency that
were required to start motor activation. The induction motor ran at a lower frequency when the
voltage dropped below the rated frequency, according to an analysis of the voltage vs. frequency
graph. It was essential that voltage and frequency have a proportionate connection. As a result, the
induction motor operated effectively at a frequency of 5.15 Hz and 29V (rms).

You might also like