Professional Documents
Culture Documents
Xp4fp Merged
Xp4fp Merged
Xp4fp Merged
Experiment No. : 04
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.
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;
}
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);
}
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
Experiment No. : 03
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
void setup() {
pinMode(6, OUTPUT);
Figure 3.2: Timing diagram for fast PWM mode (Non – inverting)
Figure 3.3: Timing diagram for fast PWM mode (Inverting)
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
Experiment No. : 05
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