ARM: Microcontroller Touch-switch Design & Test (Part 1)

Similar documents
Lab 4: Digital Electronics BMEn 2151 Introductory Medical Device Prototyping Prof. Steven S. Saliterman

USB Type A Female Breakout Hookup Guide

ECE 2036 Lab 4 Setup and Test mbed I/O Hardware Check-Off Deadline: Thursday, March 17, Name:

PIC Dev 14 Through hole PCB Assembly and Test Lab 1

Lab 4: Digital Electronics Innovation Fellows Program Boot Camp Prof. Steven S. Saliterman

E3B USER'S GUIDE. for QT310 / QT320 QProx IC evaluation and development Overview. Fast Start

Accelerometer-Based Musical Instrument

E85: Digital Design and Computer Engineering Lab 1: Electrical Characteristics of Logic Gates

ENGR 40M Project 3c: Switch debouncing

AT42QT101X Capacitive Touch Breakout Hookup Guide

CADSOFT EAGLE TUTORIAL

Goal: We want to build an autonomous vehicle (robot)

AT89S8252 Development Board V1.0. Manual

EMBEDDED SYSTEMS COURSE CURRICULUM

Pre-Lab: Part 1 Using The Development Environment. Purpose: Minimum Parts Required: References: Handouts:

Prototype PCBs design session

Lab #2: Building the System

PIC Dev 14 Surface Mount PCB Assembly and Test Lab 1

Copyright 2015 by Stephen A. Zajac & Gregory M. Wierzba. All rights reserved..spring 2015.

ENG-7680: SCADA Laboratory Experiments

Department of Electrical and Electronics Engineering SSN College of Engineering

- create new schematic to the new project, PCB design begins with a schematic diagram, which present how components are connected

REQUIRED MATERIALS Reread Lab Rules and Policies document EEL 3744 (upad and upad Proto Base) DAD/NAD Analog Discovery board PRELAB REQUIREMENTS

EE 354 August 1, 2017 Assembly of the AT89C51CC03 board

Figure 1. Proper Method of Holding the ToolStick. Figure 2. Improper Method of Holding the ToolStick

OLED Engineering Kits User Manual

COMP2121 Experiment 4

REQUIRED MATERIALS Reread Lab Rules and Policies document EEL 3744 (upad and upad Proto Base) Digilent Analog Discovery (DAD) PRELAB REQUIREMENTS

REQUIRED MATERIALS Reread Lab Rules and Policies document EEL 3744 (upad and upad Proto Base) Digilent Analog Discovery (DAD) PRELAB REQUIREMENTS

mbed Hello World! Introduction to mbed

Exercise 1. Section 2. Working in Capture

The EAGLE Schematic & PCB Layout Editor - A Guide

AT42QT1010 Capacitive Touch Breakout Hookup Guide

MTRX3700 Mechatronics

Complete Tutorial (Includes Schematic & Layout)

Drexel University Electrical and Computer Engineering Department ECE 200 Intelligent Systems Spring Lab 1. Pencilbox Logic Designer

Lab 0: Wire Wrapping Project: Counter Board

ST SPC58 B Line Emulation Adapter System

LDR_Light_Switch5 -- Overview

Quick Start Guide. January EAZ0081L02A Rev. A

Figure 1. Proper Method of Holding the ToolStick. Figure 2. Improper Method of Holding the ToolStick

NIOS CPU Based Embedded Computer System on Programmable Chip

Adapted from a lab originally written by Simon Hastings and Bill Ashmanskas

PAD ANALOG / DIGITAL TRAINER OPERATOR S MANUAL

Lecture 14: Prototyping and Schematics

[Note: Power adapter is not included in the kits. Users need to prepare a 9 12 V ( >300mA capacity ) DC power supply]

University of Hull Department of Computer Science C4DI Interfacing with Arduinos

OM13071 LPCXpresso824-MAX Development board

EECS 140 Laboratory Exercise 4 3-to-11 Counter Implementation

SECURE DIGITAL ACCESS SYSTEM USING IBUTTON

USB-to-I2C Basic. Hardware User s Manual.

ARM HOW-TO GUIDE Interfacing Switch with LPC2148 ARM

ARDUINO MINI 05 Code: A000087

V1BOOST-STEPPER Unipolar Stepper Motor BoosterPack for the MSP430 LaunchPad. User s Guide

BV511 Hardware Guide ByVac ByVac Revision 1.0

ECE 353 Lab 4. General MIDI Explorer. Professor Daniel Holcomb Fall 2015

Arduino Uno. Arduino Uno R3 Front. Arduino Uno R2 Front

Chapter 2: Introducing the mbed tw rev

Arduino ADK Rev.3 Board A000069

Pacific Antenna Two Tone Generator

Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

8051 Intermidiate Development Board. Product Manual. Contents. 1) Overview 2) Features 3) Using the board 4) Troubleshooting and getting help

University of Florida EEL 3701 Dr. Eric M. Schwartz Madison Emas, TA Department of Electrical & Computer Engineering Revision 1 5-Jun-17

Laboratory 10. Programming a PIC Microcontroller - Part II

Familiarity with data types, data structures, as well as standard program design, development, and debugging techniques.

Faculty of Engineering and Information Technology Embedded Software. Lab 3 Interrupts and Timers

LAB #1: The CSM12C32 Module and PBMCUSLK Project Board

IOX-16 User s Manual. Version 1.00 April Overview

External and Flash Memory

Logic Analyzers by Link Instruments, Inc Logic Analyzers

Figure 1. Proper Method of Holding the ToolStick. Figure 2. Improper Method of Holding the ToolStick

TurboTaig Instruction Manual

LAB 2: INTRODUCTION TO LOGIC GATE AND ITS BEHAVIOUR

EE 330 Spring Laboratory 2: Basic Boolean Circuits

ENGR 40M Project 4b: Displaying ECG waveforms. Lab is due Monday June 4, 11:59pm

Adafruit 1-Wire Thermocouple Amplifier - MAX31850K

CEIBO FE-5111 Development System

Lab 3: Building a Power Supply and a Stereo Amplifier

ARDUINO UNO REV3 SMD Code: A The board everybody gets started with, based on the ATmega328 (SMD).

Section 30. In-Circuit Serial Programming (ICSP )

Shack Clock kit. U3S Rev 2 PCB 1. Introduction

Lesson 5: Board Design Files

Using solderless breadboards

Cygnos360 V2 Installation Manual

AXE033 SERIAL/I2C LCD & CLOCK

This Part-B course discusses design techniques that are used to reduce noise problems in large-scale integration (LSI) devices.

Adafruit USB Power Gauge Mini-Kit

Chapter Operation Pinout Operation 35

Lesson 12: Preparing for Post Processing

UF-3701 Power Board Construction Guide

Infrared Add-On Module for Line Following Robot

Application Note. Tina Shahbaz-Khan EEPower EEC 134

Trouble shooting the DeskCNC controller:

HAND HELD PROGRAMMER QUICK START GUIDE

Interrupts and Timers

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

BehringerMods.com. Instructions for modification of Behringer SRC analog inputs and outputs

LED Sequencer 1.0 / 1.5

Introduction to NI Multisim & Ultiboard

One Grove Base Shield board this allows you to connect various Grove units (below) to your Seeeduino board; Nine Grove Grove units, consisting of:

Transcription:

ARM: Microcontroller Touch-switch Design & Test (Part 1) 2 nd Year Electronics Lab IMPERIAL COLLEGE LONDON v2.00

Table of Contents Equipment... 2 Aims... 2 Objectives... 2 Recommended Timetable... 2 Introduction Capacitive touch-switch principle of operation... 2 Sessions 1 & 2 Hardware & PCB Design.. 3 Sessions 3 & 4 Software... 4 Counting Loop Basics... 5 Software Implementation and Testing... 5 Further Optimization (Optional)... 7 Further Information... 8 Equipment Aims mbed module mbed account (one per student) LPCxpresso Base Board for mbed with OLED display Breadboard and IDC breakout adaptor Signal generator (for 0V 3V square wave output) Oscilloscope (to check signal generator output) EAGLE v5 CAD software (freeware version) In this experiment and its continuation (SWITCH next term), you will design, build and test a touchswitch input device used with a high-performance ARM processor. You will learn: Objectives How to implement embedded systems with appropriate use of high level languages How to design, build and test simple PCBs 1. Design hardware PCB for touch-switch 2. Become familiar with the mbed embedded programming environment 2 3. Write and test code for software implementation of one or more capacitive touch-switches via measurement of frequency on the microcontroller input pins. All software can be implemented in C++, a high-level programming language. 4. Next term, your PCBs will return from the manufacturer. In the SWITCH experiment, you will build and test hardware, choose component values, integrate and test the complete system by developing the software further. This experiment links to the programming exercise in Introduction to Computer Architecture course (EE2-19), which uses a low-level assembler solution to this problem. The code written for ARM in this experiment is expected to be high-level, you do not have enough time to write an assembler solution. Recommended Timetable Session 1 PCB tutorial, working through a simple sample design followed by the start of your (real) PCB design according to specifications provided in this handout. Session 2 Finish the real PCB design. Check for correctness. Submit for assessment Session 3 Familiarization with mbed environment. Write code to measure frequency on one input. Measure performance. Session 4 Code software for multiple inputs. Measure performance. If time allows, experiment with optimizations. Introduction Capacitive touch-switch principle of operation A resistor R and capacitor C, combined with a logic inverter, forms a Schmidt Trigger oscillator with output frequency dependent on values of R and C. The capacitor is formed from the parallel combination of a fixed capacitor and a touch-pad as shown in Figure 1. The effective capacitance of the touch-pad increases when a finger is brought close, reducing the output frequency.

If the output frequency is measured and compared with a fixed threshold frequency, this will give a touch/no touch indication. The system may have some noise, but using two thresholds for the output frequency, as shown in Figure 2, is an effective method to reduce noise. components for resistors, capacitors, touch-switch pads, hex logic inverters and the connector. If you wish to experiment with this at home, EAGLE can be downloaded to your own PCs from the web free of charge as a demo version. NOTE: The latest EAGLE version (v6) will not be compatible with the ARM experiment, so you musn t use it. This may also be the default version on the EEE system. Figure 1 - Circuit for a single touch-switch Figure 2 - Frequency Waveform A number of hardware circuits could be used to measure frequencies; we will explore the simplest and most flexible method. The digital oscillator output is connected to a microcontroller input port and software is used to count the number of signal transitions, measure frequency and perform thresholding. In a typical application of this, the microcontroller would have many other functions too, so the incremental cost of the touch-switch circuit is only that of the oscillators. Sessions 1 & 2 Hardware & PCB Design In this section you will design a PCB, which contains touch-pads, oscillators and an output via a connector (Figure 3) to the microcontroller board. The supply comes from the microcontroller (+3.3V) via the connector. You will be using EAGLE PCB software to design the touch-switch PCB with the given EAGLE library arm-parts.lbr, which has suitable 3 IDC socket mbed pin Port.Bit 1 GND 2 +3.3V 3 GND 4 +3.3V 5 6 p30 p30 P0.4 7 8 p29 p29 P0.5 9 p27 p27 P0.11 10 p28 p28 P0.10 11 12 p11 p11 P0.18 13 14 = must be kept open circuit Figure 3-14pin IDC socket pinouts. A ribbon cable will connect this to the LPCxpresso Base Board. In order to complete your PCB design, you should refer to the Specification for PCB on the ARM handout web page. List of actions for this task: 1. Work through the introductory EAGLE tutorial (see ARM handout web page). The questions (Q) in this are designed to help you understand PCB design issues. 2. Enter a schematic (circuit diagram) using components from the arm-parts library (from the EAGLE PCB files on the ARM handout web page) to construct 4 touch switches (Figure 1) and connect each touch-switch to a separate microcontroller I/O port via a single 14-pin IDC socket (Figure 3). You have some choice of packages, the IC must be 74HC14 and the capacitor can be small or large. Vcc for the 74HC14 IC should connect to the +3.3V pin from the connector. 3. Check schematic consistency using ERC.

4. Check the PCB board specifications on the ARM handout web page. These include important board layout requirements. Follow these requirements carefully. Ask a demonstrator if there is anything you do not understand. 5. Convert the schematic to a board. Change the size of the board outline to that specified by moving the top and RHS edges. Clicking the middle of each edge will move it as a whole. Check the horizontal (X) and vertical (Y) dimensions using statistics-brd.ulp before you start placing components, since changing these later will be troublesome. 6. Arrange components within the PCB boundary. Add your lab group name (important), PAD names on the layout and any other text you wish. 7. Use auto-route to make PCB tracks. If you do not get 100% optimization, or if the layout is non-optimal, you may need to rearrange the components. See the box Routing Constraints below for instructions on optimal routing. Routing Constraints PCBs can induce electromagnetic interference between adjacent tracks. In this circuit the only problem you will meet is the inverter inputs, which are high impedance nodes and can pick up interference. Specifically they can pick up interference from fast edges on other inverter outputs. The effect of this can be to lock oscillator frequencies together. To avoid this problem, ensure you inspect all tracks connected to each inverter input and check that it does not run adjacent and parallel to the tracks connected to an inverter output for more than 5mm. 8. Add testpoints and connections so that you can test the board before you connect them to the microcontroller. It will be useful to have testpoints connected to GND and Vcc. Reroute connections as necessary. 9. Check board consistency with DRC. 10. Do one final check of the board specifications, as well as a DRC check. Submit board for manufacture via the link on the ARM handout web page. 4 NOTE: that PCB submission is assessed and must be completed BEFORE THE END OF THE TWO SCHEDULED WEEKS OF THE EXPERIMENT. Sessions 3 & 4 Software The software task requires you to measure the frequency of the (digital) waveform on a generalpurpose I/O input to the mbed module. The two methods to measure frequency are: 1. Count the number of cycles in a fixed time interval 2. Count a fixed number of cycles and measure the time interval Both methods are possible. For highest performance (fixed time periods provide better noise immunity) we suggest you use the first method. This can be implemented with a main loop code that loops until stopped by an interrupt service routine, or ISR function, while counting the number of cycles. The ISR function will be executed after a fixed time period from when counting starts, by the hardware interrupt mechanism. Code on this function will signal to the main loop code that it should stop. On return from the ISR, the main loop code will end the counting loop and compute frequencies. The psuedocode of this procedure is shown in Figure 4 below. // Skeleton Psuedocode int main() { while(1) { while(/*timer not timed out*/){ // Counting method goes here // Computation of frequencies goes // here isr_function() { // Stop the counting loop Figure 4 - Skeleton Psuedocode You will learn about interrupts in your Introduction to Computer Architecture course. The details of this are not needed in this experiment because the interrupt mechanism is wrapped in an mbed Timeout object, explained below, which makes it easy to use.

Using an interrupt in this manner has the advantage that the main counting loop computation time will be smaller, which means the counting loop will work for higher input frequencies. The mbed platform has high-level support for such interrupts (e.g. the Timeout class), which makes this straightforward even if you have no knowledge of the underlying mechanism. Your final deliverable in this experiment will be to implement embedded code on the mbed that will measure the frequency of multiple microcontroller input pins driven by logic level waveforms. Higher maximum frequencies measured are desirable. Counting Loop Basics Figures 5 and 6 show two different implementations of the pseudocode needed for mbed to count the number of cycles of a digital input. In Figure 5, the outer loop code is executed once per cycle of the input. The two inner loops each execute for the time the input is low and high, respectively. In Figure 6 the loop executes continuously. count = 0; // Set up Timeout object to change a // global variable after T ms. // This loop executes till Timeout // happens. while (/*timer has not timed out*/) { while (pin == 0) { pin = iopin(); // Read digital value on I/O pin // into pin while (pin == 1) { pin = iopin(); // Read digital value of I/O pin // into pin count = count + 1; Figure 5 - Pseudocode to count number of input cycles: version 1 // global variable after T ms. // This loop executes till Timeout // happens. while (/*timer has not timed out*/) { pin = iopin(); // Read digital value on I/O pin into // pin if (pin!= pin_slave) { count = count + 1; pin_slave = pin; Figure 6 - Pseudocode to count number of input cycles: version 2 Q Which pseudocode would be possible to adapt to measure multiple input frequencies during the same period? For each pseudocode or for the one you decide to use: Q How does the value of count relate to the timer period and the input frequency? Q How could the algorithm be adapted to measure multiple input frequencies simultaneously? Q What happens to these loops if the input frequency is too high? Q* How would an input which has an asymmetric duty cycle (e.g. 1 for 10 ns, 0 for 20 ns) affect the maximum frequency at which the code will work? Q* Is there a minimum frequency which can be detected? You may be able to answer these questions theoretically and in any case will verify your answers experimentally. Software Implementation and Testing Using your mbed module and the instructions on the handout page, set up for an mbed account on the mbed website (mbed.org). (You should wait at least 30 minutes or so after setting up the first account before repeating the process). You may use either account for the experiments. When signed in to the mbed website note the tabs: count = 0; // Set up Timeout object to change a 5

Compiler: Gives you a cloud-based workspace from which you can write, compile and download your programs. Handbook: Quick reference on the standard mbed I/O functions (API). Cookbook: Extensive reference on other code including the EAOLED code that controls the display on your board. The mbed module has a USB interface entirely separate from the microcontroller, which enumerates as a USB flash disk. This disk can contain multiple files and is seen under windows. When the microcontroller starts, it automatically downloads the most recent hex file as a program and runs it. This is what you usually want. When you use a module it may already have files on it. You can ignore these. It is possible to delete files from the module, but you must wait enough time for the operation to complete (it is slow). If you don t do this, you corrupt the USB flash disk. In this case, should it happen, the solution is to reformat the disk and start again. Since everything on the USB disk is temporary this is not a problem. Nevertheless, to save time, you are advised to make no changes to files on the flash disk unless this becomes necessary - for example if the disk is full. List of actions for this task: 1. Download the EAOLED zip file from the ARM handout web page. 2. Log into your mbed account and open up the cloud compiler. 3. You will need to import the EAOLED zip file as a program into your mbed compiler (right-click on "My Programs" from the Program Workspace panel and select "Import Program" option. Select the "Upload" tab and browse to downloaded EAOLED zip file. When it shows up on the list, click "Import!"). 4. The imported file (main-test-oled) is a sample main file that demonstrates how to write to the OLED and use Timeout objects. Before compiling the code to run on your mbed module, it is likely that the library dependencies are out of date and needs to be updated. Expand your program directory from the Program Workspace panel and click on mbed build (cog symbol). Click "Update" on the Program Details panel on the right. 5. You can now modify the sample file, or write your own main file, to implement your code. Using the mbed compiler and API, write code that could implement a single touch switch by detecting the input frequency on a pin. The following mbed C++ API classes will be needed: Timeout, DigitalIn (see documentation in mbed web handbook). You are however free to use others as necessary. To debug and instrument your software initially, write code that will display the measured frequency from an input pin on the OLED display. Make sure that the measurement time can easily be changed. Because the Timeout object code operates asynchronously of the main loop code, it is essential that all global variables used to communicate between Timeout code and main loop code are declared volatile. You will find an example of this in the skeleton code. Q The Timeout object in the mbed API is implemented by an interrupt. When the specified function terminates, the interrupt will return and execution resume as though the Timeout had never happened. How does the Timeout code signal to the main code that the Timeout has happened? Q* Why is it not a good idea to put code executed after the timeout into the Timeout function, rather than the main code. (This is possible, but not recommended). Q** Why is the volatile declaration needed here for some global variables? Test the operation of the software loop before testing the hardware by modifying each inner loop so it terminates immediately (version 1) or so that count is always incremented (version 2). Observe that the count is correctly displayed on the OLED and changes as expected if the Timeout period is changed or the loop time is made shorter or longer, by adding extra code. 6

Q How do the final value of count, loop time, and Timeout time relate to each other? Figure 7 documents which mbed inputs are available on the IDC breakout adaptor. construct a Schmidt trigger oscillator on the breadboard using the +3.3v supply, be very careful to check connections. Figure 8 - Important Safety Instructions Connect the waveform to one of the mbed inputs using the supplied connection lead. Debug your code and determine what the maximum frequency it can measure is. Q How does the maximum frequency vary with asymmetric input waveforms? GND GND (P0.11) p27 pn P0.M = = = 1 3 5 7 9 11 13 2 4 6 8 10 12 14 +3.3V out +3.3V out p30 (P0.4) p29 (P0.5) p28 (P0.10) p11 (P0.18) must be not connected mbed pin N LPC1768 - Port 0, Bit M TOP VIEW as plugged into breadboard Pins are as on the DIL adaptor photo above Figure 7 IDC breakout adaptor pinouts Use a signal generator for hardware testing. Read and follow the protocol in Figure 8 before you touch the hardware. The mbed modules are fragile and will break if you connect a signal generator with the wrong output. IMPORTANT 1. Check scope GND and function generator GND are connected to board GND on the IDC breakout adaptor. 2. Set scope to measure 3.3VDC. Check this is correct by measuring board supply from the IDC breakout adaptor with a scope. This should be 3.3V. 3. Check that function generator square wave output varies between 0 and 3v. Note that this voltage range will require use of the offset knob. 4. ARE YOU SURE ALL IS OK? ERROR WILL BREAK mbed. Connect the signal generator. 5. Make sure you do not normally connect anything to the +3.3v supply from the adaptor. It is permitted if necessary to Q* Can you predict this from your earlier measurements? In order to use this software with your n touch switches (n = 4 typically) you will need to measure n input frequencies on different input pins. If you do this one after another, which is simplest, your switch delay time will be larger than if you do it in parallel. Of course using a shorter measurement time interval would solve the problem but you will find that times shorter than 20ms have much larger interference from mains and are therefore less good. Q* Why might time intervals shorter than 20ms have larger mains interference? Q** Can you find an analytic expression for the likely error due to mains interference as a function of measurement time assuming that mains waveform is a 50Hz sinusoid? What other assumptions do you make in developing this? To finish the experiment implement and test software which measures simultaneously multiple switch input frequencies. Further Optimization (Optional) This section is optional in case you finish early; it contains some ideas for speeding up the counting code, some of which are simple while others quite complex. Don t attempt them unless you have completed the rest of the activity. You are also encouraged to use your own initiative to investigate or improve the code, so you are not limited to the ideas here. 1. The PortIn API class is more difficult to use than DigitalIn, but considerably faster. 7

2. The input lines from the hardware are routed to different bits on the same LPC1768 port. They can therefore be input in parallel, as a single 32 bit word. It is possible to implement counting as a sequence of 32 bit logical operations, with a number of registers holding the bottom few bits of the required count. Note that C bitwise logical operations (& ^ ~) will compile to ARM logical operations. 3. Migrating parts of the code to assembler will possibly (but not necessarily) speed up the code. See documentation under mbed site for how to write assembler and note that the Keil tools can also be used. Not however for the fainthearted. The mbed module uses an advanced ARM ISA, which is backwards compatible with the ARM7 instructions taught in Introduction to Computer Architecture. Read the Keil ARM documentation for details. 4. Note that the code you test in this experiment will be used in the SWITCH experiment Spring Term. You will make further enhancements and changes to it at that point. Capacitive touch-switches are now widely used, as are touch-screens. One popular implementation, with sophisticated special-purpose ICs, determines the position of a finger by the ratio of capacitance changes in an XY grid of wires. This allows position sensing on a finer grid than the wires used to sense. The mbed framework is very easy to use but inflexible. You can create hex files compatible with the mbed platform using Keil tools (see Introduction to Computer Architecture web page). The mbed website gives further information. One advantage that the mbed compiler has over Keil is that it is not size limited; the free version of Keil is limited to 32K. mbed modules cost 40. There is however a new cheaper module. Also, the NXP LPC1768 microcontroller is cheap and can be used on its own with suitable programming tools, but note the difficulty in soldering SMT packages. Further Information If you are interested in this experiment the following resources will take you further and may be useful in future project work: 8