Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 25 of 25

Thread: Noob FAQ before it begins

  1. #1

    Noob FAQ before it begins

    Hi all,

    I am totally new to this and extremely excited. I have some medium programming knowledge and have been soldering here and there and I believe I can go ahead and try to do something nice with the Teensy.

    I am set to build a one way only (for the now because it is simpler) modular midi to usb device. The goal is to maximise the analog ins with 4067s.

    [Edit: I ended up using 4051 as Paul repeatedly mentions them I figured they might have been safer for a newbie]

    I understand I will have to start small and grow as I get confidence as many say. That is fine.

    Before I embark on this journey I would love to hear some suggestions about what I understood and what I haven’t, and I guess the list of my question could be very well used as a FAQ for total noobs.

    1. the recommended impedance for linear potentiometers is 10k ohms. Higher values add precision but more noise, lower values have less noise but less precision. Right or wrong?
    2. If one is set to use tons of potentiometer (32,64,128,256,..) wouldn’t be appropriate to use 5ks (or less) to reduce the noise given that for midi we only need 7 bits resolution?
    3. Is there any sense in having a potentiometer with a higher mW value? I see the majority being 250 mW or 500mW, are the latter to be preferred?
    4. Considering distance, noise and cables: in general, is it better to have the mux closer to the teensy or to the pots? Since I’d like to make it modular, I’m thinking of using widespread 5 pins din connectors to the modules which would host the potentiometers and the mux.
    5. Potentiometers are to be connected in parallel and not in series, and directly to the teensy even when interfacing with a mux. Right? (That makes the soldering more difficult though).
    6. It is not recommended to solder directly on the pins and use headers instead.
    7. On the software side: the delay needed to read properly a mux is negligible for non time critical applications (such as a midi controller). The loops in the software will run fast enough to be well within tolerable latencies (let’s say 2ms or the likes) even with a number of muxes connected to the same 4 digital pins.
    8. To manage eventual noise there are two main solutions:
      a. add capacitors between the input and ground of the potentiometers (or something like that, apologies!). This would require added latency to the reading of each mux channel of about 1ms though.
      b. use analogReadAveraging in the code
    9. Besides having a custom pcb built, is it better to use a breadboard to connect components or there is noticeable degrade compared to manual soldering (let’s consider the soldering might not be at super professional level). Is using tons of female/male - cable - female/male wirings considerable?
    10. How would you recommend soldering so many things in parallel (to the 3.3 pin for instance)?
    11. Wires: am I totally wrong in thinking that the thickest and more shielded the better as long as you can solder the head/fit it into female headers? As a thought experiment let’s suppose I connected a 3A 220v standard solid wire fro the pot output to the analog pin. Would that make sense (besides being overkill?)
    12. The 3.3 to pots wire (considering a single wire to a 5pin connector which will then go to the pots in parallel should be larger right?
    13. There are tons of 4067s with different other codes/letters in catalogues. Are they all sort of similar or should I really pay attention to part numbers etc. You guys all seem to mention it as just a 4067 variating from HC to HCT to the BE at the end. Apologies for the very stupid question.
    Last edited by apoikos; 09-19-2016 at 06:09 PM.

  2. #2
    Senior Member
    Join Date
    Aug 2013
    Location
    Gothenburg, Sweden
    Posts
    412
    Without answering your questions, I would suggest first building a small 8 pot system that can be connected directly to Teensy ADC or through a mux.
    Set it up on a breadboard to begin with.

    This will give you a chance to answer your own questions and be confident in how things work.

  3. #3
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,938
    Most of your points are valid, but probably the most critical is the physical build of this thing and how reliable you can make it, which should trump many of the 'ideal' choices in place of 'rock solid' So mlu's comment above is very valid. Time how long it takes to build out 8 pots+ panels etc and multiply...
    Point 1 - pretty much, choice is very much what is cost effective and robust for your application - watch for linear vs log pots, for ADC reads you want linear ones, for final stage gain you want log.
    point 2 - see above, wouldn't go below 1k since each pot will have 3.3/1000= 3.3ma flowing so 32 of them will suck 0.1 amps and start to become a meaningful part of the power budget.
    point 3 - No, what is critical is noise, not the EMI sort but the variations in the wiper as it moves. Older cheap devices with volume controls often crackle and spike if you adjust the volume knob and get variable results of the pot surface. Physically larger pots will often have larger physical range of motion and wiper area but haven't actually seen anything analyising different price points in pots for reliability, repeatability and effective LSB.
    point 4 - Noise wise the keep the analog lengths minimal, and design wise having the MUX close to the pots will make wiring simpler to work with. Long leads from the MUX will impact the switch time since there will be cap effects for the new pot to overcome but that's normally only a problem with high impedance sensors, not pots. At least till you get to 100s of meters.
    Point 5 - not clear on this other than that yes they do need to be independent unless you actually want to have mixed signals (cross fade)
    point 6 - It's more robust to mount the Teensy to a board, and something to be said for socketing it, since you may need to replace/move it.
    point 7 - yes, for human interface inputs you should be able to get all your readings done. Reading FROM something different story and you'd need to do some math.
    point 8 - Suggestion is mixture of both(small caps, and sensible averaging) - critical step is to avoid code that means a single LSB noise causes final 7/8 bit value to also toggle (you want hysteresis, not just decimation) If doing averaging can be useful for debug to also measure standard deviation as a warning that you having something amiss on one or more channels.
    point 9 - spring bread boards can only ever be temporary and WILL bite you without warning with loose wires. Solder is for more robust once you are not swaping things around, and you can use perma proto boards to make it easy to transition a design. https://www.adafruit.com/product/571. Adding plugs where sensible is a great idea, just as long as they are robust. Anything expensive enough to hurt if the design has to be scrapped should have a plug so you can move it to the new design. IDC plugs are great for simple cable fab (though not rated for lots of plug cycles). For bread boarding/strip board prototypes where you can't easily split the two rows nothing wrong with just running wires in parallel and using a cable with double the number of needed pins.* see note
    point 10 - With lots of things in parallel you need a power supply system, and you want to have separate power for the pots and all the digital elements, or at least a LC filter to keep things sensible. You may also need to wire in and setup analoge ref to your 3.3V pot supply https://www.arduino.cc/en/Reference/AnalogReference - note that for Teenys it's 3.3V that must not be exceeded on that pin, so design accordingly.
    Point 11 - pretty much any wire size that you can sensibly handle will carry the currents for anything but actual power. Using coax will help noise wise, but in this case other problems will swap things and be a massive pain to work with - pick whatever wire/connector types you can reliably work with - perfect signal quality doesn't help if you have to pull it apart several times to fix build quality issues.
    point 12 - Unless you are drawing more than 0.1 AMPS wire size really doesn't matter. If you are then grab an online calculator and get the right wire gauge. If the design can change current draw rapidly larger wires may be needed (motors etc) but pots should have the same current draw regardless of position if you are designing this right.
    point 13 - don't know enough on multiplexers to answer that but would strongly suggest looking up the data sheets for anything you are looking to use. Don't need to read the whole thing but the first or second page should have a table that summarise the features and anything that is different between them you need to look up and find out what that means (OEMS will be putting any 'pick me' features in that table). Also check package type and pinout matches what you are expecting.

    * note- When designing plugs:
    Always put mains power on a plug designed for the purpose
    Always have power on the female plug (no exposed pins to short things)
    where possible use keyed connectors to prevent backwards/off by one insertion
    If you are not using keyed connectors, mark pin 1 and put any critical pins (power, especially 5V power) on a pin that is not connected when reversed
    If you use the same connector size/keying twice, make sure nothing bad happens when they are swapped (use identical power/gnd connections)
    Make sure your cables are long enough you can run things 'open' (you can access rear of the face plate)

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,075
    Quote Originally Posted by apoikos View Post
    You guys all seem to mention it as just a 4067 variating from HC to HCT to the BE at the end.
    The ones beginning with 74HCT are usually best to use. Run them from 5V power, which allows for the mosfet switches inside to have lower on resistance.

  5. #5
    Thank you so much for the help to all!

    I really apologise for disappearing for ten days but it's been messy.

    @mlu I will certainly (and I have indeed, just started with 1 , 2 etc.. ) do baby steps!
    @GremlinWrangler Thank you so much for the time you took. It's all pretty clear except one point regarding power which also goes to Paul (although he's probably busy shipping 3.6s which I backed yeah!)

    - If i run 5v external power to the pots I then have to: a) either use the internal resistor (pull_down??), b) add my own, c) do nothing in the teensys that are 5v tolerant? I'm really not clear on this.
    - For instance, if as Paul says I power the 4051 from 5v then I will also have to power the pots the same. Can I feed the common out directly to the teensy? I am currently working on a 3.2 but I think I should really grasp this concept before I go on.

    Can't wait to do things! Reading a few pots per se was a piece of cake even for a total total total noob.

  6. #6
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    4,027

    Cool

    Teensy's run at 3.3v. I didn't see whether you were using either the LC or the Teensy 3.2 (I'll ignore the 3.0/3.1).

    You can power your Teensy with several different methods:
    • Use a 5v micro USB cable that can supply the appropriate amps that the Teensy needs. There is a fuse in the Teensy that prevents the Teensy from drawing too much power. In the 3.1, it was 500mA, but the schematic doesn't list a value for 3.2;
    • Apply between 3.6v and 6v to the VIN pin and connecting one of the 3 ground pins (but not the AGND pin which is between VIN and 3.3v pins on the Teensy 3.2). You probably want to only one one power source at a time, or provide the appropriate MOSFETs so the power doesn't go backwards to your power source;
    • If you are going to provide both 5v connections, you can cut the solder junction underneath the Teensy, so that the USB no longer provides power, unless you connect VIN and VUSB (https://forum.pjrc.com/threads/19228...4024#post44024)
    • Finally, if you have a regulated 3.3v source, you can hook it up to the 3 3.3v pins. You likely do not want other power sources in this case.


    The Teensy LC (and ancient 3.0 and forthcoming 3.5) are not 5v tolerant in any fashion. Apply 5v to any of the pins except for VIN/VUSB, you likely will fry your chip.

    <edit>, I mixed up the 3.5/3.6 -- I have fixed it now, but originally it was wrong.</edit>

    The Teensy 3.1/3.2 (and forthcoming 3.5) are 5v tolerant under certain conditions:
    • Digital input pins (0..33 on the Teensy 3.1/3.2) are 5v tolerant, and 5v will register HIGH;
    • Digital output pins (0..33 on the Teensy 3.1/3.2) always deliver 3.3v output. If you have a 5v device, it might not register that your pin was high if it sees 3.3v instead of 5v. It depends on the device;
    • Analog input pins that can also be digital input/output pins (A0..A9, A15..A20) can accept 3.3v up to 5v inputs, but anything over 3.3v will register as 3.3v;
    • Analog input pins(A10-A14 on the Teensy 3.1/3.2) will only accept 3.3v input, and if you deliver more than 3.3v, you may damage the Teensy;
    • The Program pin and reset pad can only accept up to 3.3v (since these are normally connected to ground if you want to program/reset the Teensy, you normally don't feed them voltage);
    • The Vbattery pin on the 3.1/3.2 is used to power the real time clock when the main Teensy is not powered, and it is meant to be attached with a 3v coin battery. I don't know if the pin can accept 3.3v input, or if it is spec'ed to be just 3v;
    • For the 3.5, the same essential rules apply, pins that can be digital pins are tolerant to 5v, but analog input only pins are restricted to 3.3v;
    • The Teensy 3.6 is not tolerant of 5v, except for the power input pins: VIN and Vusb.
    Last edited by MichaelMeissner; 09-19-2016 at 04:45 PM.

  7. #7
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,938
    You don't want 5V power on the pots since with a Teensy 3.x your ADC range is from 3.3 to 0. And non 5V safe pins will go bang into the bargain as noted above. With powering the multiplexers the trick is that they are not magic devices that swap wires in isolation like a relay would. They are a solid state device that has all channels connected all the time, and include FETS that control which input has majority control of the output. By running it on 5V you get a much more range of control between a channel 'off' and 'on' so get a better signal at the output. Something you may want to consider is spending some time on the data sheet and online references of your choice getting to grips with what transistors do, and what these terms work out to in the messy real world where your multiplexer will be producing a mixture of all it's inputs (but hopefully 99% the one you want if you have designed things right).

    The Common out of the multiplexer goes to the Teensy ADC pin you are using, and you have 3 or more digital outs controlling which channel is being passed through (which is also happening inside the Teensy, there are two physical ADCs that get connected to pins as required).

    An option when working out how many multiplexers you need is to use multiple Teensies to digitise your inputs and stream them as digital to a master device. This is more complex in code than just having a massive bank of multiplexors and indexing through them but will be much faster to build, since you can break the job into small chunks, and don't have wires running everywhere.

  8. #8
    Thank you all again. I feel dumb but all is clear except the apparently obvious to you. If I power the mux with 5v its analog output to the teensy will also range from 0 to 5v or will it wipe through the values of its analog inputs which will range from 0 to 3.3 (assuming I'm powering the pots from 3.3v)? Also, I feel (maybe stupidly), that I shouldn't power the mux with 5v and the pots with 3.3v but perhaps they are indeed separate circuits. The data sheet is here and they do explicitly make the example where everything is powered 3.3v at page 19!

    http://www.ti.com/lit/ds/symlink/cd4051b.pdf

    Thanks all again.

  9. #9
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    4,027
    Assuming it works at 3.3v with a total power load of 250mA or smaller, you should power the mux and the analog sensors with 3.3v from the Teensy, not 5v external power.

  10. #10
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,606
    @MichaelMeissner: Haven't you got the 3.5 and 3.6 switched around? The 3.6 is not 5V tolerant. The 3.5 is.

    Pete

  11. #11
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,907
    Quote Originally Posted by MichaelMeissner View Post
    Teensy's run at 3.3v. I didn't see whether you were using either the LC or the Teensy 3.2 (I'll ignore the 3.0/3.1).

    The Teensy LC (and ancient 3.0 and forthcoming 3.5) are not 5v tolerant in any fashion. Apply 5v to any of the pins except for VIN/VUSB, you likely will fry your chip.
    [*] For the 3.6, the same essential rules apply, pins that can be digital pins are tolerant to 5v, but analog input only pins are restricted to 3.3v.
    Opps?

    T_3.5 is FIVE VOLT tolerant on Digital pins.

    T_3.6 except for VIN is not 5 V tolerant.

    Of course the T_3.1 has only a current supply change - increased for the T_3.2

  12. #12
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    4,027
    Quote Originally Posted by defragster View Post
    Opps?

    T_3.5 is FIVE VOLT tolerant on Digital pins.

    T_3.6 except for VIN is not 5 V tolerant.

    Of course the T_3.1 has only a current supply change - increased for the T_3.2
    Yeah, I mixed up the 3.5 and the 3.6. The 3.6 is NOT 5v tolerant, the 3.5 is 5v tolerant (but it does not have touch sensing or the 2nd USB).

  13. #13
    Just for future reference (I guess for myself), it doesn't matter what you feed to the mux, with that power it only operates the logics probably. I am noticing (writing as I test) a better behaviour if fed 5v, mainly it does make analogreads reach 0 with no special software trick. Again the voltage output from the main in/out is the same as what it gets in from the different analog inputs.
    Might have invented the wheel but if anybody as dumb as me sees this it's the answer I was looking for.
    Last edited by apoikos; 09-19-2016 at 06:09 PM.

  14. #14
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,402
    Quote Originally Posted by apoikos View Post
    1. the recommended impedance for linear potentiometers is 10k ohms. Higher values add precision but more noise, lower values have less noise but less precision. Right or wrong?
    Higher values add precision? Is this correct in any sense? (I've not noticed it contradicted above.)

    Higher values limit current draw but the signal to noise is lower as the signal is lower but the noise is (mostly) the same... thereby lowering their potential resolution (=precision).

    Lower values use more current but produce less noisy output...

    That's been my understanding ...is there a reason higher resistance would support higher resolution (even in the absence of external noise)?

    I think it should be noted that the resolution drop from the ADC (even when at 10 bits) to the 7 bits for (most) MIDI uses gives a lot of leeway when you don't do things 'correctly'.

  15. #15
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,402
    On point eight ...add a low pass only if necessary. Just adding a cap turns the pot into a variable filter.

    But mostly you don't want to filter unless you need to and for a mux'd signal you either have to wait MUCH longer for cap to charge/discharge to the new level after a pin change or have individual filters on the pot side of the mux.

    There is the option of software filters but I don't think there's a how-to anywhere on this forum.

    A good hysteresis method is usually all that's needed to limit new errant messages in your midi send caused by noise in the last bit or two.
    Last edited by oddson; 09-20-2016 at 04:56 AM. Reason: Added last point

  16. #16
    So far, don't know why, I noticed no impact whatsoever using any value of capacitor.

  17. #17
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,907
    The capacitor would affect the rate of change seen in the value - not the range of the value seen once it stabilizes right? With no cap a full range rotation and back will track the value differently/faster than with a cap of any size.

  18. #18
    Quote Originally Posted by defragster View Post
    The capacitor would affect the rate of change seen in the value - not the range of the value seen once it stabilizes right? With no cap a full range rotation and back will track the value differently/faster than with a cap of any size.
    I thought that because it stabilises the voltage you get a slower rate yet less jittery output, and that would positively influence the output in combination with analogReadAveraging(). What I saw is that with analogReadAveraging() the capped or not capped results are the the same, although I haven't really tested every (value).
    Perhaps it is useful as it makes the software make less calculations?

  19. #19
    Junior Member
    Join Date
    Jul 2016
    Posts
    19
    2. midi can be 14 bits, depending on the message (nrpns, pitch), possibly more if you're using sysex in an obscure way.

  20. #20
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,907
    Quote Originally Posted by apoikos View Post
    I thought that because it stabilises the voltage you get a slower rate yet less jittery output, and that would positively influence the output in combination with analogReadAveraging(). What I saw is that with analogReadAveraging() the capped or not capped results are the the same, although I haven't really tested every (value).
    Perhaps it is useful as it makes the software make less calculations?
    That was just my assumption - to test - turn off the Averaging and run it back and forth showing the sampled value over the half second it takes to twist the knob over and back. Watch for the peak value and rate of change? With averaging on the same will be true - but harder to see?

  21. #21
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,402
    Quote Originally Posted by apoikos View Post
    So far, don't know why, I noticed no impact whatsoever using any value of capacitor.
    My guess is its because it's not needed.
    Have you tried serial.print () to see the raw output from the adc?

    If there's little noise then the only difference from adding an analog low pass will be an infinitesimal lag on large and fast changes from the voltage divider. You're unlikely to notice this unless the cutoff from the low pass is VERY low (<30Hz), i.e. the R*C or time constant is huge.
    Last edited by oddson; 09-20-2016 at 01:35 PM.

  22. #22
    Since this seems interesting and somewhat unclear/untested throughout the forum, as soon as I'll get the chance I'll test 1000 cycles per each analogReadAveraging() value with and without different caps and post the results back here (as stdev and average I suppose). Might be useful for future reference. Anyone has any suggestion on where the wiper produces more jitter? I tend to think in the middle, don't know why.

  23. #23
    Quote Originally Posted by Reggie View Post
    2. midi can be 14 bits, depending on the message (nrpns, pitch), possibly more if you're using sysex in an obscure way.
    I didn't think about that. You are so right. I am therefore completely lost on how they can reliably produce these pitch wheels (which luckily is not my objective), I mean, I can't even imagine that level of precision coming from the teensy ADC

  24. #24
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,402
    Pitch wheels don't really give 14 bits of precision and many don't even output on the fine scale.

    If they did, to change only the last bit you have to be able to rotate the knob by a couple hundredths of a degree.

    I think most devices interpolate pitchbend changes to avoid zippering.

    But if you were trying for greater precision then you'd need to be much more careful both in taming the signal and avoiding extraneous messages flooding out of your controller.

  25. #25
    Junior Member
    Join Date
    Jul 2016
    Posts
    19
    Quote Originally Posted by apoikos View Post
    I didn't think about that. You are so right. I am therefore completely lost on how they can reliably produce these pitch wheels (which luckily is not my objective), I mean, I can't even imagine that level of precision coming from the teensy ADC
    Probably not worth worrying about so much, most of the 'big players' in the game fudge it like using 10bits and some bit shifting or allow you to change things so the precision is better over a smaller range, 14bits is the upper limit, you can of course use less bits than that if you want. Don't forget, midi is digital, so it's not really important whether you can address all of the bits in analogue, you can just use 2 buttons (or a rotary encoder) and have access to the full range of 14bits.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •