• Sidequest: Signal Acquisition

    HummusPrince07/15/2020 at 20:01 0 comments

    The next experiments would be quite rich with analog signal measurements. Thus I needed a better way to display and analyze waveforms with my toy-scope.

    There's an open source firmware for the DSO-138. Although it seems inferior to the original FW, it prints the acquired data through the serial port by feature, so iv'e gone with it.

    The guide for firmware update requires shorting some jumpers, but I want more control so I can switch FW at any point with minimal effort. It came out like this:

    To go into UART bootloader I simply toggle the 2 switches and reset the device.

    To acquire and display it all I made a little python script, which can be found in my github.

    The resulting graphs really make visibility much much better - now I know how much info is lost for the tiny display.

    Let us measure the negative voltage generator of the DSO itself, as it's waveform is quite rich in detail.

    This:

    turn into this:

    With zoom:

    So much details can be suddenly observed. This will be helpful in the next steps.

  • Why no one like inductors

    HummusPrince07/04/2020 at 00:10 0 comments

    Before doing anything fancy, I must build something that oscillates at some frequency that depends on the value of my passives. For resistance and capacitance, it seems as if using the RC characteristics of them in series would be the simplest way.

    This means building some sort of an astable multivibrator. The famous 555 timer might do, but foreshadowing on my side (knowing my next steps considered as cheating?) got me using op amp circuits directly.

    Explaining op amps is out of my scope here. If you don't know what they are, consider going through some tutorial - Google seem to give decent results for "op amp tutorial". Anyway, suffice is to say that opamp for analog are kinda what arduino is for embedded - By using them you can concentrate on the operation of your circuit, while skipping many horrible non-idealities that usual devices have (input/output impedances, gain levels, nonlinearities). You'll pay penalties in performance and other stuff for this.

    For opamp I'm going to use some LM324 I desoldered from a dead UPS. This is quite a standard opamp for simple, low frequency applications. Each package has 4 identical opamps, and given that I don't expect anything above 100kHz, this seems to do the job.

    You might wonder what that circuit does:

    R3, R3' and R4 make an inverting Schmitt-trigger together. As I use a single supply, I want it to work around Vcc/2, which are generated by R3 and R3', which by Thevenin's theorem are equivalent to a Vcc/2 voltage source with resistance of R3||R3' = 5kOhm = 1/2*R4.

    It means that the output will be Vcc until the negative terminal of the opamp is brought to 2/3*Vcc, at which the output would switch to 0 until the negative terminal is brought to 1/3*Vcc.

    The upper branch with R and C is a typical RC series circuit. When the output is Vcc, the capacitor C gets charged through the resistor R, and when output is 0 it is decharged.

    Due to the inverting nature of this certain Schmitt trigger, it means that it's going to oscillate. It can be shown that this circuit gives a square wave with duty cycle of 50% and frequency:

    I built it and it worked quite flawlessly. The frequency was not accurate, and I suspected that it's because this opamp is not rail-to-rail, thus altering the 2ln(2) factor. Taking that into account gave very accurate results.

    This circuit is very simple and well studied - tons of information can be found on the web. This will be the basic topology for my oscillators.


    Theoretically, replacing the RC circuit with an LR one should do the exact same job, as the feedback coefficient of the negative terminal remains the same, but with L/R instead of RC this time:

    This should oscillate with

    This is awesome - the frequency is proportional to the resistance!

    However, there are problems.

    The first problem I've encountered was practical: for a reasonable inductance, say 1mH, one needs to use very small R: for 10kHz, which is the largest that my counter can get without prescaling, one gets R~14Ohm. That's plain tiny - it's hard to find resistors in this range, but more important is that it'll take huge amounts of power, which the opamp won't ever be able to supply.

    Prescaling by 100 requires 1.4kOhm, so you might thought that it would work. However, it pushes the opamp to it's limits, oscillating at 1MHz. Also, for smaller inductors this would still be a no-go.

    To be able to study it properly, I need a big coil, preferably about 1H. Just like this guy:

    I think that it used to be a clutch coil of an A/C compressor. It's quite enormous, I think it gets to 1H.

    The oscillator works with it quite well:

    However there are some noticeable quirks:

    First and foremost, the waveform look funky. It's not so square and has a noticable ramp. Also it has this extra bump while output is low. I suspect that the bump is a voltage spike on the inductor that is discharged through the LM324 protection diodes.

    Another thing is the minimal...

    Read more »

  • My analog adventure begins

    HummusPrince06/27/2020 at 21:42 0 comments

    So now that I have a proper frequency meter, I want to use it to measure electrical resistance, capacitance and inductance. The natural path to take is to make some oscillating circuit whose frequency is proportional to the values we want to measure.

    Alas, this seems like a problem - Traditional RC circuits has their frequency inversely proportional to both capacitance and resistance:

    With the less popular RL circuits, this is somewhat better, with frequency proportional to the resistance and inverse to the inductance: 

    Hence naively using my frequency meter, I can get, maybe, a circuit that measures resistance only, and requires using one of these bulky inductors, which probably would be a pain to work with.


    It seems, if so, that physics and human conventions for electrical quantities put me in a difficult position for this project - how could I measure these values using my frequency meter?

    I was able to come up with 4 possible solutions:

    1. Leave it as is, measuring the inverse of these quantities - that is, measure admittance rather than impedance.
    2. Add some digital circuit which can invert the admittance into impedance, displaying these wanted values on the display.
    3. Switch the meter's input and latch signals, effectively measuring the period rather than the frequency generated, which should be proportional to the relevant electrical quantities.
    4. Use some analog wizardry to effectively invert the impedance measured.

    The first one is a no-go: Nobody uses such quantities, we all use the old LCR values - not their inverse. To use conventional units, I'd have to use a calculator whenever I measure these values, making the device plain stupid.

    The second solution won't do either - It's almost like saying that it can't be achieved without some computing. Was it so, I'd rather put there an MCU to begin with and call it a day, and that would be lame.

    The third option might seem appealing, yet it has some drawbacks:

    • First and foremost, it means that I must be able to alter the counter control somehow. It complicates the design, forcing me to add more parts in, and making the frequency meter function itself a one trick pony.
    • Second, it makes the display refresh rate dependent on the component measured. This can lead to funky behavior - For periods very small the display will frantically refresh itself bazillion times a second, and for periods too long it would take ages to refresh. While this can be solved, it would mean once again complicating the control circuit significantly.
    • Last one concerns with user control of the device. I thought about simple switches for configuring the device parameters, such as value ranges (nF-uF-mF for example). The complicated control required for this solution might mean using exotic switches with many terminals, which I don't own and do not intend to - or rather add more control circuitry to translate simple switches to complicated sets of parameters.

    I'm less then keen to walk into this sort of electrical swamp, more so when the result is so non-elegant.

    Thus, it seems, the first route to pick is the route of analog wizardry. Wizards back in the analog days had plenty of cool tricks up their sleeves, and I'm sure that there's some trick for, say, effectively inverting the impedance of some component, thus solving all of my problems in an elegant manner.

    I am, however, not an analog wizard. Despite being sent to a wizard school, my knowledge is rather rudimentary and my experience dull. To accomplish, I'll have to learn some new analog spells and trick, and maybe capture and train some analog dragons.

    Will analog wizardry save the day? Time will tell.

    Let the analog adventure begin :D

  • Counting frequency, Precisely

    HummusPrince06/13/2020 at 14:38 0 comments

    The frequency meter concept was proved, but there are some flaws. Most of these relate to the poor oscillator used for the time base. It's frequency fluctuate depending on supply voltage, temperature, residual capacitance from the environment (breadboard?), weak coupling to other signals nearby (mains 50Hz) and more.

    Luckily, there's a solution for that. Quartz crystal resonators are free from most of these flaws, and I have lying here some 32.768kHz xtals. These are very accurate, and 32768 is 2^15, thus easily divided using the CD4060. They are also high impedance (10s of kOhms), and thus very power-efficient. This is also why they are super popular and used in virtually every watch and wall-mounted-clock.

    CD4060's datasheet recommends using a crystal with a regular parallel resonant configuration:

    However, these low frequency crystals can be quite pesky to drive. Their high impedance makes them more difficult to get working correctly, and the passive components must be from specific value ranges. A good overview of driving low-frequency crystals can be found in this NXP appnote (AN2606).

    My crystals were scavenged, probably detached from some dead product long time ago. As I don't the recommended values for the passives, I had to play with the values until I got it to work:

    Measuring at Q4 of the CD4060 you get the clean 2048Hz expected. Good one.

    Quadrupling the clock from 8192 to 32768 means that the lowest frequency I get from the CD4060 is 2Hz. Not good enough, as I need 1Hz. Thus I decided to use another CD4017 as another divider (I had no flipflops lying around).

    Lets see if the modded circuit works:

    Measuring the frequency of Q4 in the CD4060 you see 2048 = 2^11 as expected.

    Measuring the clock itself. One will expect to see 32768 ticks - which are 1 second - plus an extra tick for the latch control signal to go high. When reaching 10,000 the counter should overflow and begin counting from 0 once again, and this should happen 3 times each second for that signal, and you'll be left with 2768 + 1. That's exactly what I get, so it must be good to go, logic wise.

    Like last time, it still does no ensure accuracy. Lets compare it with my chinese pal:

    The 1kHz calibration signal of the toyscope looks very good on the counter.

    Here is a signal generated using a not-so-stable 555 astable timer (seen on the right side of the breadboard). The toyscope and the counter agree very well.

    I decided to add a X10 and X100 prescaler. Using another CD4518 to divide the input signal by both ratios seemed only logical.

    This is the resulting circuit:

    On the breadboard I've omitted the capacitors altogether, but when I'll put it all on a protoboard I'll probably add these. The oscillator probably is working good due to high parasitic capacitance in the breadboard, and when assembling I might choose for the caps different value than what's on the schematic.

    The prescaler works well too:

    100kHz is the highest value to which I credit the chinascope's frequency measurement - higher than that and the readings fluctuate drastically. Above that I'd rather believe my own device, measuring up to 1MHz :)

  • Counting frequency, approximately

    HummusPrince06/06/2020 at 19:21 0 comments

    Now that I can count, I want a prove of concept for a frequency meter. It only has to measure frequencies up to 10khz, with reasonable accuracy (say 10%) and reasonable refresh rate (say 1 second). How could I do it?

    Lets consider the counter/display module. I want to feed it with a signal source of certain frequency, and enable counting all the time. Once every second, I want to latch the counter value into the display, and right after it to reset it. so it can begin to count again.

    Looking at the control signals of the module, it should look thus:

    Time to build a circuit that can do it. I want to base it around the popular CD4060B binary counter with in-built oscillator circuit. At first the oscillator will be of the cheap and grossly-unstable RC type, where I chosen Rx=Rs=1MOhms and Cx=33pF.

    By sheer luck, it gave a frequency surprisingly close to 8192Hz. The datasheet supposes that the frequency to be expected is more like 13.77KHz, so it's either that the cap is actually 51pF - which fits precisely with 8192Hz - or that the too low value of Rs (should be at least 2 times Rx) alters the circuit properties.

    8192Hz is awesome as it's power of 2. It means that the counter generates a timebase very close to 1 second!

    Now that I have a timebase, I want to use it to generate these signals. I decided to use the famous CD4017 decade counter to generate these. It will be fed from the 8192Hz signal as it's clock, and Q14 of the decade counter whose frequency is 0.5Hz will be it's enable signal. Once a second has passed, Q14 will raise and the CD4017 will begin counting. Thus I'll connect it's Q1 to the #LE signal (through an inverter), it's Q2 to the display RST, and Q3 to the CD4060's reset and it's own reset too.

    The circuit look thus:

    R3 and C2 should make sure that the CD4017 won't reset before the CD4060 was reset. While the circuit dysfunction without R2, C3 seems optional.

    This is how the thing looks like on a breadboard:

    Notice the very perfect value on the 7segs. It's no magic - this is the circuit when counting it's own clock. The expected value is 8193±1 : 8192 clocks until the CD4017 is enabled, plus 1 clock for the value to be latched - Give or take 1 as the counter value might get latched before or after the clock has incremented the CD4017 once again.

    Thus, the image above is a good indication that the circuit logic is as expected, though no indication for timebase accuracy.

    So how does it fare in frequency counting? Surprisingly good, IMHO. Compare the display value of some random square wave with the estimated frequency that my very chinese toy "scope" is showing.

    Given one believes the little Chinese pal (I do), the meter is accurate to about 1%. This is about the deviation of the RC oscillator itself from 8192Hz.

    I'll take that as a successful prove of concept.

    Edit [13/06/2020]: Minor corrections for the schematic.

  • Counting to 10 thousand

    HummusPrince05/31/2020 at 22:11 0 comments

    I want to display at least 3 digits of the frequency or other value that I measure. Each CD4518 contains two BCD counters, so it makes sense to make a 4 digit counter rather than leaving one counter unutilized for the same price.

    The design is based on cascading the 4 counters, in such a way that when one of them overflow the next one will increment. I went with the simple design in the datasheet, using Q4 falling edge as the next timer increment. Because I wanted to disable all counters together I used their CLOCK input as an inverted ENABLE, and the ENABLE as falling edge CLOCK.

    In retrospective, I could have gone with this recommended design, as only the less-significant-digit counter must be disabled to stop to rest too. But meh, I've already tied them up together. Maybe if I'll make a PCB revision of this thing I'll do it in this more senseful way.

    As for display, I've gone the lazy way - each 7seg is getting it's own CD4511 to drive hoe directly from his respectful counter. I'm not going for the complexity of multiplexing the 4 7-segments with only one CD4511, thank you very much. It would be a pain and will also use at least the same number of chips and work as the lazy approach. This approach might be reasonable for an 8 (or more) digit counter, which isn't practical anyway.

    So, I can count to 10. Now I want to count further, from 0 to 9999. 

    Together with the four 7 segment LEDs, and the 4 CD4511 chips driving them, the whole design fits very well into my el-cheapo 18X24 holes protoboard.

    As this design is quite modular, at first I've assembled and connected only the 2 lower digits, and used the previous test circuit to test the counter.

    You can see that it was working quite well, though I found a weak solder-joint I made between one of the 4518s and it's 4511, resulting in wrong display value.

    It was also the time to see what value the series resistor of each 7seg will be - I'm lazy and won't use 7 input resistors for each individual LED to celebrate the marginally-better-looking result. That's what the crocodile wires are for. I've decided that 330 Ohms will suffice.

    I took out each of the important signals into the female headers. These are the Vdd and Gnd of course, the ENABLE, CLOCK and RESET of the counters, and the Light-Test, Blnking and Input-latch of the 7seg drivers. Also I left 4 pins for each of the decimal points, to be used in the future to indicate resolution.

    At last I wired the second half of the circuit. I let it count some random value, and it has worked very well. Here is the the counter when disabled mid-counting: 

    That's very cool in my opinion, I've hardly believed it will work that well and require no bugfixes.

    As to how it was all assembled, well, it was quite annoying to make:

     Worry not, all these are enameled 0.1mm wires (these cheap aliexpress jobbies), - so no accidental shorts, even despite the cheap materials and sloppy soldering job.

  • Counting to 10

    HummusPrince05/31/2020 at 13:35 0 comments

    The heart of this project is the counter/display.

    This module is based on CD4518 BCD counters. These really only count from 0 to 9, where each digit is represented with it's standard BCD nibble. The counter increments with rising edge of one input, or falling edge of the other (These are clock and enable pins). It's zeroed when at overflow or when the reset pin is pulled high. Each chip has 2 of these.

    And really that's it. There's not much more to it. See for yourself in the datasheet.

    But I wanted to use 7-segment LED display. I must convert the 4-bit bcd somehow. I decided to use a converter chip, named CD4511. It's no more than combinatorial logic with a latched inputs. See for yourself too.

    I want to prove that I can count from 0 to 9 (you can call it counting to 10) and display it on a 7 segment display.

    So I built a basic circuit which consists of one CD4060 (to generate a clock), one CD4518 which counts to 10 and one CD4511 to light a 7-segment display accordingly.

    The thing has worked very nicely - I can count to 10 :)