chicken 630 Posted September 19, 2014 Share Posted September 19, 2014 Thanks to an extended road trip (6000 miles) and receiving pieces for another project in the mail (hello dAISy), I'm a bit late with starting my ESI project log. But here we go. My project is to detect touch patterns on a resistive touchscreen, e.g. to wake up or unlock a device. My idea is inspired by figure 28-19 on page 772 of the MSP430FR69xx User's Guide: The picture reminds me of the circuit for resistive touchscreens: I plan to approach the project in 3 stages of incremental functionality but also difficulty: Detecting touch while ignoring touch location. This should be pretty straight forward use of AFE, TSM and PPU. Detecting touch in a specific quadrant of the touchscreen. As the ESI does not have an ADC but only a comparator, detecting the location will have to rely one a binary search algorithm: A measured voltage indicates whether touch happened above or below (and left or right) of a specific point. This will require more complex use of the TSM, maybe even invoking the PSM. Detecting a pattern of touch events by the means of a more complex state machine. Besides unknowns about the flexibility of the PSM, I also expect challenges with debouncing touch events. All the required hardware sits on my desk, so blame any delays on procrastination. Quote Link to post Share on other sites
greeeg 460 Posted September 20, 2014 Share Posted September 20, 2014 This is a very interesting. Ultra low power gesture recognition would be great for a lot of projects. Shame that resistive touch panels are less common that capacitive in consumer devices. Any project in mind to use this idea with? The comparator is connected to a DAC, so you should be able to get a reasonable resolution matrix for gestures. Quote Link to post Share on other sites
chicken 630 Posted September 21, 2014 Author Share Posted September 21, 2014 @@greeeg Der Weg ist das Ziel as the Germans say, i.e. the project is figuring out how to solve the problem. No concrete end application in mind yet. I just spent about two hours figuring out how to use the AFE to read the resistive touch screen. With a 4-wire resistive touch screen, one has to power the X axis and read the voltage on one of the Y wires. The measured voltage in relation to the total voltage applied determines the X position. Then the Y axis is powered and the voltage is read on a X wire. To avoid influencing the voltage divider, the unused X or Y wire has to be disconnected (i.e. hi-Z). I was all excited about the excitation logic built into AFE1, but as always it turns out that things are not as simple as I thought at first. Excitation means, that the selected ESICHx is pulled to GND and ESICOM outputs AVCC/2. Simultaneously ESICHx or ESICIx are enabled and one of the two is routed to the comparator. So how do I use this to implement the measurement procedure described above? Here's what I came up with after some serious head-scratching: The basic idea is to switch between two states: Measure X: Current flows from ESICOM (AVCC/2) via X axis to ESICH0 (GND), measurement on ESICI0 connected to Y- Measure Y: Current flows from ESICOM (AVCC/2) via Y axis to ESICH1 (GND), measurement on ESICI1 connected to X- As there's only a common pin to provide power, I added two PNP transistors that are turned on when the respective channel is excited (pulled to GND). The 10k resistors are there to prevent ESICOM from influencing the measurements, they are large compared to the touchscreen resistance (measured 333 and 600 Ohms for X and Y respectively). The resistors also mean, that I will measure AVCC/2 on both axis when the screen is not touched. So much for the theory.. looking forward for someone poking a big gaping hole into it Edit: Resized image Edit: Proper use of terms like power and current Quote Link to post Share on other sites
Fred 453 Posted September 21, 2014 Share Posted September 21, 2014 @@chicken I'm still trying to work the ESI out. I tend to flip flop back and forth between "Ah - I get it" to "WTF is this crazy peripheral about?". However I'm pinning my hopes on the section below. A lot of the ESI seems to be based around making it easier to use the more difficult sensors like LC for which you need the complicated excitation and AFE. Maybe for your touch screen you don't - although it worries me that the input seems to go direct to a comparator rather than to an ADC. Of course I could well be totally wrong about this as I've not really started doing anything practical yet. 28.2.1.4 Direct Analog And Digital Inputs By setting the ESICA1X or ESICA2X bit, external analog or digital signals can be connected directly to the particular comparator through the ESICIx inputs. This allows measurement capabilities for optical encoders and other sensors. Both analog front-ends have own control bits to select either the sensor input (ESICHx) or the direct input (ESICIx). This allows to use different input settings (selection of ESICIx or ESICHx) for AFE1 and AFE2. Quote Link to post Share on other sites
chicken 630 Posted September 21, 2014 Author Share Posted September 21, 2014 @@Fred think of the comparator/DAC combo as an ADC that tells you whether an analog value is higher or lower than a certain threshold. I.e. a hardware implementation of code constructs like if (analogRead(pin_x) > float_y) As for my theory above, there are at least two issues I found after some experiments on the breadboard: The transistors need resistors to limit the base current (you can tell I'm a n00b when it comes to actual electronics) The X and Y sides are not isolated well enough. When I power the X side and touch the display, the resistance through the sensor is low enough to turn on the transistor on the Y side, which completely screws up any measurement. The first one is easily fixed by adding 1K resistors on each side. The second problem however requires some more thinking. I could add two diodes between the negative side of the touch sensor and ESICHx. This will allow ESICHx to pull things low, but prevents the current to flow through the touch sensor in case of a touch event. The downside will be a lower voltage across the sensor due to the diode drop. Given that ESICOM is only VCC/2, i.e. about 1.6V, this could become an issue that limits resolution. I will play with this some more on the breadboard. Quote Link to post Share on other sites
Fred 453 Posted September 21, 2014 Share Posted September 21, 2014 I get what the comparator does. It's just limiting if you do actually want to know the input value. For instance, the comparator would do for disabling my laser of it's overheating, but it might be nice to be able to display the temperature too. Quote Link to post Share on other sites
chicken 630 Posted September 21, 2014 Author Share Posted September 21, 2014 Two more thoughts on the diode: There's no downside to use VCC instead of ESICOM to power the touch sensor. It will be turned off as long as ESICH0 and ESICH1 are Hi-Z. Note to self: Check datasheet about maximum current that ESICHx can sink. @@Fred Displaying concrete measurements is probably out of scope for this peripheral. You could (ab)use it to control a red/yellow/green LED to indicate the rough state of things. Quote Link to post Share on other sites
chicken 630 Posted September 21, 2014 Author Share Posted September 21, 2014 Adding the diodes seems to work as far as I can determine with a (sluggish) meter. Will have to verify what's exactly happening with my oscilloscope next. To answer my note-to-self above about sinking currents into ESICHx: I measured 9.8mA and 6.5mA respectively with 3.3V supply voltage. The MSP430FR6989 datasheet does not specify current for ESI specifically. There are some current specifications for digital pins on pages 44 and 45, which I interpret that an individual pin can sink 10-20mA depending on how close to VSS I need it to go. Does anyone have a more conclusive answer to how much current ESICHx can sink when internally tied to AVSS? Quote Link to post Share on other sites
chicken 630 Posted September 23, 2014 Author Share Posted September 23, 2014 After having proved out the touch screen side, the next step is to put the MSP-FET programmer and the MSP-TS430PZ100D breakout board into service. Thanks to these helpful posts by fellow members, I got first light within minutes (plus half an hour or so of soldering headers): How to operate that fancy socket: http://forum.43oh.com/topic/5848-esi-project-laser-coolant-monitor/?p=51193 Don't forget to clear LOCKLPM5: http://forum.43oh.com/topic/5750-scan-interface-applications-five-members-win-a-target-board-and-an-msp-fet/?p=51165 First light: #include <msp430.h> int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P1DIR |= BIT0; P1OUT |= BIT0; PM5CTL0 &= ~LOCKLPM5; while(1); } And I already love the MSP-FET, fits in perfectly with the rest of my furniture greeeg 1 Quote Link to post Share on other sites
chicken 630 Posted October 19, 2014 Author Share Posted October 19, 2014 Finally spent some time with this project again. Today I attacked the stimulation side, i.e. using the ESI timing state machine (TSM) to toggle ESICH0 and ESICH1. Below the working code, it took me only about 4 hours. #include <msp430.h> #define ESITSM_rep_wait ESIREPEAT4 + ESIREPEAT3 + ESIREPEAT2 + ESIREPEAT1 + ESIREPEAT0 + ESICLK // 32 ACLK #define ESITSM_rep_measure ESIREPEAT1 + ESIREPEAT0 + ESICLK // 4 ACLK #define ESITSM_state0 ESITSM_rep_wait // wait #define ESITSM_state1 ESITSM_rep_measure + ESIRSON + ESICA + ESIEX + ESILCEN + 0 // excite and measure ESICH0 #define ESITSM_state2 ESITSM_rep_wait // wait #define ESITSM_state3 ESITSM_rep_measure + ESIRSON + ESICA + ESIEX + ESILCEN + 1 // excite and measure ESICH1 #define ESITSM_state4 ESISTOP // rinse and repeate int main(void) { WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer PM5CTL0 &= ~LOCKLPM5; // release pins from Hi-Z P1DIR |= BIT0; // turn on green LED P1OUT |= BIT0; // configure all port 9 pins to ESI P9SEL0 |= 0xff; P2SEL1 |= 0xff; // configure ESI ESITSM0 = ESITSM_state0; // program ESI Timing State Machine (TSM) ESITSM1 = ESITSM_state1; ESITSM2 = ESITSM_state2; ESITSM3 = ESITSM_state3; ESITSM4 = ESITSM_state4; ESITSM |= ESITSMRP + ESITSMTRG0; // immediatly restart TSM sequence, use ACLK as initial trigger ESIAFE |= ESICA1X + ESITEN; // measure on ESICIx channels (instead of ESICHx), enable excitation logic ESICTL |= ESIEN; // enable ESI, this starts TSM while(1); } The main holdups were: Even though the documentation says that TSM starts running when ESI is enabled, one also has to set the initial trigger (ESITSMTRG0) to exit halt mode Forgot to disable dampening while exciting the channels, i.e. enable ESILCEN. If this bit is not set, the output of ESICHx will always be VCC. And here are ESICH0 and ESICH1 when connecting it up to my circuit: The ESI is not able to pull the voltage all the way to ground. I guess I will have to find a different way to sink the currents from the touch panel. But that's for another day. Quote Link to post Share on other sites
chicken 630 Posted October 19, 2014 Author Share Posted October 19, 2014 Here's the redesigned circuit. It now uses NPN transistors to connect the axis that's measured directly to GND, whereas before ESICHx acted as the current sink. The main challenge was to turn on the NPN transistor (conducting when base pulled high) when ESICHx is pulled low. I solved this by connecting the base of the NPN to the emitter of the PNP. Due to 10K resistors to VCC and GND for the PNP and NPN respectively, both are turned off when ESICHx is high/floating. When ESICHx goes low, the PNP is turned on, the base of the NPN goes high and also turns on, completing the connection to GND on the axis we want to measure. In case of a touch event, there's an electrical connection between the two sides and the opposite NPN transistor would turn on as well. We don't want this to happen, so two diodes ensure, that no current is flowing from the touch panel to the NPN transistor. The two 100K resistors pull the non-powered side to GND when there's no touch event. Without these, the voltage floats and measurements by ESICIx would be undetermined and noisy. Next up, verifying whether this also works when driven by the ESI. I will also experiment if using ESICOM instead of VCC works (probably), and whether it saves power (I don't think so). Quote Link to post Share on other sites
chicken 630 Posted October 20, 2014 Author Share Posted October 20, 2014 ESICH0 and ESICH1 pulling down now looks better. And CH2 at the point I will feed into ESICI0, without (left) and with (right) touch event: There are a two things I'm not happy about: Positive and negative spikes when the transistors switch. Might be caused by breadboard and long wires, I hope it goes away when I solder the circuit onto a perfboard. The 100K resistor takes a while to discharge the measured voltage to 0 when there's no touch event. 10K works better (used above), but I can also handle settle time inside the ESI with separate TSM excitation and measurement states. Any input on what could cause #1 in addition to breadboard capacitance and inductance from long wires, is highly appreciated. My EE skills are pretty rudimentary Quote Link to post Share on other sites
bobnova 59 Posted October 20, 2014 Share Posted October 20, 2014 Breadboard/long wire related inductance is the majority of it I'd guess. You get some of that just from the transistor(s) itself too. A very small cap between the blue trace and VCC or GND (doesn't matter as long as they're both clean. I'd probably use GND) will eat a lot of that spike without slowing the rise/fall times too much. My experience has been that even 10nF is enough to damp down spikes like those if there is some resistance in series with the incoming voltage (there is in this case, inside the touchscreen). That may even be too much, it's worth playing with. You mileage may vary of course. It's hard to say how long the spikes last on that scope setting.\ If they're the sub-microsecond-duration sort I'm thinking of they are very easy to kill with small caps. The longer they last the harder they are to kill. chicken 1 Quote Link to post Share on other sites
chicken 630 Posted October 21, 2014 Author Share Posted October 21, 2014 Thanks for the input @@bobnova. 10nF did the trick, I first tried 100nF which was too much capacitance. The spikes are almost gone, and it takes less than 50 microseconds for the measurement to settle down. I also added 47uF on the power supply side, but that didn't have any noticeable effect. Surprisingly (to me), the migration from breadboard to perfboard had little effect as far as spikes wer concerned. Before: After: I might have gone a bit over board behind the scenes Quote Link to post Share on other sites
Fred 453 Posted October 21, 2014 Share Posted October 21, 2014 Some nice progress @@chicken, but... err... that soldering could do with a little work. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.