Switch Mode Power Supplies (Part 2)

Part 1, 2

Next picture illustrates the principle of operation of my proposal for an arduino controlled Switch-Mode Power Supply (SMPS):

Instead of using an integrated chip, we will use arduino as a controller. The basic configuration requires an output line to drive the switch and two analog inputs for reading the voltage from the current sensor and the output voltage sensor. Both the voltage and current sensor are represented as functions as they require some attention.

The heart of the system is the driver of the switch. As explained before, the amount of energy flowing through the SMPS depends on the on/off ratio of a periodic signal. This all about PWM (Pulse Width Modulator). And timers from the micro-controllers can do the job nicely for us. As we will leave timer0 in peace because it cares about millis() and micros() functions, we will use timer1 which is very handy for the job. Firstly we will set timer1 prescaler to 1 in order to achieve the fastest PWM:

TCCR1B |= _timerPrescaler;

_timerPrescaler is a user defined constant from the application, defined as

const uint8_t _timerPrescaler = 1; 	/* 1 to 7, 0 = timer off, typ. 1 */

Timer1 features a programmable resolution allowing 256, 512 or 1024 steps per cycles. Once again, we will go for the fastest PWM and go for 256 steps.

/* Set fast PWM mode 5, 6 or 7, depends on timer Bits which can take the values 8, 9 or 10 (bits) */
TCCR1A |= ((_timerBits - 7) << WGM10);

As a result of these choices, the final PWM cycle time shall be : 16.000.000 / 1 / 256 = 62.500 Hz.

Adjusting the cyclic ratio (so as to say the on/off ratio) is done by adjusting the upper count trigger level of timer 1 in the OCR1B register. The updates are performed just before timer1 starts counting; the synchronization is performed thanks to the setting of a variable which can be read or write from any function from the application:

ISR(TIMER1_OVF_vect)
{
	/* Set synchronization variable */
	_syncState = 0x01;
}

Next lines of code illustrate the way synchronization is performed when a synchronization is required:

/* Set timer upper count */
_syncState = 0x00;
while (!_syncState);
OCR1B = dutyCycle;

This happens in the regulation control functions as well as in the analog to digital conversions. In this way, measurements are always performed in the same way at the same time.

Lets talk a little bit about the switch. The component of choice for achieving this task is a MOSFET transistor. Among their most interesting properties is the resistance between the drain and the gate of the transistor which is very low (< 1 Ohm) when the transistor is On. From the previous post, we know that the lower the voltage across the transistor the least the power dissipation.

In this case, I decided to go for a P-Channel MOSFET. Although they drive less current – compared to N-Channel MOSFET, but still largely enough for us – they are simpler to drive when used on the high side of the power supply. However driving a MOSFET transistor still requires some attention. There are roughly three ways of designing this part of the circuit: the quick and dirty way, the simple and yet efficient way and the lazy way.

The quick and dirty consists in the following circuit.

The gate of the MOSFET is driven to a low state by a general purpose transistor. When the transistor is not conducting, the gate is driven to a high state via a resistor. This configuration is simplistic but it has multiple drawbacks. Such a configuration is slow and the on and off states are achieved after “long” transition times during which power will be dissipated. Also, the source/gate voltage must be kept within limits (typically 10 to 12 V, check the MOSFET specifications) otherwise you will kill the transistor. So, lets get rid of this option which is good enough for driving LEDs or relays at low speeds.

The lazy way consists in using an integrated circuit which will do the driving job for us. You may even use N-Channel MOSFET transistors as some of these circuits generate their own bootstrap  voltage (see below) so that the gate can be bias at higher voltages than Vin.

The alternative is the use of a fit for purpose driver:

The driver consists in a totem pole made of two complementary transistors which common emitters (low impedance side) drive the gate of the MOSFET. This is a simple and efficient solution which keeps switching delays low. The resistors shall be chosen according to Vin and to the MOSFET specifications.

I cannot conclude this post without mentioning the use of N-Channel MOSFET transistors. These designs require a proper biasing of  the MOSFET gate, at the higher voltage that the voltage at their drain. Next circuits are dealing with the use of a bootstrap which elevates the driving voltage at the gate of N-Channel MOSFET.

Here is a custom design which uses few additional discrete components

This is in few words the way it works. When PWM in is high, T2 is fully on, T1 is fully off and the test point B is at almost 0 V so that the lower end of C1 is at 0 V and its upper end at Vin, consequently charged through D1. When PWM in is low, T2 is fully off,  T1 is fully on so that the lower end of C1 is at almost Vin. As a voltage of almost Vin is present at C1 ends, the upper end of C1 (test point A) is now at almost 2x Vin thus biasing properly T1 gate. This is the principle of the charge pump applied to biasing the N-Channel MOSFET gates without additional power supply.  It works fine as long as a residual off and off state exists in order to keep the charging process alive. This may create some problems when the over voltage current or over-current protections are triggered. Also T1 driver is not optimal so that I did not adopt this solution in my later developments.

You may prefer to use a specialized IC that contains a voltage elevator. Next picture illustrates the wiring of one among the most popular chips (IR2110):

If you stick to my original design, you will not use the MOSFET on the low side and keep using the free wheel diode. However, better performances will be achieved using the low side MOSFET. Last trick: if you are lacking a free wheel diode and have a spare N-channel MOSFET, use its protection diode (across drain and source) a free wheel diode, that will do the job perfectly.

 

Memories from my first trips in Silicon Valley

As I was tidying my electronic components, I found an untouched plastic bag containing an DC that I bought a loooooooong time ago in San Jose.

At this time, some friendly colleagues from SID (HP Scientific Instruments Division located in California Avenue) drove me to some great places around Palo Alto, including some electronic shops such as Fry’s and JDP Mocrodevices (They knew that electronics was one of my hobbies). Although I was leaving next to Paris and having access to electronic shops, I was amazed by the huge variety of components available, and above all, this was the first time I could buy components just like in a supermarket. I brought back a bag of them, including this TI DAC0800 analog to digital converter that I did not use finally. Surprisingly, they are still available at a slightly lower price that in the 80’s and not taking into consideration the changes in the value of money.

Switch Mode Power Supplies (Part 1)

Part 12

This is the begining of a series of posts dedicated to an original subject that I had in mind for sometimes now. After few attemps, I decided to share my early design which might drive us up to building a versatile lead-acid battery charger.

The aim of these posts is not to rewrite or reword the numerous publications related to switching power supplies. It is an attempt to show and explain how to build a pretty simple and yet powerful Switch Mode Power Supply (SMPS).

Let’s start with some fundamentals and explain the principles of regulated power supplies. There are multiples ways of getting a source of DC voltages: batteries, solar panels, alternators and dynamos, AC-DC converters, etc. However, most of these sources fail to deliver a constant DC voltage: batteries are getting slowly discharged, alternators and dynamos may have unstable driving speeds and deliver fluctuating voltages, AC-DC converters vary according to AC drifts and power consumption. If one really need a constant DC voltage, he will have to insert a voltage regulator in between the source of DC voltage and the load.

There are mainly two different ways of controlling the power supply output: you may use an analog regulator or a switched regulator.

An analog regulator (e.g. 78xx series regulators) is comparable to a tap with a feed back. If the flow at the exit of the tap is higher than expected the  tap is slightly closed, down to the expected value. And vice versa (I am over-simplifying, but that’s the idea). This type of regulator is very simple, cheap and comes most of the time integrated and built in one component (true for medium to low power regulators). However, these regulators suffer from a major drawback: power dissipation ! The reason is that the energy which is not used by the load has to be dissipated. This is the reason why most regulators of this kind feature large thermal dissipators to which are attached the regulators or transistors (high power). Let’s check that through an example:

On the left hand side is a source of DC voltage (~15V). On the right is the load to be fed by regulated voltage. This is a resistive load of 500 Ohm across which flows a current of 1/100 A, as the resistor is biased by the 5 V from the 7805 regulator. This same current flows through the 7805 regulator. As the voltage drop across the regulator is 10 V, the dissipated power is easy to compute.

From this example, we can draw some recommendations: avoid large voltage differences between the input and the output of the regulator, constrain the current used by the load and use appropriate heat dissipators. The good news however is that most modern regulators feature over-current and over-temperature protections which will protect the component located on the load side.

Switched regulators solve the heat dissipation problem to the cost of few external components and “intelligent” controllers. Back to the hydraulic comparison, on one side we have a reservoir of energy fitted with an on/off valve, a damper and a flow sensor. The idea is to switch the valve on and off  in order to drain just the required energy from the reservoir. As the on/off cycles create fast pressure changes a damper is fitted between the valve and the exit of the device. Based on this design, it is easy to understand that the longer the on time, the more the power flowing through the regulator. The flow sensor measures the amount of energy leaving the device and applies the feed back to the valve controller.

This is how it translates in electronic terms. This design is known as a buck converter: other component arrangements can be used for generating an output voltage which is higher than the voltage at the input (This is the booster design). Some are capable of generating a constant voltage whatever the input voltage: e.g. many portable devices feature buck-boost converts so that two 1.5 V battery can feed electronics requiring 3.0 V. Buck-Boost converters will deliver a constant 3 V from the fully charged state of the batteries (~3.3 V) down to their fully discharged state (~1.6 V). Many publications cover the principles of SMPS, among which this one or this one. The main benefit from the switched power supplies lies in the very low power dissipation across the switching element .

Further readings:

Next post on same subject

3D Prints: pen holder

Are you looking for an original present for (next) Christmas ? Here it is ! I made a couple of them for relatives and they loved it, so that I am 100% sure about my advertisement for this 3D printed product !

However, printing the parts might be really challenging because of the heterogeneity of the main part profile. Your printer must be well calibrated and cleaned.

 

Otherwise, you may, after a couple of hours (actually almost 8 hours), get very disappointed with incomplete prints, broken pieces,  unequal density of  filament prints, etc. Like in this unsuccessful attempt

In other words, this print will not only please people around you, it will challenge your printer performances! Ready for this challenge ? Here are the STL files (cube and optional bottom plate which prevents the pens from falling when moving the pen holder).

Enjoy and keep me posted with your own results.

Back to the main topic

Direct Digital Synthesizer (DDS) (Part 8)

Part 1234567, 8

As seen before, the proposed DDS design has its own limitations. The main restriction is caused by the limited frequency from Arduino: 16 MHz for 5 V supplied platforms such as the UNO, and lower frequencies for 3 V supplied platforms such as the Fio. As a consequence, the higher the requested DDS frequency the harshest signal. Next is an example of  a 8 kHz raw signal, as it is output from the VoutA pin from the MCP4921.

In the previous posts, I used a simple filtering capacitor in order to smooth the signal. In more technical terms, I used a very basic passive 1st order low pas filter. Low pass filters let frequencies which are lower than a predicted frequency threshold go through the filter while blocking the higher frequencies. Following the same principle, one can build high pass filters for removing unwanted low frequencies, or band pass filters and band stop filters which are useful for removing AC line residual.

Starting from this basic description, we can deduce that the frequency threshold (aka cornering frequency) is one of the most critical parameters. An other critical parameter is how steep the corner is ! Next plot illustrates how much filtered frequencies are attenuated depending upon the so called order of the filter: the highest the order the steepest the cornering.

Other parameters are of great importance such as the Gain, Q factor as well as the phase shift which are not covered in this post.

In the present example, I choose an active low-pass Butterworth filter, which has a maximally flat amplitude response in its pass-band region. This filter is implemented in a Sallen-Key configuration as shown in the next illustration:

Although this type of filter as unitary gain, R3 and R4 may be chosen adequately in order to set higher gains (Unitary gain is achieved by removing R3 and using a 0 Ohm resistor for R4). Computing R1, R2, C1 and C2 is not an easy task. However various options are available to the designer: on line calculation and freeware applications. Many publications are also available, mainly from electronic component makers. U1 is any rail-to-rail (input and output) high performances op-amp.

As hobbyists, we probably have many more resistor values in stock compared to capacitors. So that the easiest way to calculate the components values is to start with what you have in hands. I decided to go for a pair of 10 nF capacitors which led to a using two 910 Ohms resistors, so close from 1 kOhm that I decided to go for the simplest! Fair enough, here is the resulting signal:

The yellow plot represents the incoming signal while the blue plot represents the filtered signal. One could make two observations: first is the slight attenuation in signal second is the slight phase delay. Both relate to the behavior of this type of filter and have almost no impact on our final objective which is a clean signal generation. On the other hand we now get a remarkably clean sine wave out of the DDS.

Links:

Here are a few links which may be useful to you

 

 

Direct Digital Synthesizer (DDS) (Part 7)

Part 12345678

A recent project lead me to excavate a quite old DDS design which may be of some interest for you. Instead of using a ladder of resistors, this design features a simple, cheap and yet powerful digital to analog converter. I will later explain why I choose this particular Microchip circuit but for now I will concentrate on its key features.

  • 12-Bit Resolution
  • ±0.2 LSB DNL (typ)
  • ±2 LSB INL (typ)
  • Single (MCP4921) or Dual Channel (MCP4922)
  • Rail-to-Rail Output
  • SPI™ Interface with 20 MHz Clock Support: that’s very convenient for the DDS application
  • Fast Settling Time of 4.5 µs
  • Selectable Unity or 2x Gain Output
  • External VREF Input. In this way you can choose th full range of the output signal
  • 2.7V to 5.5V Single-Supply Operation (n other words it is Uno and Due compatible)

The chip is encapsulated in a convenient PDIP 8 pins package which is very handy for prototyping; its also comes in smaller packages such as  SOIC, MSOP and TSSOP. For more information about the MCP4921, check its datasheet >here<. You may also use the MCP4821 which is almost identical but features a built in reference voltage (2.048 V) check its datasheet >here<.

Note: Five years from now, very few publications were dealing the MCP4921 DAC; after a quick overview on the subject, I realized that many posts cover the subject. However I decided to stick to my original idea as later post will refer to this one.

Driving the MCP4921 DAC is quite easy from a hardware and a software perspective. The picture below illustrates a quick and dirty implementation of the chip using an Arduino Nano and a bread board. All you have to do is to wire the SPI ports properly.

Next is an example of wiring. Real basic: the output swing from GND to the voltage applied to Vref (actually 5 V.

The you may use a couple of simple functions as a starting point: initialize the chip

/* Initialize the chip */
void PlainMCP4921::InitializeMCP4921(uint8_t csPin)
{
	/* Initialize SPI port */
	SPI.InitializeSPIMaster();
	SPI.SetSPIClockDivider(2);
	SPI.SetSPIClockMode(0);
	/* Record the chip select pin mask */
	_csPinMask = (1 << csPin);
	/* Set chip select pin as an output pin */
	DDRB |= _csPinMask;
	/* Set default state high */
	PORTB |= _csPinMask;
}

and set require a digital value conversion

/* Write parameters and data; gain is as per HT_GAI_X constants */
void PlainMCP4921::Convert(uint16_t digitalValue, uint8_t gain)
{
	uint8_t LSB, MSB;
	/* Set parameter bytes */
	MSB = (SHT_DWN_DISABLED | gain);
	/* Set data bytes */
	MSB |= ((digitalValue >> 8) & 0x0F);
	LSB = (digitalValue & 0xFF);
	/* Send data */
	PORTB &= ~_csPinMask; /* Assert converter */
	SPI.SPITransfer(MSB);
	SPI.SPITransfer(LSB);
	PORTB |= _csPinMask; /* Deassert converter */
}

These very simple functions shall be reused in the in the original PlainDDS library and renamed PlainMCP4921. In this way we get an improved version of PlainDDS, now capable of a dynamic range of 12 bits instead of the original 6 bits. However the timer limitations stay the same and the deign fails to achieve high frequencies. However, it is still very convenient for many applications. Next is an example of code which generates a fixed frequency signal:

#include <PlainDDS_MCP4921.h>
#include <PlainSPI.h>

PlainDDS_MCP4921 DDS; /* Create DDS object */

/* Blink control led */
void BlinkLed(uint16_t cycles, uint16_t duration) 
{
	const uint8_t ledPin = PIND7;
	uint8_t ledPinMask = (1 << PIND7);
	DDRD |= ledPinMask; 
	PORTD &= ~ledPinMask; 
	for (uint8_t i = 0; i < (cycles << 1); i++)	{
		delay(duration >> 1);
		PORTD ^= ledPinMask;
	}
}

void loop(void)
{
	/**/
}


void setup(void)
{
	DDS.InitializeDDS(PINB2);
	DDS.Frequency(1000.0);
	DDS.WaveType(DDS_WAV_TYP_SINE);
	DDS.Start(STA_MOD_ENABLED);
	BlinkLed(5, 200);
}

… where the most difficult part is probably the LED blinker. As usual, the libraries are available as per the arduinoos policy

Next post on same subject

 

 

PLD (Part 6)

Part 12345, 6

The PLD features a multipurpose connector mainly dedicated to plugging sensors. This video shows how easy it is to configure a PLD an run an application for  monitoring temperatures.

Back us on Kikstarter

Do you want to know more about HL2, HL2 Panorama and HL2 PLD ? Check this video

Thanks for watching

PLD (Part 5)

Part 123456

HL2 PLD may be used for safety applications too. In this configuration, the PLD is able to detect movements up to 7 m away within and almost 90° view angle. It features a PIR (Passive Infra Red) sensor from Panasonic.

This sensors is available in different sizes depending on the required range; the enclosures are available in white or black. On top of these specifications, various power consumptions are available, ranging from 1 µA to 6 µA. This criteria may be critical regarding the applications and the expected battery life time. More reading on this sensor > here <. Few extra component are required to convert the output signal from the sensor to the PLD: actually a N-channel MOSFET and a pair of resistors.

The sensor is encapsulated in a 3D housing which nicely fit the bottom gland from the PLD. In this way, the sensor can be oriented in any direction in the horizontal plane.

HL2 Panorama features all sorts of widgets: gauges, graphs, text, state buttons and tables. In this case, I used a gauge for the power reserve and a state button for the current state: RAS means “Nothing to declare” in French.

The principle of operation is rather simple and prevents sending useless information on the LPWAN networks. As soon as a movement is detected, the PLD sends a “NOK” status. Then, during a fixed period of time, the PLD will count the number of times it senses a movement. On completion of this fixed time, if no event is in progress, it releases a “OK” status along with the number of movements sensed. In this way you are aware about a presence right away, and on completion of the event you get an idea about how frequent where the movements. As the HL2 PLD is arduino ™ compatible, you can start from there and fine tune the code to your own taste !

Using no power line, no network cable and a small compact device will help you to monitor motions in a distance place for years.

Is this what you need ? Pay a visit to our Kickstarter campaign > here <

Would you like to get the STL file for the sensor housing ? > Here < it is and this is how it looks.

Next post on same subject

3D Printing (Part 12)

Part 1234567891011, 12

3D printing can be tiring for the nerves… For a week or so, I was enable to print full size parts without enduring severe problems such as splitting layers, irregular faces and even gaps. Here is an illustration of the prints before the fix (on top) and after the fix.

The first layers where almost alright and the print was going worst and worst: awful ! I carefully and visually checked the printer and found nothing. It was obvious from the beginning that I faced a feeding problem. Usually, these problems come from clogged nozzle, clogged insulator, etc. So I checked and cleaned the whole filament path: no way. I ran a temperature measurement on the heater block: it was just fine. So what ?

I made the decision to install the printer on my desk and watch it working: “Watch out printer, big brother is watching you”. After few minutes, I heard little “klunks” next to the extrude stepper motor, once in a while. I squeezed the filament and felt that the filament was getting one step backward at each “klunk”. As the wheel was perfectly clean (I never had the least problem on this side) and the pressure mechanism free to move, my thoughts were that I was facing a torque problem. Firmly pressing the filament toward the feeder was helping quite a lot and resulted in a significant improvement of the printing quality. So that I decided to increase the current limit for the extruder driver (Check the procedure here) to 2.5 A which is the maximum rating for the stepper motor (Specifications here). In this way, the stepper motor can cope with the back-pressure from the filament being pushed toward the nozzle. Then I made sure that this increase had no dramatic effect on the motor and I checked it operating temperature using a PIR thermometer has shown here.

The stepper motor temperature stays below 60°C which is just fine. And… tadaaa, the problem has gone away !

HTH

PLD (Part 4)

Part 123456

Using the HL2 PLD (Place and Leave Device) is easy and usefull. We ran the earliest tests on… soil moisture. The reason why we chose this one is that I have always liked to have a green plant in my office and this one might last longer than the others. Because it is fitted with great soil moisture sensors connected to a PLD !

I am using a Capacitance-type WATERSCOUT SM100 sensor.

  • Range: 0% VWC to saturation
  • Power Requirements: 3 to 5V @ 6 to 10 mA
  • Output: Analog voltage 0.5 – 1.5V for a 3V excitation (ratiometric for other excitation voltages)
  • Resolution: 0.1% VWC
  • Cable Length: 6 ft (1.8 m) and 20 ft (6 m) standard, extendable up to 50 ft (15 m)
  • Accuracy: 3% VWC @ EC < 8 mS/cm
  • Sensing Area: 2.4 in (6 cm) x 0.8 in (2 cm)

It proved to be a very efficient, simple to use and pretty rugged sensor. The only advice that I may share here is related to the “installation” of the sensor. Water the ground, push the sensor down to the black ring and  tamped down to eliminate air gaps. This is critical regarding the reliability of the measurements.

Next is a picture of the oldest version of HL2 PLD (in grey) next to the PLD as proposed  by HL2 through the Kickstarter campaign.

Ultimately, this is a profile from the soil moisture as shown in HL2 Panorama where you can clearly see the decreasing moisture and the watering along the time.

Next post on same subject