You are on page 1of 26

TECHNICAL REPORT PC to 68HC11, Wireless Interface

By: Date:

Nic Cameron 334977 December 18, 2001

1.0 Introduction:............................................................................................................................................................... 3 1.1 Functional Overview:....................................................................................................................................... 3 2.0 Graphical User Interface .......................................................................................................................................... 4 2.1 GUI Overview................................................................................................................................................... 4 2.2 GUI Functionality.............................................................................................................................................5 2.2.1 GUI Flow Chart ......................................................................................................................................5 2.2.2 GUI Details .............................................................................................................................................6 3.0 Modulator / Transmitter........................................................................................................................................... 7 3.1 Tx Overview...................................................................................................................................................... 7 3.1.1 Tx Block Diagram................................................................................................................................. 7 3.2 Tx Design...........................................................................................................................................................7 3.3 Tx Testing and Construction...........................................................................................................................8 4.0 Receiver / Demodulator ......................................................................................................................................... 10 4.1 Rx Overview.................................................................................................................................................... 10 4.1.1 Rx Block Diagram............................................................................................................................... 10 4.2 Rx Des ign.........................................................................................................................................................10 4.3 Rx Testing and Construction........................................................................................................................11 5.0 68HC11 Decoder..................................................................................................................................................... 12 5.1 Decoder Overview.......................................................................................................................................... 12 5.2 Decoder Functionality....................................................................................................................................12 5.2.1 Decoder Flow Chart ............................................................................................................................ 12 5.3 Axiom Board Modifications.........................................................................................................................13 5.4 Programming / Testing Axiom board .......................................................................................................... 13 6.0 Conclusion................................................................................................................................................................ 14 7.0 Appendix A- Source Code.....................................................................................................................................15 7.1 GUI Source Code............................................................................................................................................15 7.1.1 Main Form Code ..................................................................................................................................15 7.1.2 Binary Mode Code............................................................................................................................... 16 7.1.3 Decimal Mode Code............................................................................................................................ 17 7.2 68HC11 Source Code.....................................................................................................................................21 8.0 Appendix B- Schematic Drawings.......................................................................................................................23 8.1 Tx Schematic ................................................................................................................................................... 23 8.2 Rx Schematic ................................................................................................................................................... 23 9.0 Appendix D- Bill Of Materials ............................................................................................................................. 24 9.1 Tx BOM ...........................................................................................................................................................24 9.2 Rx BOM ...........................................................................................................................................................24 10.0 Appendix E- Data Sheets.....................................................................................................................................25 11.0 Appendix F-Bibliography....................................................................................................................................26

1.0 Introduction: This report is intended to discuss the design, manufacture and testing of a wireless interface between a micro -controller and a PC. Using Microsoft Visual Basic, an application was written to enable the user to output a 6-bit binary word via the serial port of a computer. This binary word may be entered in either binary or decimal form. The binary word would then be modulated onto an 18MHz carrier to be transmitted. At the receiver, this signal would be demodulated and then decoded by a 68HC11 and the binary data would then be displayed using LEDs. This simplex communication was from PC to 68HC11 only. The ultimate goal of this project was not necessarily the transmission of a simple binary number, but to develop a system that incorporated both hardware and software components. It is not likely that it would be useful to transmit a binary number just to be displayed. However, if the binary number was used to enable relays, this system could be used to remotely turn on and off lights, radios etc. It was this idea that was the premise of this project. 1.1 Functional Overview: The following shows each functional block of this system:

Figure 1-System Block Diagram The Graphical User Interface (GUI) is an executable file created using Visual Basic. It allows the user to input data and have it transmitted through the serial port of the PC. The Modulator / Transmitter block modulates the RS-232 standard logic from the serial port onto a 20MHz carrier. The Receiver / Demodulator block amplifies the received signal and demodulates it to TTL logic. The Decode / Display block uses a 68HC11 to decode the received TTL signal and display the data that was entered using the GUI. The project was intended to be wireless, but due to unexpected problems and lack of time to solve them, a conductor was used between the transmit and receive stages.

2.0 Graphical User Interface

Figure 2-GUI 2.1 GUI Overview The GUI was created using Microsoft Visual Basic 6.0. Having no prior knowledge of Visual Basic, this portion of the project was anticipated as possibly being the most difficult and time consuming. In actuality, it was quite the opposite. Once the general programming environment was familiar, the actual programming was quite logical. The only real difficulty of this portion of the project was obtaining references for controlling the serial port. Most of the text books and references for Visual Basic do not even mention that this is even possible, let alone how to do it. After several days, and several books later, I found a book that introduced this topic. After some trial and error programming, the serial port was finally communicating. The program has two modes of operation: Binary mode and Decimal mode. The user selects which mode he/she would prefer to use. The mode is defines what number base the data is entered as. See Figure 3 for the Decimal mode window. Ultimately, the output of the serial port is the ASCII code for a 6-bit binary word. The program contains a window that explains how to use the program as well as separate windows for both modes of operation.

Figure 3- Decimal Mode

2.2 GUI Functionality 2.2.1 GUI Flow Chart

2.2.2 GUI Details When the program is started, it initially configures the serial port by setting the baud rate to 9600bps, the number of data bits to eight, and disables parity checking. Once this is completed, the program sets a variable that indicates that the port is ready to be used. Since this program is event-driven it now waits for the user to make a selection of some sort. On the main page, there are several possible selections: the two operation modes from the pull-down combo box, operation details from the command button, file close and details from the drop -down menus. If Binary mode is selected, the program checks to see if the serial port is being used by Decimal mode via the PortOK variable. If it is, an error message appears and the mode does not open. If the port is free, than the Binary mode window will open and set the PortOK variable stating that the port is now in use. Once a binary word has been entered (only 1s and 0s can be entered) and the transmit button has been clicked, the program checks that it is a 6-bit word or less, if the word is greater than 6 bits an error message will be generated. If it is not, the word is transmitted to the output register of the serial port. When the window is closed, the port status variable is set back to default. Decimal mode works the same way as binary mode except that a decimal number between 0 and 63 is entered. This number is first converted to a 6 -bit binary word before it is transmitted. Due to the complexity of the code for this conversion, and especially the time that would be need to write my own, I modified an example program that was downloaded at http://www.vb-helper.com. Once the conversion is complete, this window function acts just like the other mode of operation. See Appendix A for the GUI source code.

3.0 Modulator / Transmitter

Figure 4- Modulator / Transmitter 3.1 Tx Overview The Modulator / Transmitter block modulates the RS-232 standard logic from the serial port onto a 20MHz carrier. For a logic high input, a 20MHz wave is generated; for a logic low, the 20MHz signal is disabled. Instead of an antenna, a wire conductor was used.

3.1.1 Tx Block Diagram

Figure 5-Tx Block Diagram

3.2 Tx Design The first stage of the Modulator / Transmitter circuit is a Maxim IC MAX232 RS-232 to TTL translator chip. This was used because the VCO that was used needed a control voltage between 0 and 5V DC. The VCO that was used was the VCO stage of the Texas Instruments 74HC4046A Phase-Locked-Loop. The output signal from the VCO is fed to a TI THS4041 High-speed operational amplifier that amplified the 6volt peak-to-peak signal to +/ - 5 volts. Due to the fact that an antenna was not used, the amplifier stage was no longer necessary. See Appendix B for the schematic drawing and Appendix C for the PCB layout.

3.3 Tx Testing and Construction

Figure 6- Transmitter PCB As each stage of the circuit board was populated, it was then tested. The first device that was populated was the 74HC4046A PLL. Since the oscillating frequency is dependant on a capacitor and a combination of two resistors, it was necessary to find the correct combination of this to get a high frequency, and an output waveform with as little harmonics as possible. It was impossible to obtain a pure sine wave, as the PLL is intended to generate a clock signal for TTL and CMOS logic circuitry, its output is a square wave. Refer to Appendix B for the wiring of this component.

Figure 8 s hows the frequency out of the VCO with respect the control voltage in:

F out v.s. V in

26 24

22 20 Fout (MHz)

18 16

14 12 10 1 1.5 2 2.5 Vin (V) 3 3.5 4 4.5

Figure 8-Frequency Out V.S. Voltage In This data was collected from a transmit circuit prototype. When the circuit was built on the printed circuit board, the maximum frequency out was 18.4MHz. The second component that was tested was a Maxim MAX232-ACPE Multi-channel RS-232 Driver\Receiver. The serial port of a computer outputs 10 volts for a logic high, and +10 volts for a logic low. The MAX232 converts these logic levels to TTL. To test this chip, inputs of +/- 10 volts were used, and the output was verified to be the corresponding TTL voltage level. An LM741 Op-Amp was used between the MAX232 and the 74HC4046A as a non-inverting buffer.

4.0 Receiver / Demodulator

Figure 9-Receiver / Demodulator 4.1 Rx Overview The more complex of the two hardware units, the receiver amplifies the incoming signal. It then half-wave rectifies it and demodulates it by comparing the DC average to a voltage reference to produce a logic high output. If no signal is present, a logic low is produced.

4.1.1 Rx Block Diagram

Figure 10-Rx Block Diagram

4.2 Rx Design The first stage of the receiver board is an amplifier. It was difficult to find an amplifier that had a high enough unity-gain bandwidth to enable a high gain at a frequency of 20MHz. Ultimately, a TI / BurrBrown OPA620 wideband precision Op -Amp was used. It was only available in an SO-8 surface mount package so it had to be soldered into a DIP socket, this proved very impractical. However, with a gainbandwidth product of 200MHz, it was able to achieve a voltage gain of 10 at 20MHz. The signal is sent to a diode for half-wave rectification and then to an LM74 1 Op-Amp. The negative supply of the amplifier was 1.4 volts so that when the output was low, it reached 0 volts. The inverting input was set to a voltage reference of 120mV: just below the rectified signal voltage level. The amplifier then produces a TTL logic high if a signal is present, and a logic low when a signal is not. This logic then goes to the input of the Axiom CME11A evaluation board for decoding.

4.3 Rx Testing and Construction

Figure 11- Receiver / Demodulator PCB This PCB was the cause of many problems and many more late nights in the lab. The first problem was created when the antenna was plugged into the input amplifier. This caused the amplifier to oscillate. This was most likely due to high gain: the antenna would pick up noise at a frequency of approximately 27MHz, the amplifier then amplified this noise as if it were an actual signal. As a result, no antenna was used. Another problem was with the signal rectification. It became evident that a high speed diode was necessary as the diode that was initially used acted as a capacitor and only attenuated the signal. Also, the comparator, used to create the logic signal output, was the worst problem. Since the reference voltage on the inverting input of amp lifier was a simple voltage division of the 5-volt supply. Any deviation of this supply would affect the voltage reference. As a result, a lot of time was spent adjusting the potentiometer used to set the reference level. Even after adjustment, the demodulator output only worked intermittently. As well, the highest output of the comparator was only 4.1 volts. This may have also contributed to the lack of communication between the receiver board and the 68HC11 board.

5.0 68HC11 Decoder 5.1 Decoder Overview The output from the PC serial port was the ASCII code for the 1s and 0s that were entered via the GUI, hex 31 and 30 respectively. The 68HC11 is used to convert the ASCII code to the binary word and then output the word to the 68HC11 I/O port B where the word would be displayed on LEDs. Initially, an 8-bit word was going to be used. This was not possible because the two most significant bits are used by the Axiom board. The word was reduced to 6 bits. See Appendix A for the Decoder source code.

5.2 Decoder Functionality 5.2.1 Decoder Flow Chart Start

Configure Ports

No Data Preset? No Yes

6 Bits?

Decode ASCII Character

Move to Next Output

Output High Bit 1

1 or 0? 0

Output Low Bit

No Data Present?

Yes

5.3 Axiom Board Modifications For the Axiom board to be interfaced to the receiver board, several modifications needed to be made. Since a 9-volt adapter initially supplied the board, the voltage regulator on the board was bypassed. The board was then supplied directly with the same 5-volt supply as the receiver board. Also, the MAX232 was re moved because the logic that is being input from the receiver board is TTL and not RS-232 that the board was designed for. In order for the 68HC11 to boot from its internal EEPROM, pin 16 of the Axiom boards MCU port had to be tied to VCC. A buffer was added to drive the LEDs instead of the 68HC11 driving them directly.

5.4 Programming / Testing Axiom board The program was burnt to the internal EEPROM of the 68HC11 using the Axiom software that was supplied with the evaluation board. With the 68HC11 programmed internally and pin 16 of the MCU port tied high, the board was tested. It was powered up and connected directly to the serial port of a PC. The GUI was used to send a binary word to the Axiom board. The voltages on the outputs of 68HC11 were measured and found to be the correct levels for the binary word that was sent.

6.0 Conclusion In general, this project was success. I learned how to program using Microsoft Visual Basic as well as how to manipulate the serial communication port of a PC. Also, I learned how to use Orcad Capture CIS version 9.0 for schematic entry. I attempted to use Orcad layout to design the PCBs but this software was far too complex to learn in the time that was available. Troubleshooting and component testing were the two most important processes during the project construction. Although the system did not work during demonstration, it did work several times prior to that. The fact that each functional component worked individually means that it was probably some small problem, such as voltage levels or signal timing that was difficult to detect, that prevented it from working well.

7.0 Appendix A- Source Code

7.1 GUI Source Code Only the source code for the three main pages has been included as the Details.. page and the How to use.. windows were created by changing page properties, and not writing code. 7.1.1 Main Form Code 'declare port status variable Public PortOK 'How to use program selection Private Sub Command1_Click() Form3.Show End Sub 'When page is loaded, Comm port is inactive Private Sub Form_Load() FrmMain.PortOK = 0 End Sub 'Check port status and open selected window Private Sub Combo1_Click() If FrmMain.PortOK = 1 Then MsgBox "Only One mode may be active!", vbOKOnly, "ERROR" End If If Combo1.Text = "Binary Mode" And FrmMain.PortOK <> 1 Then Form1.Show End If If Combo1.Text = "Decimal Mode" And FrmMain.PortOK <> 1 Then Form2.Show End If End Sub 'close all sub forms Private Sub Form_Unload(Cancel As Integer) Dim i As Integer For i = Forms.Count - 1 To 1 Step -1 Unload Forms(i) Next End Sub 'Call the "Details..." form Private Sub mnuHelpAbout_Click() frmAbout.Show vbModal, Me End Sub 'Close Application Private Sub mnuFileClose_Click() Unload Me End Sub

7.1.2 Binary Mode Code Declare variables Public PortOK Dim m Private Sub Form_Load() FrmMain.PortOK = 1 'enable the serial port MSComm1.Settings = "9600,N,8,1" MSComm1.InputLen = 0 If MSComm1.PortOpen = False Then MSComm1.PortOpen = True End If If MSComm1.CommPort = 0 Then MSComm1.CommPort = 1 End If m=0 End Sub Private Sub Form_Unload(Cancel As Integer) FrmMain.PortOK = 0 End Sub Private Sub Command1_Click() If MSComm1.PortOpen = True Then MSComm1.PortOpen = False End If If FrmMain.PortOK = 1 Then FrmMain.PortOK = 0 End If 'close the form Unload Me End Sub Private Sub command2_click() If m = 0 Then MsgBox "That is NOT a binary word!", vbOKOnly, "Error" ElseIf Text1.Text < 111112 Then 'output the binary word Do Until Len(Text1.Text) = 8 Text1.Text = "0" & Text1.Text Loop MSComm1.Output = Text1.Text For x = 1 To 100 ProgressBar1.Value = x For gg = 1 To 10000 Next gg Next x 'not a valid output so... Else: Text1.Text = "Enter Your 6-BIT binary Word" m=0 End If

End Sub 'Close Serial port and exit mode Private Sub mnuFileClose_Click() If MSComm1.PortOpen = True Then MSComm1.PortOpen = False End If If FrmMain.PortOK = 1 Then FrmMain.PortOK = 0 End If 'unload the form Unload Me End Sub Private Sub mnuHelpAbout_Click() frmAbout.Show vbModal, Me End Sub 'Ensure that only a 1 or a 0 is entered Private Sub text1_keypress(KeyAscii As Integer) m=1 If InStr("01", Chr(KeyAscii)) = 0 Then KeyAscii = 0 End If End Sub

7.1.3 Decimal Mode Code Define variables Dim m Public PortOK close window Private Sub Command1_Click(Index As Integer) If MSComm1.PortOpen = True Then MSComm1.PortOpen = False End If If FrmMain.PortOK = 1 Then FrmMain.PortOK = 0 End If 'close form Unload Me End Sub close window Private Sub mnuFileClose_Click() If FrmMain.PortOK = 1 Then FrmMain.PortOK = 0 End If If MSComm1.PortOpen = True Then MSComm1.PortOpen = False End If 'unload the form Unload Me End Sub

Private Sub Form_Load() FrmMain.PortOK = 1 txtDecimalValue.Text = "Enter a decimal number from 0-63" 'enable the serial port MSComm1.Settings = "9600,N,8,1" MSComm1.InputLen = 0 If MSComm1.PortOpen = False Then MSComm1.PortOpen = True End If If MSComm1.CommPort = 0 Then MSComm1.CommPort = 1 End If m=0 End Sub Private Sub Form_Unload(Cancel As Integer) FrmMain.PortOK = 0 End Sub open about window Private Sub mnuHelpAbout_Click() frmAbout.Show vbModal, Me End Sub Private Sub command2_click() 'transmit word If m = 0 Then MsgBox "That is NOT a Decimal Number.", vbOKOnly, "Error" ElseIf txtDecimalValue.Text < 64 Then 'output info here Do Until Len(lblBinaryValue.Caption) = 8 lblBinaryValue.Caption = "0" & lblBinaryValue.Caption Loop MSComm1.Output = lblBinaryValue.Caption 'activate progress bar For x = 1 To 100 ProgressBar1.Value = x For gg = 1 To 10000 Next gg Next x Else: txtDecimalValue.Text = "Enter a number FROM 0 TO 63" m=0 End If End Sub Private Sub txtDecimalValue_keypress(KeyAscii As Integer) 'Make "ENTER" act like TRANSMIT_keypress If KeyAscii = 13 Then Call command2_click End If 'Cancel input if the key pressed is not a number If IsNumeric(Chr(KeyAscii)) = False Then KeyAscii = 0 End If End Sub

THE FOLLOWING CODE WAS DOWNLOAD FROM WWW.VB-HELPER.COM TO CONVERT DECIMAL TO BINARY AND MODIFIED FOR THIS APPLICATION Function Bin(Number) ' both Variants ' #Binary BITS# by Chris ' based on the Two's-Complement "shortcut" method '=========================================== Dim BitStream() As Byte Dim Bits As Byte Dim BitPointer As Byte Dim HexString As String Dim lenHS As Integer Dim HalfByte As Byte ' smallest VB word Dim i As Integer Dim j As Integer Const DABug As Boolean = False On Error GoTo eror Select Case VarType(Number) Case vbNull 'pass a null, return a null Bin = Number Exit Function Case vbByte ' 0 to 255 unsigned Bits = 8 Case vbInteger, vbBoolean ' -32,768 to 32,767 Bits = 16 Case vbLong ' -2,147,483,648 to 2,147,483,647 Bits = 32 Case vbSingle, vbDouble Bits = 32 ' HEX() will convert these ' to Longs (if possible!) Case vbString Case Else Err.Raise 2001, , "Not sure HOW to handle a (" & TypeName(Number) & ") DATA TYPE?" End Select '' if HEX() can't handle it, '' then neither can this code! HexString = Hex(Number) lenHS = Len(HexString) If Bits = 0 Then Bits = lenHS * 4 'bits ReDim BitStream(1 To Bits) BitPointer = Bits For i = lenHS To 1 Step -1 HalfByte = Val("&H" & Mid(HexString, i, 1)) For j = 1 To 4 ' bits

If HalfByte Then BitStream(BitPointer) = HalfByte Mod 2 HalfByte = Fix(HalfByte / 2) End If BitPointer = BitPointer - 1 Next j Next i 'now add 48 to all bits(bytes) for "0" or "1" For i = 1 To Bits BitStream(i) = BitStream(i) + 48 Next i Bin = StrConv(BitStream, vbUnicode) ' format it Bin = Trim(Format(Bin, "&&&&&&&& &&&&&&&& &&&&&&&&")) '(format it here? or outside this proc?) Exit Function eror: If DABug Then Debug.Print Err.Number & "-" & Err.Description Err.Clear Bin = "0" End Function Private Sub txtDecimalValue_Change() m=1 lblBinaryValue.Caption = Bin(txtDecimalValue.Text) End Sub

7.2 68HC11 Source Code

*********************************************************************** * ASCII Read/Decode * Written by : Nic Cameron on Oct.28,2001 * 334977 * * This program is used to Decode a 6-bit binary word that is * encoded as ASCII characters and then output the word via port B * *********************************************************************** * - Equate my Variables * * *********************************************************************** ORG $B600 BAUD equ $102B * Baud rate control register SCCR1 equ $102C * SCI Control Register 1 SCCR2 equ $102D * SCI Control Register 2 DATA EQU $003E * BIT RESERVED FOR INPUT OF DATA SCDAT EQU $102F * SCI Data Register SCSR EQU $102E * SCI Status Register ********************************************************************** * - Initialize the SCI ********************************************************************** LDAA #$30 STAA BAUD * baud register, 9600 bps LDAA #$00 STAA SCCR1 * 1 Start, 8 dat, 1 stop LDAA #$0C STAA SCCR2 * Enable tx and rx DATGET LDX #DATA LDY #$0008

* Enable counter to accept ASCII code

********************************************************************** * - Check for data * ********************************************************************** NXTWRD CLC NODAT1 LSL DATA NODAT LDAA SCSR * Read status register ANDA #$20 * Check recieve buffer is full CMPA #$20 BNE NODAT LDAA SCDAT * Read data CMPA #$30 BEQ ZERO BSET $00,X $01 * Set MSB of Data ZERO JMP NXTBIT **********************************************************************

* - Increment pointer for next bit * ********************************************************************** NXTBIT DEY BNE NODAT1 ********************************************************************** * -Output Word * ********************************************************************** LDAA DATA STAA $1004 * Output Binary word to Port B BRA DATGET

8.0 Appendix B- Schematic Drawings These schematic drawings were create using Orcad Capture. 8.1 Tx Schematic

8.2 Rx Schematic

9.0 Appendix D- Bill Of Materials 9.1 Tx BOM Component 9-pin D-shell connector MAX232 100nF capacitor LM741 CD74HC4046 1Kohm resistor 1uF capacitor 100Kohm potentiometer Purpose Connecting PCB to serial cable RS-232 to TTL translator Used in charge pump circuitry for MAX232, Supply voltage filtering, signal coupling Buffer for TTL logic VCO Resistors for LM741, tying Inhibit pin low on VCO Supply voltage filtering Control signal voltage divider for VCO, frequency control resistor for VCO Quantity 1 1 10 1 1 3 2 3

9.2 Rx BOM Component OPA620 LM741 Diode 1uF capacitor 100nF capacitor 100Kohm potentiometer Purpose High speed amplifier Comparator Rectification Supply voltage filtering, signal coupling Supply voltage filtering Gain adjustment for OPA620, voltage dividers for LM741 Quantity 1 1 1 3 4 4

10.0 Appendix E- Data Sheets

11.0 Appendix F -Bibliography Automating Science and Engineering Laboratories with Visual Basic by Mark F. Russo, Martin M. Echols Electronic Communication Systems, Fundamentals through Advanced by Wayne Tomasi Dallas Semiconductor Application Note 83: Fundamentals of RS-232 serial Commnications www.vb-helper.com www.ti.com www.maxim-ic.com

You might also like