my ideas in action

Category Archives: electronics

new lessons on analog CMOS design

Recently I’m working on some free lessons / courses on electronics.

More specifically on custom analog CMOS design.

I think is better to share my knowledge with others. I try to present detailed design with accent on the principle, methods and trade-offs.

My first is about designing a CMOS analog opamp , with full rail-to-rail inputs and outputs.

I go from easy to hard and I hope to be easy for everyone to understand reasons and the decisions that are made during design process.


For the moment I have only few 10 minutes video…. I will add more soon.



Lab power supply with PIC microcontroller (4)

I made some small changes to the schematic. I added a zener to protect the voltage feedback into Vloop opamp.

Also I changed the way the current limitation loop take over the voltage loop. Previously I was thinking to lower the REF voltage when the ILIM is reached. I think a better way is to use 2wo diodes ( 1N4148) and a 5K resistor to make a OR function. This works better and the transition is smooth. I was looking also at similar power supply from big brands ( Agilent, HP) and they do the same thing.

The new version is 3.1:

LabPicPowerSupply_v3.1_sch ,


LabPicPowerSupply_v3.1_pcb .

I made also an experiment to see hot the etching process works and how good are the tracks. I am disappointed somehow since I did not used a toner transfer but a simple permanent marker. The copper was partially etched on the areas where the marker was thin only.  Where it was thick it is ok. To etch I used hydrochloric acid (HCL 25%)  and oxygenated water (H2O2  10%)

I didn’t had access to a laser printer but I hope so make a full size experiment soon with toner on the real PCB.




Lab power supply with PIC microcontroller (3)

I have some updates regarding my project.

First of all, I have a limited time to work on this project. So it is normal to take such long time to develop it.

Second I do not want to jump too fast in “making” phase and I prefer to go slowly step by step to get a good result.

So, I was worried about the stability of my previous schematic. So after a few hours on spice simulation I understand what was the problem. Well, the main issue is that the voltage loop contained 3 low frequency poles.

One is the opamp itself that has a dominant pole at ~10Hz ( see MCP6022 spec), this cannot be avoided since any opamp will have a pole approx in this range.

The second is the output node. The main issue with this pole is that is moving with the load ( R and C) and since this is a lab power supply it will always be different.So what I decided to do is to use a small output capacitance of 1-10uF and to use a dummy load of approx 10mA. This will force the output NPN ( 2N3055) to have a minimum current even if there is no load. The main reason is that when the current is very small in the 2N3055 transistor the predriver ( BC139) will have almost no current. So the gain drops dramatically and the loop become unstable.

The other pole is at the gate of the predriver NPN . this is a “design” fault since the internal node should not affect the functionality.

So I decided to change the loop architecture and to use a intermediate amplifier with of gain of approx 5. The intermediate amplifier is made with Q4 and Q9 and the gain ratio is set by R24+R9 and R18. I chooses a gain of 5 since this gives me a opamp output voltage range between 1.3V and 4.5V for a output voltage of 0 to 21V.  Also this intermediate opamp has a high poles and do not require any compensation. Also since the gain of the amplifier set the voltage range at the output of the opamp this give me the ability to use a non Rain-to-rail output OPA. But I will keep the MCP6022 since the offset is very low and the input is rail-to-rail.

The other changes are the fact that I eliminated the resistor to SUP24V that was feeding the base of the predriver NPN.  Also I swap the opamp inputs ( intermediate amplifier has positive polarity) and I added a 100-330nF capacitor over the opamp. This compensation capacitor is necessary since I noticed that the loop may become unstable in certain conditions ( when load is changing). I need such a small value ( in the hundreds range) since the opamp will amplify the effect of this capacity  ( miller effect) and the pole generated is very low.

So the new version of the schematic is here : LabPicPowerSupply_v3_SCH

There are other minor changes :

  • removed reset PIC switch
  • removed capacitors from DAC output
  • changed the positions of some PIC  IO’s
  • added protection for the input of the opamps that measure the load current ( anti-parallel diodes)
  • added the buffer before ADC voltage measurement ( VMON). before this buffer was inside the voltage loop.
  • the ILIM protection is made by changing the voltage reference ( output of the DAC)
  • small changes in the components value
  • not use the MJ3001

I made a real test of this new architecture . I used a simple breadboard and I noticed that the stability is OK . I did not had a full test under all conditions since the 2N3055 was not on the heatsink but even like that it was capable to deliver 1A at 18V output for few seconds, this means 18W !!. I  had to stop it after few seconds since the 2N3055 became too hot.

The dummy output load I made it with the BF254B device. It was the easiest and I had laying around some devices. It can be made is many different ways but in my case I do not need accuracy.

There are some aspects that I noticed also. The predriver transistor BD139 can dissipate some power. This depend on the gain current (Hfe) of the 2N3055. My transistor had a gain of 35 at Ic=1mA so this means that trough BD139 will flow approx 30mA in the worst case. If this is happening when the output voltage is at 0V ( hard short of the lab supply terminals) then this means that the predriver will dissipate 30mA*24V =  0.72W. It may not seem too much but the datasheet show that this can bring the BD139 temperature to  ~75degC above the air temperature. If the air surrounding the device is at 30C this give a junction temperature of 100C. It is high for my taste !!! so a heatsink is mandatory !

The other issue that I noted is that 5V regulator also need a heatsink. The current consumed may reach 50mA and the power dissipated can be 1W. In this conditions LM7805 can go to 65C above the air temperature. And this is continuous and not a “error condition” like in the case of BD139. So a heatsink is really necessary. Some may argue that is not bad to use them without heatsink since this is a tolerable temperature and many Chinese manufacturers do it… well it is my design and I do not want to risk.

I made also a layout tentative.  It was not easy but at least I have a workable PCB. I still need to double-check the connection of each device to be sure that it is the correct package and the footprint is matching the actual component that I have. I hope to finish this step soon so that I can start the real manufacturing of the PCB and then component soldering.

Here are all the files for version 3  (KICAD schematic and PCB)

schematic : LabPicPowerSupply_v3_SCH

BOM list : LabPicPowerSupply_v3_BOM

PCB layout : LabPicSupply_v3_PCB

Lab power supply with PIC microcontroller (2)

So I worked more on the schematic… some changes.

Surprisingly , the hardest thing now is to search for each component and to check if it matches the footprint. This will take more days.

Regarding the case I think I will use a DVD case . the buttons are matching well the function that I want to use.


The button function will be :

[-] [+] [MENU]

[down] [up] [OK]

[ON/OFF ] [ OK ]



I tried also a routing of the board… well it is hard. manual routing is a pain in the ass, . I discovered now Freerouting and I will have to play a little bit with it to see if can give good results.



Lab power supply with PIC microcontroller (1)

I just started a new project. It is a lab power supply. The main target is to do it with a microcontroler (PIC) qnd to have good enough accuracy.
My spec is 5mV per step for output voltage and 1mA per step for current. The max voltage is 20.48V and max current is 1.024A.
For this I will have a LCD screen ( 16×2 characters) and the panel will be with push burrons. I do not want to use rotary encoders.
The Lab Power Supply will use a AC-DC converter from 220V AC and will provide also some other fixed voltages like : 5V, 3.3V and maybe others (12V).
For the moment I have two old AC-DC converter from some printers (HP and Canon).
For the case I think I will use a old DVD player case since I have there all the necessary buttons and front panel.

I target to use PIC16F1789 since it is powerfull enough and has many IO pins. The ADC reading will be made with MCP3201 12bit and the DAC wil be MCP4922 dual 12bit DAC.
For the reference I intend to use MCP1541 but here I am not sure. I may also use a trimmable reference since I want to be precise for the 4.096V value.

For the current measurement I wanted to use INA210 or similar from TI but they are not cheap and hard to find. Also TI sample program is a nightmare. So I decided to use a opamp and a PNP to read the high-side current.
The opamp that I want to use is MCP6022 (2 OPA per package) . I need to use this opamp since it needs very low offset and full rail-to-rail input/output.
The other opamps that I have are not well suited for this job (some have bigger offset or/and not rail-to-rail in/out).

The ILIM loop and voltage loop are made fully in analog domain. I do not want to make it in software since may create issues later and also because I have more experience with the analog than PIC software. The other reason is that it is easier to debug and they are modular.

For the voltage divider I use a buffer since the ADC require low inpedance input source and a simple resistor divider will not work well.

I added below the full schematic that I have now. It is still a work in progress so I do not encourage anyone to think that is fully functional or that is tested. It is just a schematic made based on my knowledge.

LabPicSupply version 1 (pdf file)

LabPicSupply BOM list

Power soft switch

I want to describe here some schematics for a power switch. The soft power switch is in fact a electronic switch ( no relay, no moving parts) that can be used as a ON/OFF for a certain device.

The classical way to switch ON/OFF a device is to use a flip switch like this :

But this mechanical switch is expensive and can break  after a wile.

The other big disadvantage is that it require the mains AC line (supply line) to physically pass through that switch. So if for example you want to put the ON/OFF switch on the front panel of a device you have to go there with AC 110/220V mains. This can create problems (noise, interference…)

Beside this some people want a “fancy” ON/OFF function with only a simple push button. Like this:

So The switch is very small and can be integrated directly on the PCB board. Beside this there is very small voltages/current passing so there is no risk of electroshock.

Usually this type of application use DC voltages in the 3-24V domain. They are used often to start a board that has micro-controller or a small electronic device.

The following possibilities are shown below:

1: power_soft_switch















Improved CMOS voltage follower

The below figure show two variants of the voltage follower.

diagram A show the classical voltage follower. This stage is used in CMOS design because we need a Vgs voltage shifting or because we need a intermediate stage that have high input impedance and low output impedance. As it is easy to observe, the output impedance is 1/gm1 so it is usually in the order of Kohms.

There are many ways to improve the voltage follower  and one simple solution I will describe here.


In the B diagram the M1 transistor is having the same behaviour like in diagram A.

But now there is M2 that form a local loop. This is a negative feedback that “boost” the performance of the M1 transistor. So now the output impedance is lowered with the gain of M2.

The sink current capability is the same as in case A but the source current capability is improved. This was not a issue with schematic A but now the mechanism that deliver current to the output net is different. In the diagram A the current was flowing from VDD to drain of M1 to output pin, while in schematic B the current flows from VDD to the source of M2, drain of M2 and to the output pin.

Another difference is that the current that flow through M1 is not fixed and do not depend on the load current. This may be important in some cases where a constant Vgs for M1 is required.

Another disadvantage of the schematic B versus the schematic A is the fact that PSRR is worse. This is do to the fact that M2 has the source connected to VDD while the gate is on a high impedance net ( that depend only on the internal loop). This may be a issue in some designs. To avoid this the designer can use other tricks to solve the issue like : regulated supply (ex : LDO ) or differential paths .

CMOS current mirror with boosting

The cascodes are used generally to increasing the output impedance of a current mirror. But sometime this is not enough. After all a ideal current source has infinite impedance so we must always try to achieve this very high output impedance.
Usually to increase the output impedance a gain is needed to “boost” the performance. This “classical” way is to use a opamp or a simple MOS transistor to acheave this.
The solution that I want to present here is simple and give good results.

M1-M4 form the classical cascode topology. The M16 current flow in to M2 so the size of M2 must be bigger than M1. Usually is 2x, 4x bigger.
The input voltage for this current mirror is VGS1 = Vt+Von.
The input impedance is 1/gm1 = small = in the order of kOhms.
The output minimum voltage is Vds16+Vds2 = usually 200-400mV
The output impedance is ro2*gm3*ro3*gm16*ro16 = big = usually in the order of 100x MOhms

The best value of Vbias is Vds2+Vgs16. This can be obtained with a replica type of circuit.

Asus A72J / K72Jr cooling – replace thermal grease for CPU and GPU

Few days ago I open up my laptop and clean it.I made a small tutorial to help other people to do something similar if they have this laptop.

I have a Asus A72J / K72Jr. This is a 17.3 inch / I5 / ATI HD5470 1G / 4Gb DDR3 / 500Gb laptop.

My problem was that I noticed that the temperature was quite high 50-55C and the fan was running almost continuously. From my past experience with laptops and PC, I know that usually when this happens it is the cooling that is not efficient any more. Usually is the fan that is not blowing enough air , or the heatsink is dirty or simply the thermal grease that transfer the heat is dried.

In my case it was the thermal transfer to the heatsink that was not efficient anymore. My laptop is approx 3 years old and this is somehow expected to happen.

So what I describe here are the steps to replace the thermal grease from CPU+GPU .

Please do not try this is you are not familiar with PC repairs. I show this here just to help other people that may need to know how to do it. The operations are easy but you need patience, calm and to be careful. For me the entire process took approx 3 hours.

So first open the HDD+RAM compartment : 4 screws on the back.

Remove only the HDD. The RAM is not necessary to be removed.

Then remove the keyboard.

To remove the keyboard you have to push the small 5 pins from the top side of the keyboard , on top of key : ESC, F5, F9, Prt.Sq, and END.

Be careful with the keyboard flat cable.

The keyboard:

IMG_0902 IMG_0901

Then you have to remove the 5 screws that are under the keyboard. They are numbered 1 to 5.

Then remove the screws from the back side of the laptop .

The are many screws:

– 2 of them hold the DVD unit – marked with CD/DVD (disk) symbol.

– 5 screws are in the HDD/RAM compartment

– The others are in the holes on the back of the laptop.

Then remove the 4 small screws marked with “A” that are under the battery compartment. I forgot to mention , but is evident, that from the beginning you have to remove the battery first !

Now , separate the front side of the laptop from the bottom side.

With the fingers create a gap and be careful not to scratch the front side. The front is kept with some simple plastic clips. Do not pull too hard since on the back of the front side is a small flat cable for the touchpad.

After you remove the front side you will have something like this:




Now you should see the motherboard and the fan.

The screen is always attached to the back side and is not necessary to be removed. It is better to cover the screen with something to avoid scratches.

IMG_0911One thing that I noticed immediately is that the mainboard controller is not having good thermal contact with the heatsink. His heatsink is the big aluminium plate that is under the keyboard. I fixed this by adding thermal grease ( see it in the pictures below).

Now you have access to the fan and his radiator.


In my case the fan and the radiator was clean.

If you need to fix only the fan then you can remove the 2 small screws . Then with a knife separate the metal plate that is under the fan by the plastic black top side. On the lateral of the fan you will notice small teeth. Be careful not to bend it too much since this is simple aluminium. If the fan do not fit well in his case it may make noise or vibrate.

In my case I continued with opening and removing the mainboard from the case.

To do this you have to remove ONLY the screws marked with white triangle. The are 2 on the small board that has SD card reader, other 2-3 on the main board.

Then remove the 2 screws from the fan.

Then remove the GND/earth screw from top-right corner that is near the screen connector.

The mainboard is easy to lift up and you have to be careful to the screen connector ( top right side) and speakers connector (right middle side – twisted pair cable)

At the end this is what you should obtain:


The fan and the small SD card board are always connected with the mainboard. Do not remove them ! not yet anyway.

This is the back side of the mainboard and the CPU and GPU are visible.

IMG_0928 IMG_0929 IMG_0931

Next step is to remove the big copper heatsink and the fan from the CPU+GPU.

Remove first the connector of the fan and then remove the 4 screws from CPU and the 2 screws from GPU.

Be careful not to bend the copper thick heatsink or to force too much pressure on the mainboard or the CPU/GPU.

The next steps are the cleaning of the old thermal grease and replacing it with a new one.

I cleaned the CPU and the copper heatsink with kitchen paper towels and alcohol. This process take a lot of time and attention. Do it in well illuminated places and with no dust.

Do not use chemicals and to not put your (dirty) fingers on CPU or GPU.

When you clean the CPU/GPU do NOT use sharp objects !

Do not use metal objects ! you can scratch the CPU/GPU core and KAPUT !

If the old thermal grease is hard to remove you can use wood sticks (matches) and alcohol. Do not use fabrics/cloths that can generate dust/lint/debris !

Do not remove the CPU from his socket !

I noticed that GPU and CPU were covered by a red plastic cover (look like a adhesive isolation) , probably to isolate a possible contact between metal heatsink and the metal parts from CPU/GPU.

Some pictures from cleaning ( in chronological order):

IMG_0937 IMG_0938 IMG_0939 IMG_0940 IMG_0941 IMG_0942 IMG_0943 IMG_0944 IMG_0945 IMG_0946 IMG_0948 IMG_0952 IMG_0953 IMG_0954 IMG_0957 IMG_0959 IMG_0960 IMG_0962 IMG_0963 IMG_0964 IMG_0965 IMG_0966 IMG_0967 IMG_0968

After the cleaning I added new thermal grease on the CPU and GPU and also on the copper heatsink:


Then I mounted all in the reverse order of the disassembly ( see order above). Pay attention to the screws of the CPU , see order 1-2-3-4 from heatsink ! Put equal pressure and do not force them too much !

All works fine now, the CPU/GPU are at approx 40-45C and the fan works only from time to time. Of course this is for idle . But even for paying HD movies the GPU is only 50C and CPU 50C also. So I’m happy with the results.

As you can see from above pictures the GPU ( ATI) and CPU (i5) are having a common heatsink and that why the temperature is almost identical on both of them.


As a side note I observed also that the mainboard have a secondary SATA connector and an additionally space for a second HDD.

This is interesting since a secondary HDD can be added. In my case I so not need it, but it may be a useful info for guys that want to use two HDD or a combination SSD and HDD.

I did not tested if the second SATA connector is functional.

The disadvantage of using this hidden connection is that you have to remove the front face/side of the laptop to have access to it.


All-in-one printers sucks !

The All-in-One printer/scanner/copy use a stupid and dumb idea. Put all this machines in a case and sell it to people. But to cut costs the manufacturer use a single microcontroller to manage all 3 functions. So even if the price is very low ( sometime what you pay is just the cartridges and the brand logo) the device must/can not be used as a separated scanner. The main reason is that if you do not have cartridge installed or they are empty almost for sure you cannot scan. It is a stupid thing since the scanning process do not require the cartridge at all. But the big companies (Canon, HP, Epson,…) force you ( and us all) to buy expensive cartridges just to be able to use the scanner.

I got (for free) a Canon Pixma MP250 and I tried to make the scanner to work without the cartridges installed. No success till now. I will not buy cartridges since they cost as much as a new printer.

I do not know what hacks to apply to just use the scanner. I need the scanner only 1-2 times per month and I think to buy a simple scanner is too much ( and too expensive).

So one more time it is confirmed the phrase : what is cheap , it is cheap for a reason !

So if anyone knows a method to make the scanner work without cartridges installed, then please let me know.