Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Dueck R.Digital design with CPLD applications and VHDL.2000

.pdf
Скачиваний:
52
Добавлен:
23.08.2013
Размер:
9 Mб
Скачать

A P P E N D I X E

EPROM Data for a Digitial Function Generator

769

SQUARE

 

 

 

 

Base

 

 

Byte Addresses

 

Address

0 1 2

3

4 5 6 7 8 9 A B C D

E F

0100

FF

FF

FF

FF

0110

FF

FF

FF

FF

0120

FF

FF

FF

FF

0130

FF

FF

FF

FF

0140

FF

FF

FF

FF

0150

FF

FF

FF

FF

0160

FF

FF

FF

FF

0170

FF

FF

FF

FF

0180

00

00

00

00

0190

00

00

00

00

01A0

00

00

00

00

01B0

00

00

00

00

01C0

00

00

00

00

01D0

00

00

00

00

01E0

00

00

00

00

01F0

00

00

00

00

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

FF

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

TRIANGLE

Base

 

 

 

 

 

 

Byte Addresses

 

 

 

 

 

 

Address

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

0200

80

82

84

86

88

8A

8C

8E

90

92

94

96

98

9A

9C

9E

0210

A0

A2

A4

A6

A8

AA

AC

AE

B0

B2

B4

B6

B8

BA

BC

BE

0220

C0

C2

C4

C6

C8

CA

CC

CE

D0

D2

D4

D6

D8

DA

DC

DE

0230

E0

E2

E4

E6

E8

EA

EC

F0

F2

F4

F6

F8

FA

FC

FE

 

0240

FE

FC

FA

F8

F6

F4

F2

F0

EE

EC

EA

E8

E6

E4

E2

E0

0250

DE

DC

DA

D8

D6

D4

D2

D0

CE

CC

CA

C8

C6

C4

C2

C0

0260

BE

BC

BA

B8

B6

B4

B2

B0

AE

AC

AA

A8

A6

A4

A2

A0

0270

9E

9C

9A

98

96

94

92

90

8E

8C

8A

88

86

84

82

80

0280

7E

7C

7A

78

76

74

72

70

6E

6C

6A

68

66

64

62

60

0290

5E

5C

5A

58

56

54

52

50

4E

4C

4A

48

46

44

42

40

02A0

3E

3C

3A

38

36

34

32

30

2E

2C

2A

28

26

24

22

20

02B0

1E

1C

1A

18

16

14

12

10

0E

0C

0A

08

06

04

02

00

02C0

02

04

06

08

0A

0C

0E

10

12

14

16

18

1A

1C

1E

20

02D0

22

24

26

28

2A

2C

2E

30

32

34

36

38

3A

3C

3E

40

02E0

42

44

46

48

4A

4C

4E

50

52

54

56

58

5A

5C

5E

60

02F0

62

64

66

68

6A

6C

6E

70

72

74

76

78

7A

7C

7E

80

SAWTOOTH

Base

 

 

 

 

 

 

Byte Addresses

 

 

 

 

 

 

Address

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

0300

00

01

02

03

04

05

06

07

08

09

0A

0B

0C

0D

0E

0F

0310

10

11

12

13

14

15

16

17

18

19

1A

1B

1C

1D

1E

1F

0320

20

21

22

23

24

25

26

27

28

29

2A

2B

2C

2D

2E

2F

0330

30

31

32

33

34

35

36

37

38

39

3A

3B

3C

3D

3E

3F

0340

40

41

42

43

44

45

46

47

48

49

4A

4B

4C

4D

4E

4F

0350

50

51

52

53

54

55

56

57

58

59

5A

5B

5C

5D

5E

5F

0360

60

61

62

63

64

65

66

67

68

69

6A

6B

6C

6D

6E

6F

0370

70

71

72

73

74

75

76

77

78

79

7A

7B

7C

7D

7E

7F

0380

80

81

82

83

84

85

86

87

88

89

8A

8B

8C

8D

8E

8F

0390

90

91

92

93

94

95

96

97

98

99

9A

9B

9C

9D

9E

9F

03A0

A0

A1

A2

A3

A4

A5

A6

A7

A8

A9

AA

AB

AC

AD

AE

AF

03B0

B0

B1

B2

B3

B4

B5

B6

B7

B8

B9

BA

BB

BC

BD

BE

BF

03C0

C0

C1

C2

C3

C4

C5

C6

C7

C8

C9

CA

CB

CC

CD

CE

CF

03D0

D0

D1

D2

D3

D4

D5

D6

D7

D8

D9

DA

DB

DC

DD

DE

DF

03E0

E0

E1

E2

E3

E4

E5

E6

E7

E8

E9

EA

EB

EC

ED

EE

EF

03F0

F0

F1

F2

F3

F4

F5

F6

F7

F8

F9

FA

FB

FC

FD

FD

FF

770 A P P E N D I X E • EPROM Data for a Digital Function Generator

E.2 C Program

This program is also on the accompanying CD in the file

\Student_Files\EPROM\EPROM.C.

/*

Hex File Generator

*Written by: Ronan Capina and Robert Dueck

*This program is to create a hex file in a specific EPROM record format.

*The EPROM is addressed in blocks of 256 bytes (8 address lines) by an 8 bit

*counter to create a digital image of one of several waveform outputs.

*Two additional address bits select one of four output functions.

*When the EPROM data are run through a D/A Converter, they create an

*analog waveform running at the frequency of the counter divided by 256.

*The waveforms are sine, square, triangle, and sawtooth.

*The record format is as follows. (Spaces are inserted only for clarity.

*The actual record must have NO spaces.)

*

*: 10 0080 00 AF5F67F0602703E0322CFA92007780C3 61

*(:Record Length = 10hex = 16dec)

*(Address = 0080hex; location in EPROM of first data byte in record)

*(Record type = 00 = data)

*(16 data bytes = 32 hex digits)

*(Checksum; Record Length + Address High byte + Address Low byte

*+ Record type + data bytes + Checksum = 00, after discarding carry)

*An END record is also required, having a similar format, except that

*Record Type = 01 = END and there are no data bytes. Checksum is still

*required.

*eg. :00000001FF

*/

#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <conio.h>

void Sawtooth(int); void triangle(int); void Square(int);

int AddrByte(int Addr); int Chksum(int sum); void sine(int);

char *HexString(int value);

char *Hex = HULL; int Ampl;

const double Pi = 3.141592654;

int main(void)

{

FILE *fp;

int Fcn =1, Linenum, sum, Byte, Addr = 0; char Record[256];

clrscr();

 

A P P E N D I X E • EPROM Data for a Digitial Function Generator

771

/*

Hex file is written to c:\eprom\eprom.hex

 

*To change the file name, modify the following line to:

*if (!(fp = fopen(“c:\\YourDirectoryName\\YourFile.hex”, “w+t”)))

{

*/

if (!(fp = fopen(“c:\\eprom\\eprom.hex”, “w+t”))) { printf(“Error opening output file.\r\n”); exit(1);

}else

printf(“File opened successfully. \r\n”);

while (Fcn != 5) { /* Create records for 4 functions */

/* Each function has 16 lines of data */ for (Linenum = 1; Linenum <= 16; Linenum++) {

/* Create record and address information */ if (Addr < 16)

sprintf(Record, “:10000%x”, Addr); else

if (Addr < 256)

sprintf(Record, “:1000%x”, Addr);

else

sprintf(Record, “:100%x”, Addr); strcat(Record, “00”);

/* Accumulate sum for calculating checksum */ sum = 16 + AddrByte(Addr);

/* Calculate byte values for selected function */ for (Byte = 1; Byte <= 16; Byte++) {

if (Fcn == 1) sine(Addr % 256);

else if (Fcn == 2) Square(Addr % 256);

else if (Fcn == 3) triangle(Addr % 256);

else

Sawtooth(Addr % 256);

/* Append calculated byte value (amplitude) to the record and update checksum accumulator */

strcat (Record, HexString(Ampl)); sum = sum + Ampl;

Addr++;

}

strcat (Record, HexStrIng(Chksum(sum))); fprintf(fp, “%s\r\n”, Record);

}

Fcn++;

}

fprintf(fp, “:00000001FF\r\n”); fclose(fp);

return(0);

}

772 A P P E N D I X E • EPROM Data for a Digital Function Generator

int AddrByte(int Addr)

{

if (Addr < 256) return Addr;

else

return (((int)(Addr / 256)) + (Addr % 256));

}

int Chksum(int sum)

{

int IntRem = sum % 256; if (IntRem == 0)

return 0;

else

return (256 - IntRem);

}

char *HexString(int value)

{

if (value < 16) {

sprintf(Hex, “0%x”, value); return Hex;

} else if (value > 255) return “FF”;

else {

sprintf(Hex, “%x”, value); return Hex;

}

}

void Sawtooth(int Addr)

{

Ampl = Addr; return;

}

void sine(int Addr)

{

double angle = ((((float)Addr) * 2 * Pi) / 256); Ampl = ((int)((sin(angle) * 128) + 128));

if (Ampl > 255) Ampl = 255; return;

}

void Square(int Addr)

{

if (Addr < 128) Ampl = 255; else

Ampl = 0; return;

}

 

A P P E N D I X E • EPROM Data for a Digitial Function Generator

773

void triangle(int Addr)

 

{

 

 

if (Addr < 64)

 

Ampl =

128 + (2 * Addr);

 

else if

((Addr >= 64) && (Addr < 192))

 

Ampl =

256 - 2 * (Addr - 63);

 

else

 

 

Ampl =

2 * (Addr - 191);

 

return;

 

 

}

 

 

E.3 Resultant Record File

:10000000808386898C8F9295989C9FA2A5A8ABAE81

:10001000B0B3B6B9BCBFC1C4C7C9CCCED1D3D5D893

:10002000DADCDEE0E2E4E6E8EAECEDEFF0F2F3F54C

:10003000F6F7F8F9FAFBFCFCFDFEFEFFFFFFFFFF01

:10004000FFFFFFFFFFFFFEFEFDFCFCFBFAF9F8F7E8

:10005000F6F5F3F2F0EFEDECEAE8E6E4E2E0DEDC00

:10006000DAD8D5D3D1CECCC9C7C4C1BFBCB9B6B319

:10007000B0AEABA8A5A29F9C9895928F8C898683E1

:100080007F7C797673706D6A6763605D5A575451EF

:100090004F4C494643403E3B383633312E2C2A27BD

:1000A0002523211F1D1B1917151312100F0D0C0AE4

:1000B000090807060504030302010100000000000F

:1000C0000000000000000101020303040506070808

:1000D000090A0C0D0F1012131517191B1D1F2123D0

:1000E00025272A2C2E313336383B3E404346494C97

:1000F0004F5154575A5D6063676A6D707376797CAF

:10010000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

:10011000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF

:10012000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDF

:10013000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCF

:10014000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBF

:10015000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAF

:10016000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9F

:10017000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8F

:10018000000000000000000000000000000000006F

:10019000000000000000000000000000000000005F

:1001A000000000000000000000000000000000004F

:1001B000000000000000000000000000000000003F

:1001C000000000000000000000000000000000002F

:1001D000000000000000000000000000000000001F

:1001E000000000000000000000000000000000000F

:1001F00000000000000000000000000000000000FF

:1002000080828486888A8C8E90929496989A9C9EFE

:10021000A0A2A4A6A8AAACAEB0B2B4B6B8BABCBEEE

:10022000C0C2C4C6C8CACCCED0D2D4D6D8DADCDEDE

:10023000E0E2E4E6E8EAECEEF0F2F4F6F8FAFCFECE

:10024000FEFCFAF8F6F4F2F0EEECEAE8E6E4E2E0BE

:10025000DEDCDAD8D6D4D2D0CECCCAC8C6C4C2C0AE

:10026000BEBCBAB8B6B4B2B0AEACAAA8A6A4A2A09E

:100270009E9C9A98969492908E8C8A88868482808E

:100280007E7C7A78767472706E6C6A68666462607E

774 A P P E N D I X E • EPROM Data for a Digital Function Generator

:100290005E5C5A58565452504E4C4A48464442406E

:1002A0003E3C3A38363432302E2C2A28262422205E

:1002B0001E1C1A18161412100E0C0A08060402004E

:1002C000020406080A0C0E10121416181A1C1E201E

:1002D000222426282A2C2E30323436383A3C3E400E

:1002E000424446484A4C4E50525456585A5C5E60FE

:1002F000626466686A6C6E70727476787A7C7E80EE

:10030000000102030405060708090A0B0C0D0E0F75

:10031000101112131415161718191A1B1C1D1E1F65

:10032000202122232425262728292A2B2C2D2E2F55

:10033000303132333435363738393A3B3C3D3E3F45

:10034000404142434445464748494A4B4C4D4E4F35

:10035000505152535455565758595A5B5C5D5E5F25

:10036000606162636465666768696A6B6C6D6E6F15

:10037000707172737475767778797A7B7C7D7E7F05

:10038000808182838485868788898A8B8C8D8E8FF5

:10039000909192939495969798999A9B9C9D9E9FE5

:1003A000A0A1A2A3A4A5A6A7A8A9AAABACADAEAFD5

:1003B000B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC5

:1003C000C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFB5

:1003D000D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFA5

:1003E000E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF95

:1003F000F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF85

:00000001FF

Answers to Selected Odd-Numbered Problems

Chapter 1

1.1Analog quantities:

a.Water temperature at the beach;

b.weight of a bucket of sand;

e.height of a wave; Digital quantities:

c.grains of sand in a bucket;

d.waves hitting the beach in one hour;

f.people in a square mile.

Generally, any quantity that can be expressed as “the number of. . .” is digital.

1.3

a.

4;

b.

8;

c.

25;

 

d.

6;

e.

21;

f.

29;

 

g.

59;

h.

93;

i.

33;

j. 185

1.5101, 110, 111, 1000

1.716

1.9

a. 0.625;

b. 0.375;

c. 0.8125

1.111/3

1.13a. 0.11;

b.0.101;

c.0.0011;

d.0.101001;

e.1.11;

f.11.111100;

g.1000011.1101011100001. . . (nonrepeating)

1.159F7, 9F8, 9F9, 9FA, 9FB, 9FC, 9FD, 9FE, 9FF, A00, A01, A02, A03

1.17

a.

2C5;

b. 761;

c. FFF;

 

d.

1000;

e. 2790;

f. 7D00;

 

g.

8000

 

 

1.19

a.

5E86;

b. B6A;

c. C5B;

 

d.

6BC4;

e. 15785;

f. 198B7;

 

g.

28000

 

 

1.21Periodic: b., c., e. Each of these waveforms repeats itself in a fixed period of time. (Note that waveform

b. may not immediately appear to be periodic. However, if we count the sequence of short pulse, short space, medium pulse, medium space, short pulse, long space, we will find that each repetition of this sequence takes the same time.)

Aperiodic: a., d. Neither of these waveforms repeats in a fixed period of time. Waveform a. has three equally-spaced pulses of equal width, but this pattern does not repeat in the time shown. Waveform d. has pulses of equal duration, spaced at increasing (i.e. unequal) intervals.

1.23From the graph in Figure 1.14, read the times corresponding to the 10%, 50%, and 90% values of the pulse on both leading and trailing edges.

Leading edge: 10%: 5 s

Trailing edge: 90%: 40 s

50%:

7.5 s

50%: 45 s

90%:

10 s

10%: 50 s

Pulse width: 50% of leading edge to 50% of trailing edge.

tw 45 s 7.5 s 37.5 s Rise time: 10% of rising edge to 90% of rising edge.

tr 10 s 5 s 5 s

Fall time: 90% of falling edge to 10% of falling edge. tf 50 s 40 s 10 s

Chapter 2

2.1See Figure ANS2.1.

 

 

 

 

 

 

 

1

 

 

 

 

 

 

 

 

A

 

 

 

 

 

A

 

 

 

 

 

 

 

Y

A

 

 

 

 

 

 

 

 

 

Y A

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

a. Distinctive Shape

b. Rectangular Outline

FIGURE ANS2.1

775

776 Answers to Selected Odd-Numbered Problems

2.3See Figure ANS2.3.

A

 

 

 

 

 

 

B

 

 

 

 

 

Y A B C

 

 

 

 

 

C

 

 

 

 

 

 

 

a. Distinctive Shape

 

 

A

 

 

 

 

 

 

1

 

 

 

 

B

 

 

 

 

 

Y A B C

 

 

 

 

 

C

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b. Rectangular Outline

FIGURE ANS2.3

 

 

 

 

 

 

2.5N is HIGH if J OR K OR L OR M IS HIGH. See Table ANS2.5.

Table ANS2.5

4-input OR

Truth Table

 

 

 

 

 

 

 

 

 

 

J

K

L

M

N

 

 

 

 

 

 

0

0

0

0

0

 

0

0

0

1

1 *

 

0

0

1

0

1 *

 

0

0

1

1

1 *

 

0

1

0

0

1 *

 

0

1

0

1

1 *

 

0

1

1

0

1 *

 

0

1

1

1

1 *

 

1

0

0

0

1 *

 

1

0

0

1

1 *

 

1

0

1

0

1 *

 

1

0

1

1

1 *

 

1

1

0

0

1 *

 

1

1

0

1

1 *

 

1

1

1

0

1 *

 

1

1

1

1

1 *

 

 

 

 

 

 

 

2.7The switches must be connected in parallel. See Figure ANS2.7.

A

B

C

D

FIGURE ANS2.7

2.9Active LOW. When the switch is pressed, it generates a logic LOW.

2.11The anode must be at a higher voltage than the cathode by a specified amount.

2.13See Figure ANS2.13.

+5V

470

FIGURE ANS2.13

2.15a. Output Y is LOW when A OR B OR C OR D are HIGH. The truth table is shown in Table ANS2.15.

Table ANS2.15 4-input

NOR Truth Table

A

B

C

D

Y

 

 

 

 

 

0

0

0

0

1

0

0

0

1

0

0

0

1

0

0

0

0

1

1

0

0

1

0

0

0

0

1

0

1

0

0

1

1

0

0

0

1

1

1

0

1

0

0

0

0

1

0

0

1

0

1

0

1

0

0

1

0

1

1

0

1

1

0

0

0

1

1

0

1

0

1

1

1

0

0

1

1

1

1

0

 

 

 

 

 

b.Y A B C D

c.See Figure ANS2.15

A

B Y A B C D

C

D

a. Distinctive Shape

A

B 1 Y

C

D

b. Rectangular Outline

FIGURE ANS2.15

2.17Output Y is LOW if inputs A AND B AND C AND D AND E are all HIGH.

Answers to Selected Odd-Numbered Problems

777

2.19Required gate is a 2-input AND.

2.21XNOR.

2.23Output is HIGH if an odd number of inputs is HIGH.

2.25a. and c. The attributes of shape, input level, and output level are all different between these two symbols.

2.27See Figure ANS2.27.

A

B

AND

OR

NAND

NOR

XOR

XNOR

FIGURE ANS2.27

2.29See Figure ANS2.29.

2.31A HIGH is required to enable the AND gate. This allows the lamp to flash.

2.33No. An XOR gate has no inhibit state. The lamp always flashes.

2.35Transistor-Transistor Logic (TTL) and Complementary Metal-Oxide-Semiconductor (CMOS). Typically, TTL can drive higher-current loads. CMOS has more flexible power supply requirements and uses less power.

2.37Low power Schottky TTL: 74LS02; CMOS: 4001B; High-speed CMOS: 74HC02. NANDs and NORs are differentiated by the last two digits in their part numbers.

A

B

Y

FIGURE ANS2.29

Chapter 3

3.1a. Y ABC;

b.X PQ RS;

c.M HJKL;

d.A W X Y Z;

e.Y (A B)(C D);

f.Y (A B)(C D);

g.Y (A B)(C D);

h.X P Q R S;

i.X P Q R S