capacitive touch multi-swipe to single

Discussion in 'The Projects Forum' started by djp8djp, May 5, 2014.

  1. djp8djp

    Thread Starter Member

    Jun 16, 2013
    30
    0
    Hi all. The title says it, but rather cryptically. Let me expound a bit...

    I have a guitar project, which has two momentary "physical" switches, which trigger an external unit for two different functions. These functions are essentially "use the next" or "use the previous". I have a small capacitive touch system on hand with which I'll be replacing these physical switches. It is from Adafruit (Standalone 5-Pad Capacitive Touch Sensor Breakout - AT42QT1070) ... no, this is not an ad, I have no affiliation with them, I just wanted to provide the details.

    But I'd like to take it further. Rather than have one touch spot (small circle or rectangle) for each switch, I'd rather have two strips. My goal is to be able to "swipe" perpendicularly across the strips in one direction to signal "next", and swipe in the other direction to swipe "previous". So I need something to monitor both strips, registering either one as a "first", and within a short time allowing the other to register as "second". If first=A and second=B, then momentarily close the circuit that was previously the "next" physical switch - I assume by a non-latching relay. If the order of events is first=B and second=A, then do the same with the "previous" circuit.

    Interesting? :cool: I hope so. Because I need help :(. I can manage the capacitive touch unit. And I can handle components and soldering. But I've only ever dealt with static analog solid state stuff - caps, resistors, pots, op amps, regulators, etc.. And I'm lost on timers and logic chips :confused:. But I have extensive experience in computer programming, in multiple high-level languages, and though I've never dealt with chip programming, I'd be willing to tackle the learning curve.

    The whole project is constrained to being onboard the guitar, and a lot of the "real estate" in its cavities is already occupied, so it's gotta be small. And there's really no room for an Arduino or RaspberryPi. And power is one or two 9V batteries.

    I have found a product that can do it, but it's way too big and has a lot of functionality that I'd never use. On the other hand, a lot of its documentation does a great job of introducing the basic mechanism of what I'm trying to do. If you'll permit me linking to something commercial, here goes...
    http://www.silabs.com/Support Docum...rt-capacitive-touch-and-gesture-detection.pdf
    http://www.silabs.com/Marcom Documents/Training Documents/lizard-labs-lesense-presentation.pdf (pp 16-18)

    Looking forward to any help with this.
     
  2. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    Welcome to AAC.

    I can't guarantee this is a sure fire solution, but in my very limited experience with touch sensors, I *think* you could do this with an 8-pin PICAXE using the touch feature. What you're describing is a quadrature encoder of sorts - this is used in robotics among other areas to determine both speed and direction of a spinning wheel. If A is detected prior to B, then you're spinning in one direction and vice versa.

    Assuming you're simply talking about two single switches, say A and B, I think the PICAXE microcontroller can do this in place of the AT42QT1070. No need for additional parts other than what would be needed to keep voltage to the PICAXE limited to 4.5-5V and whatever is needed to interface to your relay.

    The touch sensors themselves can be made of any metal of your choosing with a wire soldered to it and either placed under something like wood or acrylic or coated with paint or clear varnish - you can't allow your finger to directly touch bare metal or it doesn't work right.

    I can give this a shot if you could show us with a simple sketch with dimensions showing the size and placement of the switches relative to one another and how your fingers would be moved across them. Another question will be how fast you plan to move your fingers across both switches so we know when to "time out". I assume you don't want the circuit to do anything if one of the switches is touched beyond a certain amount of time.
     
  3. djp8djp

    Thread Starter Member

    Jun 16, 2013
    30
    0
    Hi, elec_mech. Thanks, that would be fantastic! I have done up a cartoon layout which I'll attach.

    The large oval you see is an outline of the controls cavity, in the lower bout of the guitar. This is a back-routed cavity, so the "hole" is in the back, leaving the front intact. The intervening wood layer is around 1/4" - I'm not sure yet, as I'm having the body done up, and it hasn't arrived yet. I'm hoping it's no too thick, but if I can get my ground plane big enough and my antennae small enough, it should work (fingers crossed). Even if not, I'll be wanting to use this on the next guitar, which will have a pickguard of 1.5-2mm plastic, so that'll work for sure.

    The cavity will be copper-lined, which will serve as the ground plane for the capacitive touch circuitry. Under that (which is actually closer to the top, front-facing surface of the guitar), will be two small copper strips, which will serve as the two "touch antennas". These are the blue strips. The grey circles are just the outlines of some of the other physical controls, included here for reference and orientation purposes only.

    The gesture that I'm planning is to "swipe" across the body surface (guitar top), in a motion perpendicular to the two antennae, and between the two larger/lower controls.

    How fast? Good question! I'd hop to be able to move pretty fast. As a real rough estimate (i.e. completely guessing), I'd say I might want a inter-antenna detection latency of 100msec or less. More might be fine, but even less would be better. The ability to do quick swipes would be a plus.

    Thanks again for offering to help out, it is greatly appreciated.
     
  4. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    I put your drawing in a drawing program and enlarged it to scale to see the size of the strips and their distance from one another. Looks like the strips are about a 1/4" wide and a little over 3/4" long and apart.

    I've cut some tin, soldered wires, and taped them to a piece of 3/16" (actual depth - may be considered 1/4" by industry). I've wrote a simple program to just detect one to see about the sensitivity. Pretty hard to see a reading through the wood, but the readings change based on whether I have it sitting on my desk or standing in free air as well as how close my arm is to it. Flipping it over and touching the metal (through a piece of tape) is order of magnitudes better, but this is something you can experiment with. I can experiment with thicker metal, different metal, and increase the surface area to see if that makes a difference, but before going that route, I want to test the direction detection in the software first. Not sure if I'll have time today to do that, so if not, I'll shoot for tomorrow.

    The thin plastic case should work assuming you're talking about acrylic or the like. I've tried these in the thin black plastic boxes RadioShack sells and something in that material just destroys the signal. I even thinned it out from the back as much as I could without going through the front and no dice. I had to mount the sensor on the front and spray it. Just letting you know not every plastic is a guarantee for success.

    I don't know if having the cavity copper-lined will help or harm the touch sensors, but I assume you've done more research on this subject than I. I'd suggest, if possible, trying the sensors with and without the copper liner to see if there is a noticeable difference for better or worse.

    I'll let you know when I have more to report.
     
  5. djp8djp

    Thread Starter Member

    Jun 16, 2013
    30
    0
    Wow, elec_mech, that's going above and beyond the call. I appreciate the effort.

    Actually, I'm not as concerned about the actual sensors themselves, as I've gotten that proved out to some degree already. The sensors I'm using actually each utilize two "plates", with a separation between them - thus, capacitive. In my case, one of the two plates is actually shared between the two sensors, that being the "ground plate".

    This is different than the kind of touch switch found on, say, a lamp - where a touch triggers the circuit. Instead, it is designed to work on proximity alone, and specifically through some intervening material. I gather that what you've done is similar, although I can't say that I understand completely how it works - but it must be similar. I think it is sensing a change between your two strips as a result of finger proximity. In which case, because I need two "switches", I'd need at least a third strip to make two sensors.

    Interestingly, three plates is what I'd intended. Two small strips on one large ground plane. Not actually "on", but separated by a thin insulator - say, cellophane tape. BTW - the cavity I'm using must be copper-clad anyway, so it's just serendipitously being used as a ground plane. The two "sensor" strips are proportionally much smaller not only for convenience, but also because it actually makes them work better! My original point of reference for that fact was this YouTube video (although I've found additional support since then)
    https://www.youtube.com/watch?v=QItuf6lNvmI&index=70&list=PLYzbITpTaBDeJ1vDHorFu_UQaPWlPo90Y
    The whole video is good. but the bit about proportional sizes begins around 4:00.

    So I think I'm good to go for the sensors. My original question was really more to do with what's downstream from there. Let's suppose that I have two such sensors working, each functionally equivalent to a SPST momentary switch. So they'd replace the two physical SPST switches that would normally be used in my system. But rather than just "tapping" one or the other, which requires a fair bit of precision in finding the correct invisible spot, I'd instead like to use "swiping gestures", which would require less precision. And be cooler. I'd want a "swipe" across both in one direction to equate to closing S1, and a swipe in the other direction to equate to closing S2.

    When you mentioned in your earlier post about the PICAXE, it was news to me. So I looked it up. Hey, that looks like it would be great! And it's programmable using simple Basic?... and the program uploads via USB?... and it's a DIP-8 through-hole chip that has multiple bidirectional in/out lines? Wow! That sure looks like the ticket to me!

    So I imagine that I'd have one touch sensor connected to one ("digital")pin, and the other to a second pin. Continually polling both these pins for state changes would detect when a "swipe" was started, whereupon I could branch to one of two time-limited subroutines, which would poll for the other pin's state change. If such occurred before timeout, then I could emit a signal on a third (or fourth) pin. This could trigger either a CMOS switch or a relay, that would perform the SPST momentary function that my overall system is trying to emulate. Viola !!! (maybe the PICAXE can do that last step all by itself - I don't know)

    Does that sound like I'm barking up the right tree? I'd appreciate any and all corrections and suggestions.
     
  6. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    Interesting video, I'll have to watch that from beginning to end sometime.

    The PICAXE has a built-in touch sensor feature of sorts using simply a piece of metal connected to a pin designated as a touch pin. I haven't been able to find a lot of information on it other than here. It is stated to be a capacitive sensor, so coupling what you have already learned, you may be able to make an even better (more sensitive) sensor. However, in the absence of such knowledge, I would worry about the copper ground plane negatively affecting the sensor if designed and used like the PICAXE example. However, maybe it will be even better, I just don't know.

    Forgetting about sensor design for a moment, yes, this is what I had in mind and, in theory, it should work fine with the PICAXE. The PICAXE uses a bootloader so it is not as fast as say a true PIC or a microcontroller without a bootloader. But I think for detecting two switch sensors in succession and sending an appropriate signal, you should be fine. If you were trying to make an electric keyboard and have the PICAXE respond to rapidly pressed switches and produce an appropriate tone, then I'd worry. :)

    I'd have to know more about what you are trying to trigger, but potentially, yes, the PICAXE could handle it. If not, you could use a BJT transistor or logic-level MOSFET to act as a switch in place of a relay.

    Yes, I do love the PICAXE for these types of projects - BASIC language, free software, and the chips don't cost much more (if any) than comparable microcontrollers.

    I can test my set-up to better emulate your planned design. Since you've done the research, should I attach a sheet of metal on the bottom of the wood (opposite the strips) and connect it to the GND of the circuit? Would this better simulate your design? I can then see how good or bad the sensitivity of the strips are. Or, should I put the metal sheet on top of the strips (separated electrically by tape) and test the sensitivity of the strips through the wood? I think the latter is closer to your planned design, but I'm not sure.
     
  7. djp8djp

    Thread Starter Member

    Jun 16, 2013
    30
    0
    I've put together another picture for you, that I hope will be more explanatory. This is the physical layout of my controls.

    I know this will work with what I have. It is a capacitive touch unit that I picked up, which will translate a touch to a contact into the closing of a circuit. I posted a reference to it in my first post in this thread. I will of course discuss this as much as you like, but I was really wanting to get help with what comes after that.

    So I have the equivalent of a pair of physical momentary switches. I intend now to hook each up to a digital input on a PICAXE. I know that I can write Basic code to perform what I want to do, up to the point of setting an output high (for some very small period of time) what the correct inter-switch activation and timing occurs.

    So then what? Here I am really 100% in the dark, although over the last couple of days I've been trying to get up to speed. I know that I really should learn a lot more and develop a deeper understanding of it all. And I'd like to, and most likely will once this project is finished. But right now I just don't have the time. So I need a "recipe".

    I have found various ICs that can act as switches. From the 4066 variants up to fancier stuff like the MAX4754. I know how to get the right Vcc that a chip calls for. And I know that they will accept the setting of the "control pin" for a given switch component in order to "close" the switch. So my biggest burning is .... how do I latch a given switch component? I gather (very fuzzily) that I may need some logic circuitry in there, and will likely need a flip-flop affair to "set" a voltage supply on or off. I know that I could manage getting any/all that onto a board, but really don't know how they work. The data sheets seem to NOT have examples (as I'm used to seeing with op amps)

    Please help a poor newbie. I'd also be happy if someone could point me towards some beginner-level introductions or real-world simple examples for actually using bilateral switching ICs

    ps - I have one other possible application for all this within the same project, which would double my mileage for this learning curve!
     
  8. djp8djp

    Thread Starter Member

    Jun 16, 2013
    30
    0
    BTW - in case you noticed, my earlier posts referred to using the PICAXE output to create a momentary switch, and my last post referred to a latching switch. In order to do the double-implementation that I mentioned, I really need to do both. For the momentary, I think I can drive a switch IC direct from the PICAXE (yes? no?). But for the latching I think I need some sort of .NOT. and a latch ?????
     
  9. djp8djp

    Thread Starter Member

    Jun 16, 2013
    30
    0
    I know much of this will be redundant, but I thought it'd help to lay out this thing properly from square one. I should have started the thread like this. Sorry.

    ******************************

    This project is part of a guitar modification that includes some mechanical switches. It's a polyphonic pickup, designed to be used with a guitar synthesizer, to produce special effects and emulations of other instruments. The special pickup itself is a passive inductor (actually, 6 little ones), and the bulk of the electronics are in the synthesizer. But the system requires that a few mechanical switches and some onboard electronics be installed in the guitar. I've attached the entire schematic of the onboard electronics (although most of it is moot, I'll be referring to parts of it). And for completeness, a picture of a guitar that's had the typical install.

    The onboard system gets its power (+/-7VDC) from pins 12 and 13 of a 13-pin cable (connector = "GK OUT"), which connects to the powered synthesizer. Low-level (approx 1.5Vrms) signals are generated by either the regular guitar pickups ("GUITAR IN") or the special pickup ("DIVIDED PICKUP", or "GK"). These signals AKA "music"... I hope. BTW, it may look weird to see a signal called GUITAR IN at what is actually the guitar's output jack... but the signal is IN as far as the synthesizer is concerned, and the jack is just where all the regular pickups' signals are ultimately routed to for their usual output.

    There are two momentary switches (DOWN/S1 and UP/S2). They change what sounds the synthesizer will produce. These I'd like to replace with a pair of capacitive touch switches. I plan not to use them as regular "spot" switches, but as "strips" that I can "swipe" across. My current plan is to to hook them up to digital in/out lines on a PICAXE, whose program will determine the timing and order of switch contacts. When its criteria are met, it will emit a signal on either of two other digital in/out lines. I'm hoping that these can simply trigger a switch IC to close, with its closed pin tied to ground, and thereby substitute for S1 and/or S2. So now I can avoid 2 holes in the guitar top. Yaayy.

    The user is also able to select which signals are sent to the synthesizer - the modes are GK, Guitar, or both ("MIX"). This is accomplished via a 2P3T mechanical mini toggle switch. The left side of the DP3T (SW2A, com=pin13) sends to ground either/neither of the signals from the Guitar or the GK. When the switch is at either extreme, this effectively "mutes" one of the signals, leaving the other live, and thus the backwards-looking labels are correct. When the switch is in the middle, both are on (=MIX). Meanwhile, the right side of the DP3T (SW2B, com=pin23) is running a +5V input voltage through a resistor network, and forwarding to output pin 9 a constant DC level of 1.56V, 1.04V, or 0.52V. This level is interpreted by the synthesizer unit, which implements the appropriate mode. It seems at first little redundant to have both of these functions. But the synthesizer can't tell the difference between a simple pause in the playing, or the "no signal" state of one input being grounded. So it needs the "help" indicated by the pin9 voltage set by SW2B.

    But I want to get rid of that mechanical 3-position DP3T (SW2A & SW2B) too. Instead, I'd like to implement two more capacitive touch sensors, connected to two more inputs on the PICAXE. A program very similar to the above would detect a "swipe" across them in either direction. One direction would equate to a function of "next setting" and the other direction would mean "previous setting". And these would function cyclically. So repeatedly swiping "next" would move the setting GK-MIX-GUITAR-GK-MIX-GUITAR-GK... etc. And repeatedly swiping "prev" would move the setting GK-GUITAR-MIX-GK-GUITAR-MIX-GK... etc.

    But this requires that the project produce more than the momentary function of the S1 and S2. This part needs to latch. I know how to chain two SPDT switches to create an SP3T - and two of these become my DP3T. And I can handle the programming of several PICAXE output pins that will manage all that for a given required system mode....

    ...but how do I latch the switch ICs?
     
  10. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    Ah, I think I see now. :D

    So you've got the touch sensor portion covered and just need to react to the sensors in a quadrature fashion then. So to recap:

    Goal A

    Replace two mechanical momentary switches, SW1 and SW3, with two touch sensors. However, instead of reacting to momentary pushes, you want to slide your fingers across each sensor rapidly. Which of the switches to be activated will depend on the order the two sensors are tripped. This is a momentary action (for tripping SW1 and SW3), correct?

    Goal B

    Replace a DP3T switch with a similar pair of touch sensors with a similar operation, except the direction of the slide determines direction of switch position so repeated sliding in the same direction will ultimately allow every switch position to be cycled through. However, in this case the switches need to latch.

    If this is correct, the PICAXE can do the latching as well. Switching the audio signals for part B will need to be done with something like the ICs you mentioned, a CD4066 or a MAX4754 (excellent find by the way).

    Part A may not need these ICs if you just need to momentarily make a signal GND connection. If unsure, then using the aforementioned IC switches is the safest bet.

    So for the touch sensors, you are using the AT42QT1070 in standalone mode correct? If I'm reading the datasheet correctly, it has push-pull interface on its outputs meaning the outputs do not float, which is great because this allows you to connect the output of the AT42QT1070 directly with a PICAXE pin, assuming you're using 2.3-5.5V to supply both ICs.

    I think you'll need a bigger PICAXE though to do everything. You'll need four inputs for the touch sensors and at least four outputs to control all your switches assuming you use the MAX4754. A 14M2 should do it.

    I can write a program to get you started. Since you're using your own touch sensor IC, I think I'll need to use something like IR or light sensors to simulate both touch sensor outputs rapidly. Testing the timing portion is important here, so I'm going to avoid using mechanical switches or attempting to use the PICAXE touch sensor function since these add complexity (and timing resources). The logic is a piece of cake, the work will be in debugging so we get the timing just right, but that shouldn't be too hard.

    I assume your touch sensor IC will output a high signal (~5VDC?) when a touch sensor is touched - is this correct?
     
  11. djp8djp

    Thread Starter Member

    Jun 16, 2013
    30
    0
    Wow. I just posted this reply, and my session timed out before I clicked “post” … and it lost the whole thing to the void. Grrrr!! Let me see if I can remember most of it.
    ----------------------------------------
    You have the picture perfectly. I would be very happy if the PICAXE could do all the switch latching. I’d looked into a “manual” solution, involving NOT and NAND gates, to perhaps buffering transistors to supply the latch voltages, and on to the switches. Aaaghhh!! Tell me I don’t gots ta go there!
    Of course, that’d only needed for project part B anyway. For part A, I’m more optimistic about the PICAXE being able to just send a switch IC’s control pin high momentarily, and be done. There are two such circuits, and the schematic strangely names both of the SW1 and SW3 connections as 1 and 2. But yes, a SPST IC switch could have its common connected to, say 1, and the NO pin to nothing, and the NC pin to 2. Then when the PICAXE sets its control high, it toggles, closes 1 and 2… tadaa. It may be necessary to hold it high for a moment, to let the synthesizer recognize it. I think regular TTL protocol is 1msec? And yes, I think you have the AT42QT1070 nailed down correctly.
    As for part 2, I think that I’d maybe be wasting some of the MAX4754. Its linked pairs of DT switches are cool, but I need 3 throws, so an IC that’s designed as 3T would do (does that exist?), or I could use a pair of SPDTs. I found the NLAS4684, which is a dual SPDT. I could use one of those to replace SWA and the other for SW2B. I’d need 4 PICAXE pins. I’ve laid out my understanding on an attached diagram – please correct me where needed.
    Unfortunately, that NLAS4684 is surface-mount, and I can only build in perf/vero/stripboard, so I’ll need a through-hole dual SPDT. It would be nice if it were bilateral, but maybe that’s not necessary. But a low Ron spec would be good, so as not to mess with the rather specific voltages passing through SW2B. Any recommendations for such a part?
    The 14M2 I’ll be happy with – I will for sure need the extra pins. The bonus is its ability to run two programs – two simple small programs are generally better than one bigger complex one. On the other hand, with two independent programs, the right hand doesn’t know what the left is doing. That may be an issue with my latest inspiration – I’d considered positioning the two pairs of capacitive sensor strips like an octothorp (“pound sign”, #). If that falls apart, I’ll just put them further apart, like this || = .
    The programming will probably be the easiest part for me. I write code for a living, but it’s been a while since I used BASIC, and I’ll have to learn PICAXE’s flavor (I usually write C++, C#, OpenGL, GLSL, CUDA). I’ll be looking into the language and tools this weekend. To see if I’m barking up the right tree with the program, I wrote a pseudo-code snippet for part A. This is the kind of thing I had in mind.
    Looking forward to your reply!
     
  12. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    As an aside, to latch something, you could use a T flip-flop. Look up CD4013 or 7474 with T flip-flop. You can do this with any flip-flop I think, but I like using D-flip flops because all you need to do is make one jumper connection. The T flip-flop acts like a divide-by-two counter. You send it one pulse (low-high-low) and the output goes low. Send another pulse (low-high-low) and the output goes high. The output is latched until it receives another pulse. And the 4013/7474 are dual flip-flops, so you can get two latches from one IC.

    You could then potentially use a quadrature encoder like the LS7184 by US Digital. It outputs a clock and direction signal whenever a quadrature signal is detected. Of course, one IC costs as much as a small microcontroller, so it's not really worth the effort, but something to keep in mind perhaps.

    I'll look at your code in detail tomorrow, but I'm sure you're on the right track. I can throw something together tomorrow as a proof of concept if nothing else.

    I think the MAX4754 would be perfect, but I need to draw it out first. It will do exactly what you've drawn if you picture a shared connection between SW2A and SW2B. These are switched at the same time according to the schematic, correct? If so, I think the MAX4754 will do it and you'll use all the pins and still only need two I/O pins. I'll try to draw something tomorrow.

    The PICAXE does have the ability to run parallel routines simultaneously, but I was thinking one program that checked all four touch sensors in rapid succession. If you'd prefer to parallel them though, I don't see a problem trying that. There may be some limitation of the PICAXE I'm not aware of, but testing will determine this.

    If you want to go crazy, you could use just three touch sensors. When you swipe between A and B, you'll engage SW1 or SW3 and if you swipe between B and C, you'll engage SW2A or SW2B. Put them in a triangle pattern and you could add another swipe feature between A and C! :eek:
     
  13. djp8djp

    Thread Starter Member

    Jun 16, 2013
    30
    0
    Hi. Wow, you see, this is why I need help with all that stuff downstream of the PICAXE. I read what you wrote, and it was pretty much just Greek to me. Although I had run across reference to D-flip-flops, I didn't think they were right for the job. See what I know? I'll try this weekend to make more sense of it.

    I think I agree with you about the MAX4754 after all. If I set it up the way I did in my last diagram, it'd be a good substitute for SW2A and SW2B. Right on. I guess I should have seen that. Maybe I did at one point - not sure anymore.

    I like your suggestion about three sensors. Inspired! But I think I'll stick with two pairs of strips for this go-'round. Maybe next time. And I'll just physically separate the two pairs a little, to avoid complications. (yeah, I know... too late!)

    I didn't want you to have to go to too much more trouble. I know you're going to work on the physical implementation, so I thought I'd do what I could and try to cobble together some better code. See attached. I looked up the language reference, and did what I could. I hope it can run without needing too much work. I wrote it in a text editor, no IDE, no tools. This is for project part A, which is the replacement of the two momentary switches SW1 and SW3. The parallel code for part B would be very similar.
    Naturally, there's a few talking points...

    - connect capacitive touch SPST momentary switches to PICAXE C.0 and C.1. They go high at 5V.
    - connect PICAXE B.1 to the control pin of one of the SPST IC switches
    (whose Common is to schematic SW1 pin 1, it's NO pin is to nothing, and it's NC pin to schematic SW1 pin 2)
    - connect PICAXE B.2 to another SPST IC switch's control pin
    (all the same as previous, expect for schematic SW3)

    - We'll consider the capacitive touch switch that I named CT1 to be physically located "above" the other, CT2. So a swipe "down" would be from CT1 (first) to CT2 (second). A swipe "up" would be CT2 followed by CT1

    - When a touch switch is closed, a Timer is initialized, by setting it from zero to 1. It's not a timer, really, just a counter. This non-zero state is used in various places as a flag that the Timer is "active". We will have 4 Timers. This means we can have up to 4 "swipes" ongoing at once. Why? Well, you have four fingers, don't you? So this will let us "swipe" or "strum" with 1, 2, 3, or 4 fingers, eliciting a corresponding number of output signals. The synthesizer should be able to keep up. I tried my outboard unit tonight, and I could tap the switch 10 times in a little over 1 second, and the synthesizer kept up just fine.

    - The program starts with all Timers zeroed (="off"). At the first closure of a touch switch, the swipe direction is determined by which of the capacitive touch switches was closed. The first Timer is then "started", and the program enters a "mode" of dealing with ONLY that direction of swipes. This is indicated by a direction-specific "Swipe Count" variable being set above zero. The program can register more than one swipe in the same direction (i.e., "strumming"), if it finds that the first switch is opened and re-closed, whereupon it starts another Timer. But it will not even begin to even look for swipes in the other direction until all swipes in the first direction are complete, or have timed out. The timeout is determined by a maximum, set at program start. It is not clock-based, but program loop-based, so I have no way of telling where to start with it. I think it should equate to about a second or so.

    - The program tracks the state of both touch switches, by setting a "flag" when they close or open. A switch closing triggers certain operations to be performed, such as starting or stopping a Timer. Monitoring the switch states enables us to ensure that these operations are not duplicated for a single switch closure. We do not allow them to be run again until a closed switch has once again been flagged as open. In other words, the program will only initiate ONE swipe (start a Timer) per one closing of a switch. Holding a switch closed has no additional effect

    - Note that the linear nature of the program means that it may be possible to "miss" some touch switch events. For instance, if we have a swipe count of more than one, then after the second switch of the swipe sequence is closed, the program will be busy setting an output pin high and then pausing for 2 milliseconds. It could happen that the second switch of the sequence is closed again, for less than 2 milliseconds, during this time. In which case, by the time that the program gets around to checking the switch states again, the program will have "missed" its closing and opening. The problem is self-correcting to some degree, in that the second time counter will eventually limit-out. This will amount to a missed event, but at least that's the worst error that is produced. In all likelihood though, because humans are much slower than microelectronics, as a capacitive touch switch is swiped by finger contact, it may remain so for several milliseconds - hopefully ample time for the program to complete even its slowest loop at least once, and "catch" the switch in its new state.

    - What is the PICAXE program size limit? I hope I haven't already passed it.
     
  14. djp8djp

    Thread Starter Member

    Jun 16, 2013
    30
    0
    Wow. Good thing I checked that attachment. It wanted to open as a .php file. Weird, it came from Notepad and has the .txt extension. I'm trying again as a Word97 .doc and .txt
     
  15. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    Attached is a first crack at a schematic.

    I've put your code into the IDE and made a few tweaks to syntax only so it compiles. As time allows over the weekend I'll study it and let you know my thoughts. Initially I think we can get away with a few less nested IF statements, but I haven't studied the code so we'll see. I will say I love the fact you use comments and tabbing, so reading your code will be very easy. Sorry, I'm sure being a professional programmer this is probably how you roll, but spending a lot of time with beginners, reading others code can be, at times, difficult. :rolleyes:

    Sorry if I wasn't more clear. The PICAXE can handle latching with no problem. The flip-flops are a way to latch an output for a purely digital logic solution (no microcontroller). Just wanted to give you that for future reference.

    The IDE for PICAXE is free, you can download it here. This is version 5.5.5 and it is stable. You may come across version 6 - this is a beta version and I don't recommend it.

    A couple of notes regarding your code - you don't need to use LET when assigning a value, e.g., variable_x = 1 works fine. Also, elseif statements are written with no space between them, e.g., elseif, not else if.

    Other than that, I think you're golden from a compiling perspective. Again, I'll review your code and get back to you. Let me know if you have any questions or concerns regarding the schematic. I added logic-level MOSFETs to act as switches for SW1 and SW3 since they are getting 7V from elsewhere. Might be a simpler way, but I know this isolates the voltages. An optocoupler is another way to go.
     
  16. djp8djp

    Thread Starter Member

    Jun 16, 2013
    30
    0
    I found one "else if", a spare space, and the subroutine "clearearliesttimer" somehow got mis-named "clearearliesttimer1" so I deleted the "1". And I got rid of the "let" commands - I was happy to, they bugged me. There are always those little language-flavor differences. There's one app I have to use occasionally at work, and the C flavor it uses is really oddball, seems to do everything backwards from normal, and I'm constantly violating its syntax.

    The pretty tabs you saw weren't tabs, they were spaces. Remember, I did it in a text editor on my breaks. But they're tabs now!

    So I cleaned it up, and wrote program 2. I had downloaded and installed the IDE, so I did it there (they're .bas now). But the darned thing doesn;t want to run or check syntax or anything. It says it can't find the executable (which I've set to PICAXE-14M2) Strange, because I navigate there in Explorer, and there's the file. Weird. I'll reboot, maybe the installer is funky. Or maybe it just needs a PICAXE connection to do anything at all (which would also be weird)

    Anywayyy.... here's some code for you. Programs 1 and 2. Program 2 is simpler, and might be easier to start with. For some reason, the forum uploader decided my .bas files were invalid. So I appended ".txt" to them... just chop that off and you should be good to go.
     
  17. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    Hmm, not sure what can't find executable means. With the code in the PICAXE IDE, you should be able to click on the SYNTAX button at the top and it will tell you if everything is on the up and up. I couldn't change the .txt file into a .bas file (not sure if this is a limitation with Win7 or something else), so I simply cut and pasted. I had to change the define for the CT pins to pinC.x. There are times when the IDE is fine with symbol = C.x and other times where it wants to see symbol = pinC.x. Something with how the variable is used.

    I've attempted to hand draw a flowchart based on your rev 01, but even with that I'm at a loss. Perhaps I'm not looking at the comments thoroughly since I'm focused on the code, but I don't know what the four timers are doing. For better or worse, it appears you're counting the number of times the program loops without a defined pause. Since PICAXE uses a bootloader and is inherently slow (relative to a microcontroller without a bootloader running) this may be fine, but I like to add a pause to get a since of time.

    I finally gave up and drew out flowchart of how I would approach this initially. I attempted to upload a .png, but for some reason the attachment system just went into space everytime I tried uploading it, so I had to convert it to a PDF instead. In essence, I've kept it dirt simple. Look to see if CT1 or CT2 is triggered first. If tripped sensor is released before TimeLimit is reached, look to see if second sensor is tripped and repeat. If second sensor is released within TimeLimit, trigger appropriate switch. If TimeLimit is reached in any case, clear the timer and wait for triggered sensor to be released then begin afresh.

    Let me know what you think. We can always build on this (or scrap altogether :)). I just need a simple base to start from so I can see what you're trying to do.
     
  18. djp8djp

    Thread Starter Member

    Jun 16, 2013
    30
    0
    Yeah, I know, unravelling someone else's code is never fun. I've had to do it with tens of thousands of lines at a time, so consider yourself lucky.

    Nice flowchart. I only ever use them at the macro scale, because at the code-line level they can get messy fast. Things like recursion are notoriously difficult to represent graphically. Even just multiple subroutine calls, like I used here, can be bad enough. What it boils down to is that the process is not strictly linear. A given sub may be called from number of places, and lines start crossing and it turns into spaghetti.

    I think part of the problem in grasping it is, as you mentioned, my inclusion of multiple timers. This I explained briefly, as a means to be tracking several simultaneously ongoing swipes. Tricky, but I think my code is essentially sound, barring slight debugging. Your flowchart looks like you got the gist of the simpler program 2, although it's not exactly what I wrote.

    Don't get your cranium in a twist. I'll do up a flowchart for you, with notes tacked on, that should get you there. But I'm heading out right now, so you may not see it tonight. Try looking mid-morning tomorrow (I am MST).

    I also have some questions regarding the MOSFET switching for program 1. But that must wait for now too.
     
  19. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    A very good point. I strongly encourage new programmers to do so so they can better "see" what they are doing. Likewise, I find it helpful when looking at someone else's code when it isn't immediately clear. As you stated, not worthwhile at a micro-level and you are no beginner. :D

    Yes, I need to read the comments in more detail. Perhaps I'm just thinking the operation is more linear than you have in mind. I see two sensors, with a simple on-off function: first sensor is tripped, then released, then second sensor is tripped, then released, then depending on the order, a switch is engaged. I gather you're looking for multiple detections, but having no background in guitar or music (unless you count an eclectic MP3 collection), I'm not yet following the desired operation. Sounds like we can learn from each other - always a bonus. :)

    Ask away when you're ready.
     
  20. djp8djp

    Thread Starter Member

    Jun 16, 2013
    30
    0
    OK, so I built some flowcharts for ya. Just PowerPoint, but I exported it as PDF. I also put together a companion document, that explains everything. Naturally, in painstaking mind-numbing never-ending detail. That's why I put it in a Word doc... so the post wouldn't explode. I highly recommend you read thru the doc, and refer to the PDF as required. I apologize for some of the introductory-level stuff, but I thought I'd better build it so thread newcomers could catch up.

    I'll put up my MOSFET switching questions later. Right now I need a break.

    Hey, have you noticed that this thread has almost 400 views, and it's only you and me talkin'? I'm not complaining - I'm sure between us we can nail this thing. I just thought it was odd.
     
Loading...