You are on page 1of 13

# Mechatronics Laboratory Assignment 4 Parallel Communication Glue Logic, Hardware Interrupts, Analog to Digital Conversions, and Board Fab

Possible Points: If checked off before your lab time the week of Mar. 12th 14 points If checked off after your lab time the week of Mar. 12th and before 4:00PM Mar. 16th 9 points If work not finished before 4:00PM Mar. 16th 0 points

Recommended Due Date: By your lab time the week of Feb. 27th

## DSP/BIOS Objects Used:

values you could set AdcRegs.ADCTRL1.bit.SUSMOD to are 0,1,2,or 3. For a bit field with only 1 bit of a register, the value is either 0 or 1, etc.
InitAdc(); // This function takes care of powering on the ADC correctly.

## //Enable SEQ1s interrupt //Set Interrupt to occur every SEQ1 completion

//Core clock divided by 18 // Found this by trial and error. Could need to be

## // Internal reference used

// set these 5 fields so that the order of ADC channels // sampled is A0,B0,A1,B1,A2,B2,A3,B3,A4,B4.

// Reset SEQ1 // Clear INT SEQ1 Good practice to clear possible // interrupt before enabling the interrupt.

Know how to use the BUTTER function in Matlab to design both low- and high-pass filters. Understand how to take the coefficients returned by these functions to create difference equations that are coded in C to implement a filter. The help for filter in Matlab gives the order of coefficients for filters created in MATLAB. You will have to design two filters for the lab, so give some thought on how to code the difference equations in C.

## Laboratory Exercise GE423, Mechatronic Systems

Lab 4, Page 2 of 13

start_SPI()

you will set the appropriate ADC register bit to start the ADC conversion sequence. On completion of

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; PieCtrlRegs.PIEIER1.bit.INTx6 = 1; // Clear possible interrupts before enabling int. // enable PIE interrupt 1.6

## IER |= M_INT1; // Enable legacy INT1 in the interrupt enable register

2.

The default project creator code already given to you uses the following flow to sample the four optical encoder interface chips (LS7366) every 1ms: i. The PRD PRD_StartADC is setup to be triggered every 1ms. ii. PRD_StartADCs function
void start_dataCollection(void)

## is therefore called every

1ms and it simply calls the function start_SPI(). GE423, Mechatronic Systems Lab 4, Page 3 of 13

iii.

start_SPI()

sends an 8 bit command to the four LS7366 chips telling them to latch their

encoder counts to the chips read register. iv. After the 8 bit command has been received by the LS7366 chips, the SPI interrupts the TMS320F28335 indicating the transfer is complete and it is ready for more data to transfer. v. Inside the SPIs ISR, LS7366 chip #1 is selected and its count value is read over the SPI serial port. After optical encoder #1s 32bit count has be read the SPI again interrupts the processor and the procedure is repeated three more times to read chip #2, #3 and #4. vi. At the final interrupt, indicating that the LS7366 #4s count value has been read, the SWI SWI_control is posted.
control(void)

## Then when priority permits, the SWIs function

void

is called. Here is where you place your code that does something with the

sampled sensor readings. For this lab and remaining labs, you will also need to sample the ADC inputs every 1ms. Do this by inserting the sampling of the ADC inputs at the beginning of the LS7366 read process. i. Inside PRD_StratADCs function
start_SPI(), void start_dataCollection(void)

set the appropriate ADC register bit to start the conversion sequence

start_SPI()

## to read the LS7366 chips. In step 3 you will create the

header files name these result registers the ADC mirrored results registers and gives them the C

So for example, to read the first ADC sampled value you would use the

following C statement:

## Ten global integer variables,

through

and

through

// Reinitialize for next ADC sequence AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Reset SEQ1 // Clear INT SEQ1 bit

## PieCtrlRegs.PIEACK.all=PIEACK_GROUP1;//Acknowledge/CLR interrupt to PIE

4.

With the ADCINTs interrupt service routine written, setup DSP/BIOS to call this function when the ADCINT interrupt occurs. a. Open your projects DSP/BIOS *.tcf file. Explore the Scheduling section to the HWI section. Scroll down to the bottom of the HWI section and expand the PIEINTERRUPTS. Here you will find the 96 different interrupts possibly generated by the TMS320F28335. The one we are interested in is PIE_INT1_6. Select PIE_INT1_6 and right click and select Properties. b. c. In the General tab of the properties window enter your ISRs function name, not forgetting the beginning _. In the Dispatcher tab, check the Use Dispatcher box. Also select all for the Interrupt Mask. We will talk more about these settings in lecture, but the Dispatcher, when enabled, adds the capability to call operating system functions like SEM_post and SWI_post inside your ISR. The interrupt mask set to all disables all other interrupts while this ISR is running. On completion of this ISR all interrupts are re-enabled.

5.

Now that the conversion of the ADC channels has been inserted into the data collection sequence, you can use these sampled ADC values along with the optical encoder readings. The best location to put this code is in the SWI_controls function control(). Here you have all the ADC readings and all the optical encoder readings. Similar to what we did in the first exercise of Lab 3, echo the value sampled on ADCINB1 and ADCINB2 to DAC outputs 1 and 2. To do this you will need to scale the raw ADCIN reading that is in the range 0 to 4095 to a volt ranging from 0V to 3.0V. Then write this scaled value to the DACs using the function. Limit the values written to the
writeDAC7564() writeDAC7564()

## GE423, Mechatronic Systems

Lab 4, Page 5 of 13

1. 2. 3. 4. 5. 6.

Open up VB, create a new project by selecting VB Pro Edition Controls, and immediately save it to a local directory containing your repository. Open up the form view. Add 2 text boxes and name them txtDAC1 and txtDAC2. Add 2 labels and name them lblADC1 and lblADC2. Add a Winsock object Add a button, name it cmdSendDAC and give it the caption SendDAC. Also change the buttons property Default to True. When the Default setting of a button is set to true, the buttons code is run when you press the Enter key of the keyboard.

7.

Add a Picture Box and name it pbxArena. Make sure to size the Picture Box large enough so that in later assignments you will be able to draw the course and its obstacles Change the property AutoRedraw to True. Change ScaleHeight to 10, ScaleWidth to 10, ScaleLeft to 5 and ScaleTop to -5.

8.

Single-click on the Winsock object in the form view. Leave the Winsock settings to the defaults, except for the following: Name: Winsock1 Lab 4, Page 6 of 13

## 0 - sckTCPProtocol Your robots IP 10001

Double Click on the SendDAC button and insert the following code: This sends a space delimited string to the DSP
Winsock1.Senddata(Chr(253) & txtDAC1.Text & & txtDAC2.Text & Chr(255))

10.Double click on empty space in your form window. Add the following code to the auto-generated function Form_Load:
Winsock1.Connect 'Connect to TCPIP Server application running in Linux on the robot

11.Arrow to the very top of your form code above all the other functions. Add the following global variables:
Option Explicit Dim strNextString As String Dim tcpipValue1 As Single Dim tcpipValue2 As Single Dim tcpipValue3 As Single Dim tcpipValue4 As Single

12. At the top of VBs code window select Form in the left pull down and in the right pull down select Unload. VB will then create the Form_Unload function. In this function as the following code:
Winsock1.Close

13. Add one more button to your application. Name this button cmdClear and give it the caption Clear. Double click on the button and insert the following code to clear the picture box when this button is clicked
pbxArena.Cls

14. Again at the top of VBs code window select Winsock1 in the left pull down and in the right pull down select DataArrival. VB will then create the Winsock1_DataArrival function. This function is called when there is at least one character received over the Ethernet into VB. Most of the time this will be the entire string of characters sent from the robot but the code must handle the case when the entire string is not sent thus a start and stop character is used. Add the following code inside this function (cut and paste):

Dim intStart As Integer 'the index of StartChar Dim intEnd As Integer 'the index of EndChar

## Dim splitstrings As Variant Dim Chars_received As String Dim tempstring As String

Winsock1.GetData tempstring, vbString strNextString = strNextString & tempstring ' Append new com data intStart = InStr(strNextString, Chr(253)) If (intStart > 0) Then strNextString = Mid(strNextString, intStart) intEnd = InStr(strNextString, Chr(255)) 'Find the index of EndChar 'Find the index of StartChar

If (intEnd > 1) Then 'If Start&End exist and Start comes before End

## GE423, Mechatronic Systems

Lab 4, Page 7 of 13

Chars_received = Mid(strNextString,2, intEnd - 2) splitstrings = Split(Chars_received, ) If Ubound(splitstrings) = 3 Then tcpipValue1 = Val(splitstrings(0)) tcpipValue2 = Val(splitstrings(1)) tcpipValue3 = Val(splitstrings(2)) tcpipValue4 = Val(splitstrings(3)) lblADC1.Caption = CStr(tcpipValue1) lblADC2.Caption = CStr(tcpipValue2) pbxArena.circle (tcpipValue1,tcpipValue2) , 0.25 End If strNextString = Mid(strNextString, intEnd + 1) End If End If

Code on the TMS320F28335 to check that your VB application is working correctly. The code on the TMS320F28335 processor side to test that your VB application has been built correctly is mostly given to you. The OMAPL138s DSP is already flashed with a program that takes care of receiving and sending data to and from VB. For sending data to VB you simply have to write the two ADC readings to two variables already created for you called
tcpip1

and

tcpip2.

So in the

control()

sendData()

## function call, assign

tcpip1

to the first

ADC voltage reading and tcpip2 to the second ADC reading. To test if data is being received correctly from VB, write the transmitted values to the two DAC channels and then monitor with the oscilloscope the change in the DAC voltage output. So in your code, instead of echoing the sampled ADC of filtered values to the two DAC channels, change the code in the
omap_dac2 control()

to the

writeDAC7564()

function.

omap_dac1

and

omap_dac2

## GE423, Mechatronic Systems

Lab 4, Page 9 of 13

Section #2 Design a new shield circuit board, along with its interface C code, for the TMS320F28335. The current shield board on the robots processor board is the green board to the left of the color LCD. The design will actually be a partial design, because I only want you focusing on the SPI connections from the TMS320F28335 to the external chips. I do not want you designing the external connections to these chips. Even though this is a partial design, I still would like you to both create an EagleCAD schematic and an EagleCAD board layout. This will give you some extra experience working with circuit board fabrication. You are even going to go as far as sending your board files to a PCB companys automated board file check website giving you some initial experience in ordering your designed board. Assignment: 1. Design a new shield circuit board that interfaces the TMS320F28335 to five integrated circuits that use the SPI serial interface for communication. The five chips are the DS1394, MAX5436, MAX3100, MAX6627 and MCP23S08. So your new circuit board will have a real-time clock chip (DS1394), a digital potentiometer (MAX5436), an additional RS-232 UART serial port (MAX3100), a digital temperature sensor (MAX6627) and an 8-bit I/O Expander (MSP23S08). You will only be writing C code to interface with the MCP23S08 chip for this assignment. I mention this here so you dont spend a lot of time reading the datasheets of the other 4 chips. GE423, Mechatronic Systems Lab 4, Page 10 of 13

4. 5. 6.