Presentation is loading. Please wait.

Presentation is loading. Please wait.

UniMAP 1 Interfacing DIO ADC Keypad LCD. UniMAP 2 Using I/O ports in C program on Linux machine 1.Need permission to access the port. This is done by.

Similar presentations


Presentation on theme: "UniMAP 1 Interfacing DIO ADC Keypad LCD. UniMAP 2 Using I/O ports in C program on Linux machine 1.Need permission to access the port. This is done by."— Presentation transcript:

1 UniMAP 1 Interfacing DIO ADC Keypad LCD

2 UniMAP 2 Using I/O ports in C program on Linux machine 1.Need permission to access the port. This is done by calling the ioperm() function (declared in unistd.h, and defined in the kernel) somewhere near the start of your program (before any I/O port accesses). The syntax is ioperm (from, num, turn_on), where from is the first port number to give access to, and num the number of consecutive ports to give access to. For example, ioperm(0x300, 5, 1) would give access to ports 0x300 through 0x304 (a total of 5 ports).

3 UniMAP 3..cont The last argument is a Boolean value specifying whether to give access to the program to the ports (true (1)) or to remove access (false (0)). You can call ioperm() multiple times to enable multiple non-consecutive ports. See the ioperm(2) manual page for details on the syntax. The ioperm() call requires your program to have root privileges. ioperm() can only give access to ports 0x000 through 0x3ff

4 UniMAP 4 Accessing the I/O ports To read a byte (8 bits) from a port, call –inb(port), reading from port –it returns the byte it got. To write a byte, call –outb (value, port),

5 UniMAP 5 …cont To read a word (16 bits) from ports x and x+1 (one byte from each to form the word, using the assembler instruction inw, call inw(x). To write a word to the two ports, use outw(value, x). If you're unsure of which port instructions (byte or word) to use, you probably want inb() and outb() --- most devices are designed for bytewise port access. Note that all port access instructions take at least about a microsecond to execute.

6 UniMAP 6 The SBC ADC

7 UniMAP 7 ADC configuration  The analog to digital converter (ADC) used on board the TS-5500 is the MAX197 which is capable of converting 8 channel analog input. The output is 12-bit digital conversion of the analog input.  Each channel is independently software programmable for unipolar or bipolar conversion and a four range of analog input: - 10V to +10V, -5V to +5V, 0V to +10V and 0V to +5V.

8 UniMAP 8 Setting ADC conversion mode To start the conversion, firstly a value needs to be written to the I/O location 196h to initiate the conversion. The value determines the channel to convert, unipolar or bipolar mode and the range select.

9 UniMAP 9 The ADC Ctrl Register Figure : ADC control register (196h)

10 UniMAP 10 Reading the Data Once the conversion is completed, the reading can be read at locations 196h (LSB) and 197(MSB). When using unipolar mode, the upper four bits of the MSB is equal to zero while in bipolar, the result is twos-complement binary with the upper four bits (bits 12 to 15) equal to bit 11 (sign extended).

11 UniMAP 11 Summary of ADC registers

12 UniMAP 12 Code excerpt struct param{ int init; // determines which channel to convert int count; // adc channel count }; struct param value[] = { {0x08,0},{0x09,1},{0x0A,2},{0x0B,3},{0x0C,4},{0x0D,5},{0x0E,6},{0x0F,7}, }; if(ioperm(0x195, 3, 1) < 0)// set io permission for 0x195,0x0196,0x197 {printf("Error channel permission\n"); return -1;} … for(i = 0; i < 8; i = i + 1) {outb(value[i].init, 0x196); do { ival = inb(0x195); } while((ival & 0x01) != 0); // read LSB of input ival = inb(0x196); lsb = ival & 0x000F; }

13 UniMAP 13 The SBC DIO 1

14 UniMAP 14 DIO1 configuration The DIO1 port has 14 lines of digital input/output (DIO) lines, +5V and GND. Figure 2 below depict the DIO1 header pin out.

15 UniMAP 15 DIO 1- Pin Out

16 UniMAP 16 Setting the DIO as In or Out Twelve (12) out of the fourteen (14) digital lines can be set as output or input by software. The other 2 lines, which are DIO1_12 and DIO1_13 are always inputs. Setting the direction ( input /output) of the 12 DIO1 lines can be done through the control port at IO location 0x7Ah. The bits of 7Ah that determine the digital lines as input or output are as shown in figure 3 below. In all cases, when a control bit is a “1”, it is setting the corresponding DIO line to output( writing data to the DIO port), while a “0” sets them to inputs( reading data from the port). All control bits at I/O location 0x7Ah are initialized at reset to be “0”.

17 UniMAP 17 Figure 3: DIO1 control port (0x7Ah)

18 UniMAP 18 Accessing the Data The data for port DIO_0 to DIO_7 are byte wide accessible at IO location 0x7Bh. While DIO1_8 till DIO1_13 are accessed through the lower 6-bits of the IO location 0x7Ch.

19 UniMAP 19 The digital inputs of the TS-5500 have standard TTL level thresholds and must not be driven below 0 Volts or above 5.0 volts. DIO_0 to DIO_7 have 4.7KΩ pull-up resistors to 5V biasing the signals to logic ‘1’.

20 UniMAP 20 Code excerpt if(ioperm(0x7A, 3, 1) < 0)// set io permission for 7A, 7B, 7C { printf("Error DIO access\n"); return -1; } outb(0x02, 0x7A);// set DIO 0-3 and DIO 8-11 as input // DIO 4-7 as output inb(0x7B); // read input from DIO 0-3 value= inb(0x7C); // read input from DIO 8-11

21 UniMAP 21 Reference Linux I/O Port Programming TS 5500 User’s Manual Linux developer manual


Download ppt "UniMAP 1 Interfacing DIO ADC Keypad LCD. UniMAP 2 Using I/O ports in C program on Linux machine 1.Need permission to access the port. This is done by."

Similar presentations


Ads by Google