Show by Label

Sunday, September 1, 2019

Upgrading & Tuning my FY6600/6900 Waveform Generator

My FY6600 recently died on me. RIP

More and more waveforms turned out as corrupted and no matter what I tried, even "repairing" with the PC software did not do anything. The fact that I could not repair the waveforms in the flash memory may have been caused by my very early firmware version. 

In the end, after researching all the available instruments in the below $500 price range, I purchased a FY6900 as the replacement.

This is a major improvement from the the FY6600 I have used for many years, so I'm actually very happy with that Function Generator. 

For details about what I did with the FY6600, look further below.


FY6900 Modifications

One modification I did was to un-solder the ground lead to the Earth pin of the mains receptacle, and soldered a 1K 1/4W resistor in between. This still keeps the AC levels on the BNC's to about 150mV AC when floating, but breaks the hard ground loop to Earth ground.

This unit has a 10MHz oscillator, so using an external 10MHz reference is now fairly simple. I wanted to preserve the original oscillator, just in case, so I added a switch. 

Warning!
Keep in mind that you need to switch between the internal or the external clock when the system is powerless, not on stand-by!, otherwise strange things may happen. Consider that the 10Mhz clock is also used for the CPU so unexpected things can happen like messing with the on-board flash memory!

I added an SMA connector to the back-panel as an input for the 10MHz and also added an SPST switch next to it. I de-soldered the oscillator from the board with my heat gun, while using some Kaptan tape to protect the surrounding parts from de-soldering or worse, flying away.

I then flipped the oscillator on it's side and resoldered pads 1 and 4 to the pads on the PCB. These two pads are for the 3V3 power inputs for the oscillator. I used a small wire to connect the GND pad of the PCB to the GND pad on the oscillator, pad 2. The output pad on the oscillator, pad 3 went to the switch on the back-panel. 

The SMD connector braided center wire was soldered via a 10nF capacitor to the switch.  The ground of the braided cable went with a thin wire to the GND pad on the PCB where also the GND pad of the oscillator is connected.

The center pin from the switch went to the output pad on the PCB. I used a normal thin wire, I didn't think it needed a braided cable.

 I later marked the backplate to show the position I for internal and E for external. 

Here are some pictures of what I did.







You just about see a (loading) resistor at the switch next to the capacitor, that was removed after testing.

After soldering, I thoroughly cleaned the oscillator area from solder flux.

The GPSDO output is a 2Vpp square wave, the internal oscillator has a 3V3 level output, the FY6900 didn't really care, it still worked well with both inputs.

Before I discarded the dead FY6600, I took the better Opamps that I installed out of it, but did not bother to install them into the FY6900 yet. When I really need better fidelity at higher output voltages, I may still do that. I also didn't see the need to install a fan.


==============================================================

FY6600 upgrades and modifications 

For a while, I had contemplated to upgrade my FeelTech FY6600-30MHz Dual Channel Waveform Generator.


This is a very interesting instrument that has specifications that would be comparable to instruments hundreds of Euro's more expensive. Unfortunately, the manufacturer of the design took some short-cuts to penny-pinch some more profit out of the device, and that causes some problems and degrades the instrument.

Initially I didn't care too much, the instrument performed very well for me, but when I started to dig into high precision oscillators and the likes, see my other posts, I needed a higher precision counter function. This can be rather easily done by replacing the main oscillator but I also wanted to see what other people did and what else was possible.

There is a huge number of postings about this instrument on this blog : eevblog.com , after reading through all of them (yes really - it took me three days) I decided to tackle the three most important issues.

These are four main issues reported by the many users on the forum.

  1. A very poor (el cheapo) switching power supply with no earth ground. This could put an AC voltage as high as 1/2 of the main voltage on the BNC outputs. The current is very little though, and is caused by the leakage of a capacitor, but still.
  2. Distortion of the waveforms at higher amplitudes. This is caused by the selection of rather inexpensive and older design opamps. Interestingly, there are provisions on the PCB to install much better opamps.
  3. A rather poor main oscillator with poor precision and significant drift. The drift is mainly caused by the fact that the oscillator is way too close to three voltage regulators that get pretty hot.
  4. The 20dB attenuation circuit in the output section for output voltages above 5V has incorrect resistor values.


4. The attenuation issue
At this moment I'm not going to address that problem.

3. The oscillator
The recommended replacement oscillator for the CTS 50MHz 50ppm CB3 version (some instruments have the SM77H) is the model D75J from Connor Winfield. This is a surface mount temperature compensated crystal controller oscillator (TCXO) in the 50Mhz version, calibrated at 25 degrees to 1ppm and a stability of 2ppm. Incredible precision and stability! Because the D75J is a temperature controlled oscillator, the effects of the nearby regulators are pretty much eliminated. This is especially important if you use the FY as a counter.

To reduce some heat hot-spots from the three on-board regulators near the oscillator, I added two small "sticky tape" heat-sinks (Raspberry Pi type) on top of the three regulators. The temperature of the heat-sinks after more than two hours is now about 46 degrees C, and more evenly spread.

After I installed the new TCXO, I measured the precision against a calibrated oscillator.  I measured the frequency of this oscillator to be 5,000,001.7 Hz. This is very close to the calibrated value of 5,000,002.1 Hz, but that factory calibration was eons ago, although the oscillator was never used until very recently (see my other post: Frequency Generator with Fast Edges). Either way, that is a remarkable precision and the reading over a few hours only changed 0.1Hz. The heating of the temperature inside the FY enclosure no longer seems to have an effect. The next step is to measure the result with a GPS Disciplined Oscillator (GPSDO), a project I'm currently working on.

2. The opamps
I replaced the single dual output amplifier with two single THS3095 opamps. I also increased the +/- 12V supplies to +/- 15V to give them more headroom. The performance at higher output voltages and at higher frequencies is now much improved. Still not great, but much better, at least worth the small investment and trouble to do this. The best performance is still with 5V p-p and lower output voltages. I wonder what the higher frequency models actually deliver, if mine at 30MHz is already very poor.

1. The power supply
The power supply has been talked about many times on the forum, with several options offered, but there are only a few examples for a replacement.  I decided to design a completely new supply, that would let me adjust the +/- 12V outputs to +/-15V as well. The new output Opamps need this voltage to display the wave forms without distortion at the maximum output.

Going through my parts collection, I picked a 24VA block transformer that could be mounted on a protoboard. The transformer is a little too heavy (in VA) with 2 separate winding's of 12VA each, and an output of 15VAC. Both secondary winding's are fused with 0.8AT PTC fuses. The primary has two separate 115V winding's. Because there are separate windings, I took advantage of that feature, and while experimenting while building, I created two separate supplies with a full bridges on either one to keep all my options open. This dual bridge is not really needed, but diodes are cheap and you can avoid ground problems (using a star ground), especially easy to do when you are using perf- or protoboard instead of  a real PCB layout. They are needed when you decide to use switched inverters and using a positive one for the negative side. I tied the supplies together at the connector going to the main board, not anywhere else. 

Because there is no separate winding for the 5V supply, I needed to tap that from one of the 12V supplies. Due to that, I also wanted to avoid the inevitable switching noise coming from the 5V DC-DC regulator going back into to the 12V supply as much as possible. Using a DC-DC switching regulator for the 5V supply poses no issue because this supply is further regulated on the main board to create the 1V2, 1V5 and 3V3 supplies for the digital components. The +/- 12V supplies are used to power the analog side with the Opamps for the output section. Any noise on the 12V rails can make it to the output signal. After measuring the final results, I added another 330nH inductor to the plus input of the DC-DC convertor, to prevent more switch noise from being injected back into the 12V supply. This added inductor is not shown on the circuit diagram below.

The weight of the transformer will prevent the instrument from sliding as much, because the instrument was so light before, a bonus.

I decided to use the LM317 and LM337 voltage regulators for both the +/- 12..15V analog supplies. The only specialty in this circuit  is around the 10-turn trimmers, because they are China quality, and therefore cannot really be relied upon. The worst case is when the runner looses contact, creating a much higher output voltage than you intended, and this could potentially blow up the output amplifiers of the FY6600. The way I selected the adjustment components is such that you can get just below 12V and just above 15V. Depending on the tolerances of your 317 and the 337, (which are notorious), you may have to adjust a resistor value here and there. I bread-boarded the circuits before I mounted them, just to be sure.

For the +5V supply used for the digital circuits, I selected a simple DC-DC Buck convertor because doing that with normal linear regulators would create too much heat (burning off the difference between approx. 20V and 5V at 500mA). I did not want to add a fan, with all it's generated high frequency switching noise inside the box. I also reused some parts from the old supply, specifically the line filter and the 5V choke.

My unit is intentionally still floating. This can be fixed easily with a BNC/USB connection to another earth grounded instrument. If I change my mind, I can still add a 4mm connector to the back, tie that to the power ground and make a connection to earth ground with a test lead that way. Or, change the two-prong AC connector to the 3-prong version.

Here is my design:



And here is the unit with the supply installed:



Just above the upper left hand corner of the transformer, you can see the two little heat-sinks I used on top of the three regulators to disperse their heat. Just above it you can see the metal can oscillator that I'm going to replace. The person that did the layout of the board had no clue as to the heat effect of the regulators on the stability and precision of the oscillator. 👿

I did not have room on the protoboard for the DC-DC convertor, so I used double sided sticky tape to put it on top of the transformer and moved it away from the analog section of the main board. These DC-DC devices are notorious for their switching noise superimposed on the output voltage. Using the 10uH inductor from the old supply and a few capacitors on the output reduced the 25mV ripple at about 1MHz to about 7mV, which should be OK.

When I started the testing, I had to resort to a little kludge because the heat-sink I used was too small. In hindsight, I should have used two separate and larger heat-sinks. Doing that now would cause some major and ugly surgery. Bolting another one on it is now better with the supplies at +/- 12V, it will be significantly cooler when I change them to +/- 15V. (less of a voltage drop over the regulators) At +/- 12V, the heat-sink is now just below 50 degrees C. After more than two hours, the temperature inside the case is about 35 degrees C, at a room temperature of 27 degrees C, which is a bit warmer than I like but fine for now.

After I raised the +/- 12V supplies to +/ 15V to give the output amps more headroom, the reduced voltage drop over the regulators decreased so much that the extra heat-sink kludge is no longer needed.

With all the mods done, I'm happy with the results.

I am actually most impressed with the precision of the counter function now. With my GPSDO now fully operating, I could finally measure the actual precision. When I measure the 10MHz output of the GPSDO, the counter with a gate of 10 sec. gives a result that is exactly 1 Hz too low. (9.999.999.00 MHz) Not a bad result at all for these modifications. It takes about 15-30 minutes of warm-up time to reach the highest precision.

 

UPDATE : January 5th, 2021

Using a GPSDO as the master clock

Now that my GPSDO project is finally coming to a conclusion, it is time to start to use that as the master clock for the FY6600, something I had planned all along. It took along time to get that project finished, you can follow that on other post on this Blog.

The trick to use the 10 MHz GPSDO is that you need to multiply the 10 MHz 5x to get to the required 50 MHz for the master clock. At the same time, I wanted to allow myself to use the FY6600 with the updated OCXO as well as the GPSDO. I designed a circuit and build a PCB for that Clock Generation circuit. There are a few gotchas to worry about so I made some provisions to experiment with the circuit, just in case. The major issues I expect to have is with the 50 MHz clocks and the selection gates. They may not be fast enough. I could not prototype this with these parts so I will need to build the circuit on the PCB.

Here is the schematic I'm working from.

The circuit is pretty simple. Top left is the SMA connector where the 10MHz from the GPSDO comes in. It goes through a buffer and then to the PLL that is set for a 5x multiplier. In the bottom half, you see the new place for the D75J that I need to lift from the FY6600 main PCB. The toggle switch that is shown in the middle will allow me to switch between the two sources. The three gates allow me to select one or the other. The question I have is if the 74HC02 is fast enough for these 50 MHz clock signals. 

I may not even need these gates, because both the PLL and the D75J have disable/enable inputs. They are both connected to the switch as well, so if push comes to shove, I can select either method and hopefully have it working. If I use the enable/disable pins, I may be able to connect both outputs together, without needing the 74AC02. I'm not sure how much they "tri-state" when disabled and if they influence each other.


 


The layout is above. The expert users with eagle eyes will see that I committed to a "cardinal sin" by using two vias between the TCXO and the buffer. The datasheet tells you to avoid that, but I took the easy (lazy) way. Mea Culpa Conner Winfield folks.

The major headache for me was to mount this on the back panel. I did not want to mount it flush to the back-panel, just in case I want to add a fan. I also didn't want to block the few cooling slits in the back.  The method I eventually decided on is a little cumbersome in order to mount it vertically. On the top left hand side of the PCB are the soldering contacts for a very small sliding switch. It just protrudes through one of the cooling slits. The bottom left pads are for an SMA connector. This is actually a male version with a nut, and it will be connected to a male-female panel feed-through SMA connector. The distance to the left is such that the PCB can be mounted vertical and is secured by the feed-through connector. I just need to drill a hole for the feed-through connector on the bottom from one of the slits. 

The solder pads on the right-hand sid 😁e are for the 50 MHz out, GND and the 3V3 supply. These short leads will go to the main PCB of the FY6600 where the original oscillator was mounted before.

I believe starting with the FY6900, it has a 10 MHz master clock, so in that case, you could feed the GPSDO signal straight to that input and you don't need the PLL clock multiplier. A short wire will bridge this device.

If you didn't upgrade the original SM77H or the CTS CB3 oscillator with the D75J, the solder pads on my PCB will not allow you to mount it on the foot print, you have to use three short wires. If I do another turn, I will add a separate footprint. The SM77H also has an enable/disable pin.

I build one board and found that the enable/disable for the PLL chip did not do what I expected. The output is always there. This means that you will have to use the the 74AC02 to switch between one or the other source. The other small issue I had was with the soldering of the D75J on the board. I could not get it to work. The pads for the footprint I designed where too small. I ended up mounting it the same way as I did on the FY6600 main board, by using tiny bend leads that went from the TCXO to the board pads. 

Mounting the PCB in the enclosure went as I expected. I drilled a 6.5mm hole in the bottom of the most left vertical slit to mount the SMA throughput connector. I used the most left hand vertical slot, because that will keep the board out of the way if I decide to add a fan, and the three wires to connect the pads for the TXCO on the main board to the new PCB will be very short.

With that modification, we're just about coming at the end of what can be done to improve this very inexpensive but otherwise great value product for hobbyists.

 

Next steps?

The next step for me will be to order a C6  mains receptacle and a C5 mains cable with an earth ground and properly "ground" the instrument with a 10nF/500V capacitor and in parallel two 1Meg Ohm resistors in series. At that time, I may also replace the 5V DC-DC switching supply board with a switching 7805 equivalent and mount that on the power supply board. If I'm bored and have nothing else to do 😁, I may even design a proper PCB for the power supply.



Enjoy!

If you like what you see, please support me by buying me a coffee: https://www.buymeacoffee.com/M9ouLVXBdw

Friday, August 23, 2019

Frequency Generator with fast edges


This post describes the building of a 20MHz frequency generator with a 1-2-5 frequency selection down to 1 Hz through a rotary decoder. The frequency generator is a stable high precision 5MHz oscillator.  The device also has fast rise (<=1ns) output edges that are generated through a Fast Rise assembly taken from a Tektronix PG506 Calibrator. The PG506 was used by Tektronix engineers to calibrate instruments. I used it extensively in my earlier career at Tek.

[Update:]
When I finished my GPSDO project, described in other post, I made that very precise 10MHz signal available as the master clock for this instrument.


The reason for this design
When I started to investigate the DIY build of a differential probe, see one of my other posts, I needed a fast edge pulse to measure the bandwidth in lieu of using much better equipment that I don't have. I also wanted to have a precise pulse generator with many frequencies, analog to the PG506, to measure and calibrate instruments or help in prototyping circuits.

For about 40 years, I held on to a Fast Rise Board assembly from a PG506 dating back to my time at Tektronix. The unit was defective coming out of a unit that was still under warranty (actually blown up by the user) and could not be repaired without some significant surgery. With some help I was able to fix it. For a long time I wanted to reproduce part of the PG506 Calibrator to test and adjust DMM's and oscilloscopes and although I even had a prototype for the Standard Amplitude amplifier up and running, I never saw the real need to spend some significant money on the required precision parts to finish it.

During this development I already built a PIC-AXE program to control the frequency selection so the time was right to put it all together. The main controller for the instrument is a PIC-AXE 14M2, and I use a second 18M2 controller to serially drive the LCD display. The PIC-AXE chips are very easy to use and are programmed in BASIC. PIX-AXE has a great Software Development Environment (SDE), which I think is even better than the Arduino SDE. http://www.picaxe.com/

Please keep in mind that this is a quick-and-dirty "put together". Dealing with fast pulses with frequencies at 20MHz on proto-board are typically not very forgiving for glitches due to the fast switching of devices, and this is no exception. When (if) I decide to build a final version, I will have to make a proper PCB with power and ground planes and do a much, much better job at decoupling.
[Update: I did build a PCB, read on]

The building process
In any case, if you're interested, here is the design that I put together.

Clock generator

Above is the circuit diagram. Below is a picture of the oscillator I'm using. It's an old unit that was in my parts collection for 40 odd years as well. It was calibrated and measured to deliver 5,000.0021 KHz at 27 degrees Celsius. That's only 2.1ppm by the way.

A clock of 5MHz does not really work well in a 1-2-5 divider sequence, so I used a PLL chip to multiply the 5MHz oscillator output to get a 20MHz clock. The output of the 5MHz oscillator also goes to the front panel through a few buffers.


Because of the constraints of the enclosure, I mounted it upside on the top cover so it's still in the proper position. It's not "ovenized" but encased well to prevent wild ambient temperature fluctuations. The designers must have designed it with certain temperature parameters in mind, so I didn't want to mount it on its side or upside down.



Frequency Selection
The 20Mhz oscillator signal comes in at the top left of this diagram. It is divided by 7 74LS390 decade counters (two per package) into the main frequencies. All the outputs go to an 8-input multiplexer, a 74LS151. The selection of the 8 inputs goes through 3 inputs (A, B and C) and are driven by the controller. The output of the multiplexer then goes through a divider section of two 74LS109 flip-flops that divide the selected frequency through 2 or 4 to get the intended 1-2-5 frequency selection sequence. The divider outputs are selected through three OR-gates, who are also driven by the controller through NOR gates. The output of the OR-section is buffered and goes to the Fast Rise board, and also the the output BNC connector. (one still to-do is to replace U11.6 with the spare F02 and add that F04 gate in parallel to the output buffer section to get a bit more diving capability)

The controller also drives transistor Q1, which is used to activate a small relay. The relay switches the positive and negative power to the Fast Rise board. The Fast Rise board gets very warm when used, and that does not work well with a precision oscillator, so I decided to switch it off when not used, similar to the operation in the PG506. The zener diode is used to lower the 16.5V to the 12V DC for the relay.


CPU Circuit
The main controller circuit is quite simple. On the top left is a stereo connector that is used to program the device in-circuit, through the PIC-AXE USB to serial cable. The main 14M2 controller sends out a serial stream to the display controller, which is an other PIC-AXE controller, a 18M2 version. The main outputs of the 14M2 controller are the ports that drive the mux frequency selection and the /1 /2 and /4 step selection, in addition to driving the power for the Fast Rise board.
The selected settings are transmitted over a serial interface to another PIC-AXE controller on the LCD board section, and that drives the LCD display.
Lastly, the controller also deals with the rotary encoder. Pushing the rotary encoder button toggles the Fast Rise board power. Turning it left or right will select the output frequency.

Display Circuit
The display circuit consists of a PIC-AXE 18M2 controller that takes the serial input data from the main processor and multiplexes that to a typical LCD display. Due to space requirements, I selected an 8x2 LCD display. The code for this controller is a standard program that can be downloaded from the PIC-AXE site (Serial LCD). I used a ribbon cable to connect the display controller to the LCD display on the front panel.


DC Power Circuit
Due to space and noise considerations, I used an external 15-0-15VAC 2x300mA transformer. I have a number of these transformers in various voltages and housings and use them to power several of my tools. They all have 4mm test lead connectors, and I use a 3-pole DIN connector to connect the AC voltages to the power board.

For this instrument, I need three different voltages, +5V for all the logic, and +16.5 and -16.5 in addition to +5V for the Fast rise board.

NOTE:
With the 1.000uF capacitor (C4) in the positive supply side, there was a mains ripple on the +16.5V output when the Fast Rise board was activated. The Fast Rise board consumes a lot of power from the +16.5V and the +5V supply. The raw AC supply sagged to just below the headroom of the LM317, creating a hum on the positive High Rise pulse. Using Schottky diodes to create more headroom just didn't do it, so I added a 3.300uF in parallel to C4 and that fixed that problem. When (if) I decide to turn this circuit into a real PCB, I will redesign the power section and use high efficiency/low drop regulators and do a better job decoupling.


PG506 Fast Rise Board
The design of this circuit is a typical testament to the skills of the Tektronix analog designers, that were among the best in the industry in those days.

 
The code
The code for the main controller and the serial LCD driver can be found on my Github site: Frequency-Generator

The various parts as I built them look like this:

This is the power board. The little black square is the switching 5V regulator. I don't show the extra 3.300uF cap here, that was added later.


The Fast Rise board is at the very top. To the left is the front panel with the 8x2 LCD.
On the bottom of the case (in the middle here) is the main board. On the top left of that board is the PLL on an SMD carrier and the 4 LS390 decade counters. Next to them the 74LS151 mux and the LS109 flip-flops. Top right is the programming connector for the main controller. In the middle to the left is the 18M2 display controller and the adjustment for the display contrast. Next to that the 3 pins for the oscillator connection. To the right are the F32 OR gates and F02 NOR gates.
On the bottom row from left are the 14M2 main controller, the 74F04 buffers and in yellow the relay.


The standard Power-up screen after de device has booted up, displaying the version number of the software.

On the left side are the two Fast Rise output BNC's. On the top the positive edge, and below it the negative edge.
Below the LCD display are the main output BNC and to the right the 5MHz output of the oscillator. Top right is the rotary encoder with push button, and below it the output voltage adjust for the Fast Rise pulses.


Performance
How does it perform?

I'm using a 74F04 as the output drivers for my clock signals, and use two gates with a series resistor of 50Ohm. They produce a nice and steady 4ns rise time, using a 1mtr coax terminated in 50Ohm at the scope input.

I think I can improve on the cross talk and glitches, but that will be when (if) I design a proper PCB. [ I did]


Above is the 5MHz oscillator signal taken from the BNC connector on the front panel. Note that the end of the BNC cable is terminated into a 50 Ohm coax terminator before it goes to the scope input. Because of the poor decoupling on the main circuit board, the switching transitions of the various gates and the PLL are clearly visible. I don't care too much at the moment, more important for me right now is the frequency selection, the timing precision and the Fast Rise outputs.



Above is the 20MHz pulse, again terminated into 50Ohm.



Above is the 100KHz signal terminated into 50Ohm. The two gates of the 74F04 driver for the output are doing a good job, note the rise-time of 3.7ns.


Pushing the rotary encoder toggles the Fast Rise board power.




And here is the beautiful positive edge of the Fast Rise board. According to the PG506 specification, the Fast Rise edge should be <=1ns. This is at the limit of my RIGOL DS2072A (with the 300MHz hack - it reports that it is now a DS2302A).
The rise-time is not a steady 1.250ns, it varies a little. I was lucky when I pressed the print button on the scope to get this picture.



The pulse of the Fast Rise at 100KHz looks like this:



Calculating bandwidth from rise time
The "rule of thumb" calculation to infer bandwidth from rise time is BW = 0.35 / rise time for (Gaussian type) analog scopes and for DSO's it should be BW = 0.40  / rise time.

The RIGOL specifications for the DS2302A list a 300MHz bandwidth (@ 3dB) with a typical rise time of 1.2ns.
If we use the rise time specification of 1.2ns for the RIGOL with the factor of 0.40, we get 333MHz, on paper...

In the above actually measured case, the calculated bandwidth is 0.40 / 1.3ns (max) = approx. 307MHz. Spot on!

Master clock precision
After I upgraded my FY6600 Function Generator & Counter with a 1ppm precision TCXO oscillator, I measured the frequency of the master oscillator to be 5,000,001.7 Hz. This seems to be a little better that the part got after calibration (5,000,002.1 Hz). Either way, that is a remarkable precision for such an old and never used part.

The next step is to measure it again as soon as I have my GPS disciplined oscillator ready, which is a project I'm starting right now. If all goes as planned, this should allow me to verify the clock precision of my counter within 1ppm, and also allow me to calibrate the master clock again. The now up and running GPSDO was used to measure the precision of the FY6600. It is exactly 1Hz too low at 10 MHz. This means that the precision of the 5MHz oscillator is even better than I first anticipated.

Todo's?
As mentioned earlier, there are some things I could do to get rid of the noise, glitches and cross talk, but right now, I'm very happy with the results.

Update [may 2020]
I used this unit extensively while testing the 100 MHz differential probe design that my friend and I designed recently. Look at our blogs that details this project. We could only really characterize the diff probe with the fast edges. That alone was worth the trouble to build this unit.

In addition, after having now completed three working Global Positioning System Disciplined Oscillator (GPSDO) units on another project, described on this blog, I wanted to test a couple of things. For this test I needed a very stable and precise 1 second clock signal, to replace the jittery but very precise 1s pulse coming from the GPS unit that drives the GPSDO. This is a perfect task for this unit, but it needed a "final" modification.

To feed the unit with the extremely precise GPSDO 10MHz output, I added a BNC connector to the back panel, and wired that to the oscillator input pins on the main board. From now on, I will connect the 10MHz square wave output of one of the GPSDO units to this input to create a very precise 10MHz base clock. In order to get the master 20MHz clock back, I needed to change the configuration of the PLL multiplier chip from 4x to 2x. I also no longer needed the 5MHz oscillator, so I took it out.

Needless to say, this change in the setup works very well. So well actually, that I'm now seriously considering making a decent PCB layout and get rid of the nasty glitches and wiggles on the output pulses.
 
Update December 2020
For a while I decided to invest the time to design a PCB and see if I could reduce the cross-talk and get better signals. Besides, the wiring was complicated such that it would have been very difficult to make modifications or worse, a repair.
 
Because of the density of the many parts on the PCB and reducing cross-talk, I decided to go SMD as much as possible. This also meant that I had to redo the schematics considerably before I could turn it into a PCB.
Here are the schematics for version 2:







And here is the PCB design:
 

 
 

Note that for the rectification diodes, I used SS54 types, because that's what I had. They are very fast diodes, typically used in DC-DC convertors. A better one would be the B2100-13-F or equivalent. 
 
I made one error with the layout.  When I selected the clock multiplier from the library, it attached the wrong package to it, and I didn't notice this until I de-soldered the chip from the carrier I was using on the version one and wanted to place it. Bummer. The footprint is so small that you can't really finagle it. I tried, but that didn't work so I soldered the chip on a small carrier board and used short tiny wires to make the 4 connections.

It only took a few hours to solder all the parts in place and test the circuits. I changed some of the wiring going to the various other boards and places and voila:



The signals are a lot cleaner, especially the Fast Rise signals. There is still some of the 10MHz wriggle on top of the waveforms, but other than that, it is much cleaner.
 
Here is a picture of the 5MHz signal that I also show a little up from the version 1 circuit.
 

This is cleaner, the 20MHz wriggles are gone, only the 10MHz are still there and even more important, I now have a 50% duty cycle.
 

The plans is now to connect it to my GPSDO. When I tried that, the GPSDO lost lock immediately. This happened before and is caused by ground loops and DC connections. I'm definitely going to design a multi-channel distribution amplifier with electrical isolation.

After I added the isolated output protection (transformers) to my GPSDO, I could use it as the source for this instrument and also for my FY6600 waveform generator. This is described in another project on this Blog.


Enjoy!

The code
The PCB Gerbers and the code for the main controller and the serial LCD driver can be found on my Github site: Frequency-Generator

The PCB
I have several PCB's available at cost and shipment so if you're interested, send me a PM or add a comment to the Blog.


If you like what you see, please support me by buying me a coffee: https://www.buymeacoffee.com/M9ouLVXBdw


Tuesday, May 28, 2019

_HowTo: CPU temperature driven fan

This topic was one of my earliest postings on the raspberry Pi Forum (December 2013).

This is a PWM driven fan based on the core temperature. It was originally designed for my MediaCenter that ran on my overclocked RPi Model B (the very first model)

I recently needed something like this for my RPi Model 3 B+, so I looked it up again.

Here is the original post : https://www.raspberrypi.org/forums/viewtopic.php?f=35&t=62438&p=463458

Even after all the changes with Raspbian, 6 years later it still works.

The code posted in the forum works, but there is a more clever way to get the temperature reading without having to put it in a file, and then read it out again for processing. I now also use Python 3.5.

I'm using a small 5V fan. I like the Noctua NF-A4x10 5V, it is very quiet does not consume a lot of power and I'm using it for all my RPi Model 3's.

If you like what you see, please support me by buying me a coffee: https://www.buymeacoffee.com/M9ouLVXBdw
 

Here is the latest version that I'm using at the moment:


#!/usr/bin/python3
#-------------------------------------------------------------------------------
# Name:        run_fan.py
# Purpose:     use PWM to run a fan to keep the core temperature in check
#
# Author:      Paul Versteeg
#
# Created:     01-12-2013, modified june 2019
# Copyright:   (c) Paul 2013, 2019
# Licence:     <your licence>
#-------------------------------------------------------------------------------

import RPi.GPIO as GPIO
from time import sleep
import subprocess
import shlex
import string
import sys, os
import traceback

DEBUG = True

FAN_PIN = 4 # GPIO 4

GPIO.setwarnings(False) # when everything is working you could turn warnings off
GPIO.setmode(GPIO.BCM)  # choose BCM numbering scheme.
GPIO.setup(FAN_PIN, GPIO.OUT)# set GPIO port as output driver for the Fan


Fan = GPIO.PWM(FAN_PIN, 100) # create object Fan for PWM on port 22 at 100 Hertz
Fan.start(0)            # start Fan on 0 percent duty cycle (off)

delay = 30              # seconds of delay, testing the core every 30 seconds is OK
cool_baseline = 60      # start cooling from this temp in Celcius onwards
pwm_baseline = 40       # lowest PWM to keep the fan running
factor = 3              # multiplication factor
max_pwm = 100           # maximum PWM value
fan_running = False     # helps to kick-start the fan

def main():
    global fan_running
    '''
    This program controls a Fan by using PWM.
    The Fan will probably not work below 40% dutycycle, so that is the
    fan PWM baseline. The maximum PWM cannot be more than 100%.

    When the cpu temperature is above 50 'C, we will start to cool.
    When the cpu reaches 70 degrees, we would like to run the fan at max speed.

    To make the PWM related to the temperature, strip the actual temp from the
    cool baseline, multiply the delta with 3 and add that to the the baseline
    PWM to get 100% at 70 degrees.

    I have selected a PWM frequency of 100Hz to avoid high frequency noise, but
    you can change that.
    '''
    try:
        while True:
                # get the core temperature
                # need to use the full path otherwise root cannot find it
                cmd = "/opt/vc/bin/vcgencmd measure_temp"
                args = shlex.split(cmd)
                output, error = subprocess.Popen(args, stdout = subprocess.PIPE, \
                                stderr= subprocess.PIPE).communicate()

                # strip the temperature out of the returned string
                # the returned string is in the form : b"temp=43.9'C\n"
                # if your localization is set to US, you get the temp in Fahrenheit,
                # so you need to adapt the stripping somewhat
                #
                core_temp = float(output[5:9]) # for Celcius

                if DEBUG : print (core_temp)

                if core_temp < cool_baseline :
                    Fan.ChangeDutyCycle(0) # turn Fan off
                    fan_running = False

                if core_temp > cool_baseline :
                    if fan_running :
                        duty_cycle = ((core_temp - cool_baseline)*factor)+pwm_baseline
                        if duty_cycle > max_pwm : duty_cycle = max_pwm # max = 100%
                    else:
                        # kick-start the fan for one cycle
                        duty_cycle = 70
                        fan_running = True

                    Fan.ChangeDutyCycle(duty_cycle)   # output the pwm

                    if DEBUG : ("pwm {:.2f}".format(duty_cycle))

                sleep(delay)

    # the following will allow you to kill the program
    except KeyboardInterrupt:
        Fan.stop()      # stop the PWM output
        GPIO.cleanup()  # clean up GPIO on CTRL+C exit()

    except Exception as e:
        sys.stderr.write("Got exception: %s" % e)
        if DEBUG :
            print(traceback.format_exc())
            print("GPIO.cleanup")
        GPIO.output(FAN_PIN, GPIO.LOW)
        GPIO.cleanup(
FAN_PIN) # leave the other pins alone
        os._exit(1)


if __name__ == '__main__':
    main()




Enjoy!

Sunday, March 24, 2019

Pretty universal battery profiler



Recently, I had a number of Li-Ion and LiPo cells fail on me, and I also suspected a very poor capacity from many of my NiMh cells. Using a method that I concocted earlier with a Raspberry Pi and an ADC was too much trouble and it did not really give me what I want. That method is described in one of my other posts.

The units you can buy give you a mAh number, but don't give you a graph, which is what I really wanted.
I also did not want to buy something that I can build, so I started a Google tour to find a design to my liking. That took a while because most designs that I found were too rudimentary. My philosophy is that when you decide to build something, you might as well do it right.

The design that I eventually found that was even beyond my expectations can be found here : 
http://www.vwlowen.co.uk/arduino/battery-tester/battery-tester.htm

This is a very complete instrument that comes with a very nice PC program to show the discharging graphs, great for documentation, and you can also drive the testing tool with it. I have never written an application that runs on a Windows PC, so I was delighted with this solution. I normally save data in a CSV format and use Excel to create graphs. This program is so much better!

The only initial downside was the hardware in terms of size. I don't have enough room, and I only build instruments in cases when I use them a lot.

Hardware changes and improvements
Very quickly though, I saw some simple improvements to the hardware that John Lowen, the original designer, used. I decided to use an Arduino Nano board as the processor. The good news is that it already comes with a serial to USB interface, and the power for the whole kit can be supplied from this USB link as well. I also wanted to reduce the foot print of the board I was going to use, so instead of a traditional 20x2 LCD, I opted for an inexpensive Nokia 5110 LCD display, that allowed me to display at least 5 lines with 14 characters each with a very small footprint.

There is also another user that I follow, that found this information and build one too. Greg Christanson makes beautiful PCB layouts, I've used two of them myself for other projects, so if you're interested in his version, have a look here:

I also happened to have two breakout boards with the INA219 from Adafruit already in my stash.
 https://www.adafruit.com/product/904
I ordered these a few years ago when I had plans to design my own power supply. (which I did, see an other post) The INA219 is a high-side bi-directional DC current sensor that can also measure the voltage. The chip itself is designed for battery operated devices like PC's, tablets and phones, and helps to figure out how much juice is still available from the cells.

Building a prototype
As is typical for me, I started out with a breadboard version of some of the hardware, and learn from it. After I was satisfied, I started with a protoboard that allowed me to reduce some noise and resistance of the current loop. The INA219 has very jittery readings of especially the current, so I wanted to make the signal path as clean as possible before I did some more drastic work.

Here is a photo of the setup where I did most of the work. In the background is the prototype, beyond that is a simple Li-Ion charger.


One of the reasons for building the prototype was to see how low in voltage the circuit would go. It was designed specifically for Li-Ion cells with a cut-off voltage of about 3.0V and a fully charged voltage of 4.2V. I wanted to go as high as 14V to be able to measure 12V lead batteries, and as low as 0.8V for 1.2V cells like Ni-Mh. That turned out to be no problem at all.

In the partially built version above, I still used a 20x2 LCD screen with an I2C interface, because my Nokia 5110 displays took a long time to arrive from you know where.

The finished hardware
Here is a picture of the finished product running a stress test at a 1Amp discharge current.


Here is a simple circuit diagram that shows what I did in some detail. The Ax and Dx names refer to the Arduino Nano pins.



Note that there is an error in the diagram above: Pin 4 of the Nokia display needs to connect to D4 of the Arduino, not D2.

It was not easy to create the right setting for the back-light of the display to get the picture right. In real life it's much better. The reason why some numbers are difficult to see is that they quickly change and I did not want to speed-up the camera too much due to my room lighting.

The reason I say stress testing is that the maximum current that the heat-sink allows is about 1Amp. With that current, the temperature of the heatsink gets around 60 degrees Celsius. A maximum decharge current of 1Amp is enough for my intended applications, but if you go higher, get a larger heat-sink or use a fan.

Let me explain what you see on the LCD display.
First line is the title and the version number.
Second line is the cell voltage on the left and the dis-charge current on the right.
Third line is the 13-bit PWM number on the left and the "PID" error number on the right.
Fourth line shows the mAh number so far on the left and the running time on the right.
The fifth line is blank and used for error messages and to signal the end of test.

To the right of the display is a beeper, en below it is a trimmer to adjust the back-light level of the LCD.
Furthermore to the right is a fuse and below it the MOSFET on a heat sink.
Next to that are two cell holders, one for normal AA and 14500 types, and next to it a 18650 version.
Below these holders are a LiPo type socket and in blue a 2-wire terminal to connect everything else.
Below the display is the Arduino Nano and to the right the INA219 breakout board.
Below the Nano is a 4-pin connector for the I2C 20x2 LCD and a 100 uF cap for the 5V supply decoupling.
Above the Nano is the 1K2 series resistor to the Gate of the MOSFET, and the 10uF filter to ground.
Below the MOSFET is a 100K resistor that ties the Gate to ground, for safety.

The Nokia LCD display uses a 5-wire SPI and 3V3 power connection to the Nano.
The INA219 is fed by 5V coming from the Nano/USB port, and connects to the Nano with a 2-wire I2C connection.
The MOSFET I use is the same type as John uses, an IRL2203N Logic Level MOSFET, but I tried a few others like the BUK956R1 and they work just as well, as long as they are Logic Level.

Changing the MOSFET mode of operation
Apart from using another display and the Nano, the only major deviation I made to John's circuit is to increase the size of the filter capacitor to the Gate of the MOSFET, and add a 100K safety clamp to ground. John used a 100nF filter, and used PWM to drive the Gate, in an attempt to switch the MOSFET on and off. This is the preferred method to regulate power (and save energy and heat), but I found that the INA219 does not really like that. By increasing the capacitor value to 10uF, you create a crude ADC and the resulting DC voltage will drive the MOSFET into it's linear mode, and is than really acting as a variable resistor.

Improving the PC side of things
Together with John Lowen, we worked on some of the changes I suggested for the original PC program, to make it accept other cell technologies as well and turn it into a universal cell tester. He was very helpful and responsive and I think the program is now a lot better and supports all my particular wishes. One of the nice touches he added was a minimum cut-off voltage based on the various cell technologies. While te test is running the graph also shows the Min and Max values for that particular technology.

Important!
This post is based on John's Batterytester software. He and I worked together to create the 1.2 version. In the mean-time, he has made some changes to the code and is now at version 2.2c. My published code on the Github is compatible, but I may miss an update that John does. Send me a PM if that is the case again.

Testing some cells
Below is an example of a test report. This is a poor cell that I rejected. Although it still performs pretty well, it has less than a third of the specified capacity left. If it ever had that. I now do incoming inspections on all arriving cells.

Because I needed extra 18650 cells, I ordered two UltraFire 4.200mAh 3.7V cells from a distributor. When they arrived, there was a nice note in the package saying that the UltraFire cells were not performing to their expectations, so they send me two German made M2 TEC 8.800mAh cells, specified to deliver 11.8Wh. This translates to a discharge current of over 3Amps. I charged and tested them 5x to obtain their maximum capacity. I used the maximum 1Amp with the tester, and lo and behold, even these German manufactured cells did not get above 1.200mAh. They weighted 35 grams, seems a little low to me. This is the reason I wanted this tester in the first place! And yes, I did send the distributor the test reports. I have never heard back from him...


Note the jittery lines for the current and voltage after about 5 minutes into the test. I suspect this is due to the chemical reaction of the cell during the discharge. Some cells display a very nice line, and some very jittery. I don't think that this effect is a good sign for the quality of the cell. When the voltage is jittery, the current will be jittery too, because the program tries to keep the current constant.

Here is another test,this time of a 14500 Lithium cell, where I suspected the capacity very much.

The cell weight is a good give away for the vastly overrated capacities that are advertised, so this is a nice touch from John to add it into the documentation. His intention for this feature is to slap an unscrupulous or oblivious vendor with this proof to get replacements or his money back.

Are more expensive cells better than considerably less expensive cells?
There is only one way to find out.
Below is a test made with the latest version of the tester software using an inexpensive IKEA LADDA AAA HR03 1.2V NI-MH cell with a capacity of 900 mAh :


Inexpensive does not have to mean poor performance is what you can see here.

Is a much more expensive Panasonic BK-4HCCA 1.2V Eneloop AAA Ni-Mh 900mAh is any better?



Trying to improve on the original Arduino code
While testing, playing and learning about the Arduino code, I decided to try a real PID routine to see if I could improve the current loop. It was very jittery and I saw some room for improvement. I experimented for a few days with different methods while learning the subject, because I'm pretty much a noob with PID methods. In the end, I got one working pretty good, after making considerable changes to the original code, but it did not improve much. John's method seems to be good enough.  The root cause I think is the INA219 measured current "noise" in combination with the fluctuating voltage level of the cell. It almost looks like the chemicals inside the cell are "boiling", creating tiny effects on the output voltage. That combined with the jittery current readings from the INA219 is in my opinion the reason.

I also experimented with a version of my software low frequency filter program (IIR) that I used in my milli-Volt DMM code (see my post about that) to filter and tame the 24-bit ADC output. It worked in this application as well, but had some side-effects without improving much so it went in the bit-bucket as well. I think we need to leave "good enough" alone, and be satisfied with it.

Changing the PWM counter resolution
The most significant improvement I got however was when I realized that the 10-bit PWM counter that John used was too course for the current loop regulation. A single digit change caused too much of an effect. If you realize that the Gate voltage to turn on the MOSFET and regulate it as a resistor is all done within a very small Voltage range (VGS).  Typically within 100-200mV. A 10-bit counter with a 5V maximum output has a bit level resolution of 5V/1024 bits=4.8mV. My observations were that this is not fine enough. John maybe wasn't aware of the trick you can use to get higher resolution counters. I experimented with 12, 13 and 14-bits and settled on 13, giving me a bit resolution of 5V/8192 = 620 microVolt.

Most of the other software changes I made were to create a nice way to display the results on the Nokia display by making numbers right justified.

Finally, I added some code changes to better terminate the loop when an error occurs, or when the test finishes normally.

I also have no use for running the tester all by itself, so there is no method to try to input the test parameters other than by using the PC. All that code is gone. I also don't see a need to have an LED signalling the end of test, that's what the display and beeper are for, so that went out as well.

There are a number of added comments and additional documentation in the code, so my changes should be self-explanatory.

The code can be found on my Github site here : https://github.com/paulvee/Universal-Battery-Tester

Note:

23-Oct-22: I found that John updated the PC software now to V2.2c. It still worked with my earlier version V3.03 but to stay compatible, I have updated my code to V3.04 which is on the Github.

Conclusion
This tester is very easy to build, and the project was already very well documented. If you consider building a very good battery tester or profiler, you now have two options to choose from. I can highly recommend either one.

Enjoy!
Paul


If you like what you see, please support me by buying me a coffee: https://www.buymeacoffee.com/M9ouLVXBdw