Unformatted text preview:

EECS 100 uC Touch Sensor Interface B. Boser Page 1 University of California Berkeley Department of Electrical Engineering and Computer Sciences EECS 100, Professor Bernhard Boser LABORATORY 11 v1 MICROCONTROLLER TOUCH SENSOR INTERFACE We have already investigated touch sensors with the oscilloscope. In this laboratory we will interface them to a microcontroller. How could a microcontroller possibly measure a capacitance? A particularly simple solution that microcontrollers excel consists in precharging the capacitor to a known voltage and then measuring its discharge time through a resistor. Larger capacitance results in increased charge and hence increased discharge time. The figure shown above illustrates the concept. The switch is initially closed and opens at time t1. The voltage Vc across the capacitor decreases as Ctouch discharges through R. The discharge time is calculated as the difference between the time t2 when Vc decays to some reference level Vdis and t1. Touching Ctouch increases its value and hence the discharge time to t2’. The EE100 microcontroller board has two touch sensors and a discharge resistor connected to port P2 as follows:EECS 100 uC Touch Sensor Interface B. Boser Page 2 Measuring the discharge time of Ctouch1 involves the following steps: 1. Set P2.7 low 2. Set P2.6 high to charge Ctouch1 to VDD 3. Wait a brief period of time to ensure Ctouch1 is fully charged, e.g. delay(10) 4. Charge the direction of P2.6 to input 5. Store the current time in variable t1 6. Wait for P2.6 to go low 7. Store the current time in variable t2 8. The discharge time equals t2-t1 The current time is available in a variable called TAR. For example, the statement t1 = TAR takes a snapshot of the current time and stores it in variable t1. The skeleton program listed below (also available from the website for download) sets up the microcontroller configuration and then calls the function touch1 repeatedly to measure the discharge time of Ctouch1. #include "io430.h" void delay(unsigned int n) { while (n > 0) n--; } // RC capacitive sensor on P2.6 discharging into P2.7 int touch1() { unsigned int t1 = 0; // start of discharge interval unsigned int t2 = 0; // end of discharge interval // Set P2.7 low ... // Set P2.6 high to charge Ctouch1 to VDD ... // Wait a brief period of time to ensure Ctouch1 is fully charged delay(10); // Charge the direction of P2.6 to input ... // Store the current time in variable t1 ... // Wait for P2.6 to go low ... // Store the current time in variable t2 ... // The discharge time equals t2-t1 return t2-t1; } int main(void){ // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; // maximum clock speed BCSCTL3 = LFXT1S_2; // frees up pins BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ;EECS 100 uC Touch Sensor Interface B. Boser Page 3 // turn on timer A free running TACTL = TASSEL_2 + MC_2; // P1 is feedback P1DIR = 0xff; // P1 output P1SEL = 0; // digital out // configure P2 for capacitive sense P2OUT = 0; // P2 output low P2DIR = BIT6 + BIT7; // P2 is output P2SEL = 0; // P2 is digital i/0 P2REN = 0; // P2 disable pullup resistors for (;;) { unsigned int T = touch1(); // display T on LED bar ... // wait a little delay(100); } }EECS 100 uC Touch Sensor Interface B. Boser Page 4 LAB REPORT Lab Session: Name 1: SID: Name 2: SID: Complete the skeleton program to read touch sensor 1 an hand it in at the start of the laboratory Program for reading Ctouch1: ___ of 20 P Run your program on the microcontroller. Attach a scope probe (set to 10x attenuation) to the resistor near point P2.6 and verify that the waveform shows the exponential discharge. Printout of scope screen: ___ of 10 M Modify the code such that the length of the bar graph is an indication of the presence and size of a finger on the touch sensor. E.g. no or a single LED lit with no finger present, a few LEDs lit with a small finger or a finger at some distance from the sensor, and all LEDs lit with the entire touch sensor covered. Have the GSI verify your result. Proportional bar graph display: ___ of 10 M Congratulations! You have acquired a very impressive list of laboratory skills and can undertake quite challenging electronic circuit projects. I wish you success in your careers and hope that what you learned in EE100 contributes to this success. Feel free to continue experimenting, e.g. expanding this laboratory to also sense the 2nd touch interface connected to the microcontroller. More importantly, look for opportunities for electronic circuits in your work and come tell me about your projects and successes. Even after the course has ended I am always interested in hearing about new projects, discussing your ideas, and helping as I can.EECS 100 uC Touch Sensor Interface B. Boser Page 5 SUGGESTIONS AND FEEDBACK Time for completing prelab: Time for completing lab: Please explain difficulties you had and suggestions for improving this laboratory. Be specific, e.g. refer to paragraphs or figures in the write-up. Explain what experiments should be added, modified (how?), or dropped.EECS 100 uC Touch Sensor Interface B. Boser Page 6 PRELAB SUMMARY Lab Session: Name 1: SID: Name 2: SID: Summarize your prelab (P) results here and turn this in at the beginning of the lab session. Completed skeleton


View Full Document

Berkeley ELENG 40 - Laboratory 11 v1

Documents in this Course
Lecture 3

Lecture 3

73 pages

Lecture 1

Lecture 1

84 pages

Guide 4

Guide 4

8 pages

Diodes

Diodes

7 pages

Quiz

Quiz

9 pages

Load more
Download Laboratory 11 v1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Laboratory 11 v1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Laboratory 11 v1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?