Difference between revisions of "Arduino/C3/Digital-Logic-Design-with-Arduino/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| style="border-spacing:0;" | style="background-color:#c0c0c0;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| '''Vi...")
 
 
Line 146: Line 146:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Point to the /home/spoken/Assembly folder
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Point to the /home/spoken/Assembly folder
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| This will assemble the code and create a file '''boolean.hex'''.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| This will assemble the code and create a file '''boolean.hex'''.
 +
 +
|-
 +
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Clear the terminal.
 +
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Let us clear the screen.
  
 
|-
 
|-
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"|  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"|  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Next we need to upload the code to the '''Arduino'''.
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Next we need to upload the code to the '''Arduino'''.
 
Let us clear the screen.
 
  
 
|-
 
|-
Line 160: Line 162:
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| For this, type
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| For this, type
  
'''avrdude space hyphen p space atmega328p space hyphen c space arduino space hyphen b space 115200 space hyphen capital P space forward slash dev forward slash ttyACM0 space hyphen capital U spach flash colon wcolon boolean.hex'''
+
'''avrdude space hyphen p space atmega328p space hyphen c space arduino space hyphen b space 115200 space hyphen capital P space forward slash dev forward slash ttyACM0 space hyphen capital U space flash colon wcolon boolean dot hex'''
  
 
and press''' Enter.'''
 
and press''' Enter.'''
Line 199: Line 201:
  
 
D = WXY + W′Z
 
D = WXY + W′Z
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| We are going to implement these equations in our program and verify their truth table.
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| We are going to implement these equations in our program and verify their '''truth table'''.
  
 
|-
 
|-
Line 269: Line 271:
  
 
The values of '''input variables W, X, Y '''and '''Z '''are stored in '''registers r17, r18, r19 '''and '''r20 '''respectively.
 
The values of '''input variables W, X, Y '''and '''Z '''are stored in '''registers r17, r18, r19 '''and '''r20 '''respectively.
 +
  
 
The values of '''r17, r18, r19 '''and '''r20 '''are stored in the '''dummy variables r0, r1, r2 '''and '''r3'''.
 
The values of '''r17, r18, r19 '''and '''r20 '''are stored in the '''dummy variables r0, r1, r2 '''and '''r3'''.
 +
  
 
These values are used to restore the '''original registers '''after performing '''operations. '''
 
These values are used to restore the '''original registers '''after performing '''operations. '''
Line 315: Line 319:
 
<nowiki>;Z'= r7</nowiki>
 
<nowiki>;Z'= r7</nowiki>
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The '''comp subroutine '''is used to find the '''complement '''of a '''variable'''.  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The '''comp subroutine '''is used to find the '''complement '''of a '''variable'''.  
 +
  
 
The '''complement '''of '''W, X, Y '''and '''Z '''are calculated and stored in '''r21, r22, r23 '''and '''r24 '''respectively.  
 
The '''complement '''of '''W, X, Y '''and '''Z '''are calculated and stored in '''r21, r22, r23 '''and '''r24 '''respectively.  
 +
  
 
The values of '''r21, r22, r23 '''and '''r24 '''are stored in the '''dummy variables r4, r5, r6 '''and '''r7'''.
 
The values of '''r21, r22, r23 '''and '''r24 '''are stored in the '''dummy variables r4, r5, r6 '''and '''r7'''.
Line 361: Line 367:
  
  
The value in '''r0''' is left shifted thrice and stored in '''r30'''. Now, the fourth '''bit''' of '''r30''' holds the result of '''B'''.
+
The value in '''r0''' is left shifted thrice and stored in '''r30'''.  
 +
 
 +
 
 +
Now, the fourth '''bit''' of '''r30''' holds the result of '''B'''.
  
 
|-
 
|-
Line 390: Line 399:
 
or r30, r0
 
or r30, r0
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The '''logic''' for '''C''' is implemented and the result is stored in '''r0'''.  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The '''logic''' for '''C''' is implemented and the result is stored in '''r0'''.  
 +
  
 
The value in '''r0''' is left shifted four times and stored in '''r30'''.  
 
The value in '''r0''' is left shifted four times and stored in '''r30'''.  
 +
  
 
Now, the fifth '''bit''' of '''r30''' holds the result of '''C'''.
 
Now, the fifth '''bit''' of '''r30''' holds the result of '''C'''.
Line 425: Line 436:
 
or r30,r0
 
or r30,r0
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The '''logic''' for '''D''' is implemented and the result is stored in '''r0'''.  
 
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The '''logic''' for '''D''' is implemented and the result is stored in '''r0'''.  
 +
  
 
The value in '''r0''' is left shifted five times and stored in '''r30'''.
 
The value in '''r0''' is left shifted five times and stored in '''r30'''.
 +
  
 
Now, the sixth '''bit''' of '''r30''' holds the result of '''D'''.
 
Now, the sixth '''bit''' of '''r30''' holds the result of '''D'''.
Line 495: Line 508:
  
 
'''avrdude -p atmega328p -c arduino -b 115200 -P /dev/ttyACM0 -U flash:w: combination.hex'''
 
'''avrdude -p atmega328p -c arduino -b 115200 -P /dev/ttyACM0 -U flash:w: combination.hex'''
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| * To upload, press the up arrow to get the previous command.  
+
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"|  
 +
* To upload, press the up arrow to get the previous command.  
  
 
* Now change the filename as shown and press Enter.
 
* Now change the filename as shown and press Enter.
Line 535: Line 549:
  
 
Spoken Tutorial workshops
 
Spoken Tutorial workshops
| style="background-color:#ffffff;border-top:1pt solid #000001;border-bottom:0.75pt solid #000001;border-left:1pt solid #000001;border-right:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The''' Spoken Tutorial Project''' Team:
+
| style="background-color:#ffffff;border-top:1pt solid #000001;border-bottom:0.75pt solid #000001;border-left:1pt solid #000001;border-right:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The''' Spoken Tutorial Project''' Team conducts workshops and gives certificates.
 
+
* conducts workshops and gives certificates.
+
  
 
For more details, please write to us.
 
For more details, please write to us.

Latest revision as of 09:11, 9 April 2018

Visual Cue Narration
Slide 1: Welcome to the Spoken Tutorial on Digital Logic Design with Arduino.
Slide 2:

Learning objectives

In this tutorial, we will learn to:
  • Implement and verify the AND, OR and XOR operations in assembly.
  • Implement and verify simple Combinational Logic.
Slide 3:

Pre-requisites

To follow this tutorial, you should have basic knowledge of:
  • Electronics and
  • Assembly language
Slide 4:

System Requirement

To record this tutorial, I am using:
  • Arduino UNO Board
  • Ubuntu Linux operating system version 14.04
Slide 5:

External Devices

We also require some external devices such as:
  • Breadboard
  • Arduino UNO Board
  • Seven Segment Display
  • 220-ohm Resistor
  • Decoder (7447 IC) and
  • Jumper Wires
Show the image: We will use the same circuit setup as we did for the decoder in the earlier tutorial.
show the live connection Let us see the live connection setup.
Now we will write an assembly program to verify the logical AND operations.
Open text editor Open any text editor and type the following program.
Highlight according to narration:

.include "/home/spoken/Assembly/m328Pdef.inc"

ldi r16, 0b00111100

out DDRD, r16

m328Pdef.inc file and the source code are available in the code files link of this tutorial.

You can download and use it.

The highlighted code configures pins 2, 3, 4 and 5 of the Arduino as output pins.

ldi r16, 0b00000001

ldi r17, 0b00000001

and r16,r17

We are considering only the first bit of r16 and r17 for our boolean operations. Here, both are 1.

This line performs bitwise AND operation on the bits of r16 and r17. The result is stored in r16.

ldi r20, 0b00000010 The rest of the program takes care of displaying this output.

The LSB of r16 has our result. This has to be shifted by two positions to the left.

rcall loopw This line of code calls the loop named loopw.

This loop takes care of shifting the LSB of r16 twice.

out PORTD, r16

start:

rjmp start

The value in r16 is sent to PORTD.

This displays either 0 or 1 on the Seven segment display.

loopw: lsl r16

dec r20 brne loopw ret

Here, contents of r16 are left shifted once.

Then the value of r20 is decremented by 1.

If the value of r20 is not equal to zero, the loop is repeated again.

Save the code I’ll save the code as boolean.asm in the home slash spoken slash Assembly folder.
Switch to the terminal. Switch to the terminal.
Type,

> cd /home/spoken/Assembly

> avra boolean.asm

Go to the folder where boolean.asm file is saved.

Type, avra boolean.asm and press Enter.

Point to the /home/spoken/Assembly folder This will assemble the code and create a file boolean.hex.
Clear the terminal. Let us clear the screen.
Next we need to upload the code to the Arduino.
Type,

avrdude -p atmega328p -c arduino -b 115200 -P /dev/ttyACM0 -U flash:w: boolean.hex

For this, type

avrdude space hyphen p space atmega328p space hyphen c space arduino space hyphen b space 115200 space hyphen capital P space forward slash dev forward slash ttyACM0 space hyphen capital U space flash colon wcolon boolean dot hex

and press Enter.

Point to the output Now you can see that the digit one on the seven segment display is glowing.
Slide 7:

Assignment 1

Pause the tutorial and do the below assignment.

Modify the values of r16 and r17 to verify the rest of the truth table of AND.

Replace the keyword and in the program with or to perform logical OR operation.

Replace the keyword and in the program with xor to perform logical XOR operation.

Next, we will implement and verify few simple combinational logics.
Show the setup Let us see the live connection setup. It will be the same as the previous setup.
Slide:

A = W′

B = WX′Z′ + W′X

C = WXY′ + X′Y + W′Y

D = WXY + W′Z

We are going to implement these equations in our program and verify their truth table.
Truth Table: This is the truth table for the equations shown above.

Here W, X, Y and Z are the inputs.

A, B, C and D are the outputs.

Let us consider the first row of the truth table. Thus, all the inputs will be zeros.

As per the truth table, we can expect the output as 1.

We will display the output on the seven segment display.

Let us write an assembly program to implement and verify these equations.
Open text editor Open any text editor and type the following program.
.include "/home/spoken/Assembly/m328Pdef.inc"

ldi r16, 0b00111100

out DDRD, r16

Let me explain the program.

This line configures pins 2,3,4 and 5 of the Arduino as output pins.

;dummy for output

ldi r30, 0b00000000

;W = r0

ldi r17, 0b00000000

mov r0, r17

;X = r1

ldi r18, 0b00000000

mov r1, r18


;Y = r2

ldi r19, 0b00000000

mov r2, r19


;Z = r3

ldi r20, 0b00000000

mov r3, r20

r30 is a dummy variable for storing the output.


The values of input variables W, X, Y and Z are stored in registers r17, r18, r19 and r20 respectively.


The values of r17, r18, r19 and r20 are stored in the dummy variables r0, r1, r2 and r3.


These values are used to restore the original registers after performing operations.

mov r16, r17

rcall comp

mov r21, r16

mov r4, r21

;W'= r4

mov r16, r18

rcall comp

mov r22, r16

mov r5, r22

;X'= r5

mov r16, r19

rcall comp

mov r23, r16

mov r6, r23

;Y'= r6

mov r16, r20

rcall comp

mov r24, r16

mov r7, r24

;Z'= r7

The comp subroutine is used to find the complement of a variable.


The complement of W, X, Y and Z are calculated and stored in r21, r22, r23 and r24 respectively.


The values of r21, r22, r23 and r24 are stored in the dummy variables r4, r5, r6 and r7.

lsl r4

lsl r4

or r30, r4

Note that A is nothing but the complement of W.

Now, we have implemented the first equation.

Next, we perform two left shift operations and store the value in r30.

Thus, the third bit of the r30 has the value of A.

rcall reload The reload subroutine reloads the values r0, r1, r2, r3, r4, r5, r6 and r7 from its copies.

They might have changed during previous operations.

;Logic for B

and r0, r5

and r0, r7

and r4, r1

or r0, r4

lsl r0

lsl r0

lsl r0


or r30, r0

The logic for B is implemented and the result is stored in r0.


The value in r0 is left shifted thrice and stored in r30.


Now, the fourth bit of r30 holds the result of B.

rcall reload

;Logic for C

and r0,r1

and r0,r6

and r5,r2

and r4,r2

or r0,r5

or r0,r4

lsl r0

lsl r0

lsl r0

lsl r0

or r30, r0

The logic for C is implemented and the result is stored in r0.


The value in r0 is left shifted four times and stored in r30.


Now, the fifth bit of r30 holds the result of C.

rcall reload

;Logic for D

and r0,r1

and r0,r2

;

and r4,r3

;

or r0,r4

lsl r0

lsl r0

lsl r0

lsl r0

lsl r0


or r30,r0

The logic for D is implemented and the result is stored in r0.


The value in r0 is left shifted five times and stored in r30.


Now, the sixth bit of r30 holds the result of D.

out PORTD, r30


start:

rjmp start

comp:

mov r31, r16

ldi r16, 0b00000001

eor r16, r31

ret

reload:

mov r0,r17

mov r1,r18

mov r2, r19

mov r3,r20

mov r4, r21

mov r5, r22

mov r6, r23

mov r7, r24

ret

Finally, the value stored in r30 is sent to PORTD to be displayed.
Save the code as combination.asm in the home slash spoken slash Assembly folder.
Switch to the terminal.
Type,

> cd /home/spoken/Assembly

> avra combination.asm

Type, avra combination.asm and press Enter.
Point to the /home/spoken/Assembly folder This will assemble the code and create a file combination.hex.

Let us clear the terminal

Type,

avrdude -p atmega328p -c arduino -b 115200 -P /dev/ttyACM0 -U flash:w: combination.hex

  • To upload, press the up arrow to get the previous command.
  • Now change the filename as shown and press Enter.
Point to the output Now you can verify the truth table with the output shown on the seven-segment display.
Assignment: Pause the tutorial and do the below assignment.

Change the values of W, X, Y and Z and verify different rows of the truth table.

This brings us to the end of this tutorial. Let us summarize.
Slide 11:

Summary

In this tutorial, we learnt to:
  • Implement and verify the AND, OR and XOR operations in assembly.
  • Implement and verify simple Combinational Logic.
Slide 12:

About Spoken Tutorial project

The video at the following link summarizes the Spoken Tutorial project.

Please download and watch it.

Slide 13:

Spoken Tutorial workshops

The Spoken Tutorial Project Team conducts workshops and gives certificates.

For more details, please write to us.

Slide 14:

Forum for specific questions

Please post your timed queries in this forum.
Slide 15:

Acknowledgement

Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.

More information on this mission is available at

this link.

This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.  

This is Priya from IIT Bombay signing off.

Thanks for watching.

Contributors and Content Editors

Nancyvarkey, Nirmala Venkat