Sunday, June 9, 2013

MPPT solar panel controller

PIC16F1782 has got built in almost all components needed to build a switching regulator. I've already tested a possibility of building step down regulator utilizing a microcontroller with "advanced analog peripherals". This time I would like to build a true maximum power point tracking converter for a solar panel. 
My monocrystalline test solar panel is rated with:
Peak Power (Pm) 10W
Open Circuit Voltage (Voc) 21.67V
Short Circuit Current (Isc) 0.61A
Maximum Power Voltage (Vmp) 17.49V
Maximum Power Current (Imp) 0.57A
Maximum power voltage is lower than voltage needed to charge a 12V lead battery so I need a step-down converter:

I found it difficult to arrange which pins should be connected to which signals. There are some alternatives on which pins periferals are connected and it is rather difficult to notice the best arrangement looking only at schematic. It is much easier to notice every possibilities and clashes on a spreadshit like this:

pin






1st 2nd
RA0 2 AN0 CxIN0-




COMP_I
RA1 3 AN1 CxIN1- OPA1OUT



PV_I_SHUNT
RA2 4 AN2 CxIN0+




COMP_I
RA3 5 AN3 C1IN+




PV_I_FBK
RA4 6
C1OUT OPA1IN+



PV_I_SHUNT
RA5 7 AN4 C2OUT OPA1IN-



PV_I_SHUNT
RA6 10
C2OUT




COMP_I
RA7 9


PSMCxCLK




RB0 21 AN12 C2IN1+
PSMCxIN CCP1(2)

STOP_SWITCHING
RB1 22 AN10 CxIN3- OPA2OUT



COMP_V
RB2 23 AN8
OPA2IN-



PV_U_FBK
RB3 24 AN9 CxIN2- OPA2IN+
CCP2(2)

OUT_V_FBK
RB4 25 AN11 C3IN+




COMP_V
RB5 26 AN13 C3OUT




COMP_V
RB6 27




TX(2) ICSPCLK PROG TX
RB7 28




RX(2) ICSPDAT PROG RX
RC0 11


PSMC1A




RC1 12


PSMC1B CCP2(1)

PV_I_SET_PWM
RC2 13


PSMC1C CCP1(1)

PV_V_SET_PWM
RC3 14


PSMC1D




RC4 15


PSMC1E


LED2
RC5 16


PSMC1F


LED1
RC6 17


PSMC2A
TX(1)
DRIVE_HS
RC7 18


PSMC2B
RX(1)
DRIVE_LS
RE3 1






PROG
VDD 20








VSS 8








VSS 19









Thursday, May 30, 2013

Blaupunkt Melbourne 120 vs voltage dip during engine start

I replaced factory-mounted car radio with new fancy Blaupunkt (mostly because of possibility to playback mp3). The radio works fine but I noticed that every time I start-up the engine the radio switches off because of supply voltage dip (engine starter drains lots of current). I try to do ecodriving which includes switching engine off when I expect that I will wait for possibility do drive further more than 1 minute and in such cases radio boots up like another 50...60 seconds of my valuable time. What's funny - there were no such problem with factory-mounted CD30.

I took Melbourne 120 from my, connected to regulated power supply and measured that the Blaupunkt product goes off when voltage falls below 9 Volt. On this picture it still works but it was enough to go 100mV lower to cause reset.

I didn't find anything trustful about car battery voltage during engine start up so I did real-life measurements with my 1.2 liter Opel Corsa. This is battery voltage measured during starting engine. You can notice that voltage falls to about 7 Volts, after around 100ms voltage reaches 9 Volts and than goes rather up.
Avoiding this voltage dip would keep the radio alive during engine start. I came up with such an circuit idea:
There are two ways the radio can be supplied: from the car battery through D1 or from the buffering capacitor C1 through D3. D1 and D3 works so the Blaupunkt will be supplied from the voltage which is momentary higher. During almost all time Melbourne will be supplied through D1 from car battery. C1 will be charged thrugh D2 to voltage which is almost equal to car battery. During engine starting battery voltage will fall down but thanks do D2 C1 will not be discharged. When car battery voltage is lower than C1 + 1.4 Volt the radio will be supplied from C1. Of course it will take a moment to discharge C1 but this is only matter of 100ms for battery voltage to go above 9 Volt again. 

Now, let's calculate C1 value to find out if it such solution is possible. From definition of capacitance:
C=Q/U
Definition of current is:
I=Q/t 
which can be transformed to
Q=tI
lets put Q intu definition of capacitance and we get:
C=tI/U
Where:
C is capacitance
t is discharge time
U is voltage drop across capacitor.

Let's calculate what voltage drop do we accept: before engine startup voltage across battery is around 12.4 Volt, on C1 voltage will be 0.7 Volt lower due to D2 so 11.7V. To keep Melbourne alive voltage across C1 must be higher than 9 Volt + 0.7 Volt so C1 voltage at the end of discharge is 9.7 Volt. 11.7 - 9.7 Volt = 2V.
Time read from oscillogram above is around 100ms, after 100ms voltage on car battery will raise and will be high enough to supply the radio. Let's assume that during this time the radio will be consuming 2 Amper.
C=0.1[s] 2[A] / 2[V] = 0.1[F]
So we are looking at 0.1 Farad capacitor with voltage rating of minimum 16 Volt. Conventional electrolytic capacitor would be huge so I looked for so called ultracaps aka goldcaps.

After short searching I decided to choose Su'scon 5.5F 2.5V. I had to use 6 capacitors in series to achieve voltage rating of 15V which is barely enough to install it in a car. I choose capacitors which have values 50 times bigger that my calculations say, it is not because I distrust my calculations - the only one and simple reason is that this capacitors were cheap. You may be tempted to choose 5V ultracapacitors but be aware - usually they are designed to backup RTC and some memory and they have high ESR value (what basically means that they can't provide too much current). 
Plug and play - My circuit is equipped with male and female ISO connector so it can be simply connected between the radio and original cable harness. 
Here is my prototype ready to go:


It works!
I connected it and surprisingly inrush current didn't blow a fuse. I didn't even bother to look at fuse and see what its rating, I just assumed that there has to be some fuse on radio supply line (and another in the Balupunkt itself). SO far I had no time to make exact measurements and test what does voltage look like but one is for sure - it works, I can start up the engine and Melbourne 120 works without any interruption.

One more thing has to be measured - leakage current. I tired to test it with my desktop power supply but with no success. To do such a measurement you need really stable voltage, in case of 5F each millivolt of voltage change causes flow of couple of hundreds of uA needed to charge or discharge the capacitor (depending on direction of this voltage change)


Tuesday, November 13, 2012

PIC16F1503 based MPPT controller for photovoltanic system


Once I found a really simple MPPT circuit on Chris' website: http://www.freewebs.com/acselectronics/buildppt.html I decided to build something inspired by his work. I always wanted to build a switching regulator based on a general purpose simple (and cheap!) microcontroller instead of specialized switching controller. I choose PIC16F1503 because it has got build in two comparators, PWM (maybe not very sophisticated but fully functional) and CWG - new peripheral from Microchip which can be used to generate dead-band time between two outputs.
My first goal was to build something as “prove of concept” so it is not a real MPPT controller because it doesn't measure a PV cell current, but it adjusts load of the PV cell to make sure it works with given output voltage. Here is circuit diagram:
It's actually simple step-down converter with P-channel MOSFET (I decided to use P-channel because it allows use of common ground to measure input and output voltage). Load of this circuit will be a lead-acid battery so I added D3 to make sure that circuit will not discharge battery. D3 introduces lose of efficiency so right now I'm thinking about other fancy circuit which will do that better (with lower voltage loss across itself).
Here is an idea how microcontroller is configured to control switching regulator with its peripherals:
This is straight-forward implementation of switching regulator but implemented in a microcontroller, after initialization of FVR (Fixed Voltage Reference), PWM, comparator and CWG (complementary waveform generator) it works and software can do something else. And it will do: I plan to implement perturb and observe algorithm to search for maximum power condition of PV cell. I plan to introduce some changes to Circuit: I have to add PV cell current measurement. I also have to add another PWM with RC filter as a source of voltage of comparator. PIC16F1503 allows me to use a DAC output as a input signal for comparator but DAC is 5-bit only, it is to small resolution for effective MPPT tracking.
Another improvement will be second MOSFET instead of D4 to increase efficiency. Due to a simplicity of MOSFET driver circuit off-time is longer than I want so I will search for some improvement, maybe totem-pole circuit?

Here is a waveform on pin 6 of microcontroller (channel 2) and gate of MOSFET (channel 1), it is clearly visible that there is much to improve, especially switch-off time.  


Here is picture of a circuit itself during early tests:
It's built on one-side substrate to minimize costs, why should I order PCB in a fab if I know that circuit will anyway need changes?

Here is PCB design, as usually I have to show off how nice PCBs I draw. I used SMD components wherever it was convenient. I even managed to design whole PCB on one layer without a single wire-bridge.  
I will update this post or I will write the new one when I will build next version of this circuit with mentioned improvements.



The software "as it is"

#include <pic.h>

__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_ON & CP_OFF);


void main(void)
{
    OSCCONbits.IRCF=13; //4MHz

    ANSELA &= ~(1<<2);
    TRISA &= ~(1<<2);   //konfigurj LEDa
    PORTA &= ~(1<<2);   //zgas LEDa


    PWM1CON=0;
    PR2=9;           //40 us
    PWM1DCH=7;
    PWM1DCL=1<<7;


    TMR2IF=0;
    T2CONbits.T2CKPS=1; //prescaler /4
    T2CONbits.TMR2ON=1;
    PWM1CONbits.PWM1OE=1;
    PWM1CONbits.PWM1EN=1;
    TRISC &= ~(1<<5);


    FVRCONbits.CDAFVR=1; //4.096V
    FVRCONbits.FVREN=1;  //enable



    ANSELA |= (1<<7);    //comparator
    TRISC |= (1<<3);
    CM1CON1bits.C1PCH=2; //positive input to FVR (1.024V)
    CM1CON1bits.C1NCH=3; //ngative input to C2IN3-
    CM1CON0bits.C1ON=1; //on


    TRISC &= ~(1<<4);  //konfiguruj wyjscie do sterowania mosfetem
    PORTC &= ~(1<<4);
    CWG1CON0bits.G1EN=1;    //wlacz
    CWG1CON0bits.G1OEB=1;   //w?acz wyjscie
    CWG1CON0bits.G1POLB=1;  //inwersja na wyjsciu
    CWG1CON1bits.G1ASDLB=2; //zero w auto shot down
    CWG1CON1bits.G1IS=2;    //na wejsciu jest PWM
    CWG1CON2bits.G1ARSEN=1; //auto restart enabled
    CWG1CON2bits.G1ASDSC1=1; // comparator 1 

    while(1)
    {

        
        if(CMOUTbits.MC1OUT)
            PORTA |= (1<<2);  //wlacz leda
        else
            PORTA &= ~(1<<2); //zgas LEDa
    }
}


Tuesday, November 6, 2012

How to fix Mercedes W201 180 fuel pump controller (so called relay)


A fuel pomp relay switches fuel pump for a definite time (usually about 2 seconds) after the ignition have been switched on to make sure that pressure in fuel system is high enough. This can be easily heard as you are starting your car. The relay also detects crankshafts rotations by monitoring signal from primary winding of a ignition coil, so when you turn on a starter the fuel pomp is immediately switch on stays on as long as the engine is running. Here is PCB of that “relay”:
  And here is a closeup of tracks which conducts fuel pump current, I marked this particular two tracks:
Here is solution for the mentioned problem:
I don't know if the same problem occurs in other relay types but i suggest trying to fix it before you buy another one. If the layout of other relay is similar to this it can and it will cause a similar problem. If you have problem with starting your Mercedes you can check if it's a matter of fuel pomp switch by connecting terminals 30 and 87, you can even leave it that way but I wouldn't recommend this solution. In case of an accident - when engine is stopped fuel pomp should be also stopped to prevent fuel leak, if you will “short connect” fuel pomp - it will not.

Thursday, November 1, 2012

SMS 7-bit encoding doubts in Open AT


Right now I'm writing some software for Sierra Wireless GSM Module - Q2687. This application is written with open AT library supported by GSM module vendor and have to handle special characters in SMS messages. I've set text mode for receiving SMS and started sending messages containing characters from basic characters set extension (see GSM 03.38). I was expecting to receive special character encoded according to this table:
It turns out that this characters are encoded completely different. Neither ESCAPE TO EXTENSION TABLE nor that second byte is like in presented table. I found out that encoding is rather like this:

Hex Dec Character name Character
0x20 32 ESCAPE TO EXTENSION TABLE

0x2020 32 32 CIRCUMLFLEX ACCENT ^
0x2028 32 40 LEFT CURLY BRACKET {
0x2029 32 41 RIGHT CURLY BRACKET }
0x202F 32 47 BACKSLASH \
0x203C 32 60 LEFT SQUARE BRACKET [
0x203D 32 61 TILDE ~
0x203E 32 62 RIGHT SQUARE BRACKET ]
0x20AD 32173 VERTICAL BAR |

As you can see - something is definitely not the way it should be. Look at VERTICAL BAR encoding - it isn't event coded on 7 bit characters, so what encoding it is? I don't know yet but I have to simply implement conversion (which is quite easy to code) before I will treat received SMS with cstring functions.
I tested this situation with messages sent with Android-based mobile as also with plain old Nokia C1.

If you are familiar with Open AT you can test it on your own:

void SmsCtrlHandler(u8 Event, u16 Nb)
{

}

bool SmsMessageHandler(ascii * SmsTel, ascii * SmsTimeOrLength, asii * SmsText)
{
u16 i=0;

while(i<strlen(SmsText))
TRACE((1,”SmsText[%d]=0x%X”, i, SmsText[i])); //display received message byte by byte
return FALSE;
}

s8 smsHandler;
smsHandler = ald_smsSubscribe(SmsMessageHandler, SmsCtrlHandler, ADL_SMS_MODE_TEXT);






Monday, October 22, 2012

How much can DRL lights improve fuel consumption?


Lets say that DRL lights power consumption is about
PDRL = 10[W].
Alternatively you can drive with “normal” lights on, that is: a front low beam + rear position lamps and registration plate lamps (in my case H7, R5W, W5W respectively)
PNORM=2*55+2*5+2*5[W] = 130 [W],
we have omitted dashboard back-light but it shouldn't introduce too much error.
Volume of fuel V with energy density Ed needed to supply power P in time t is given by
where ηtotal is total efficiency.
Distance S is:
S = vt
where v is speed. We can also write:
lets insert t in the first fraction and we get:
Efficiency ηtotal is product of a engine efficiency ηengine, and a belt and alternator efficiency ηbalt
If we want to calculate the volume fuel difference we should insert power difference into formula so:
Lets assume that belt and alternator efficiency is
ηbalt = 50%.
In case of diesel engine
Ed = 37.3[MJ/ltr]
let also assume peek diesel engine efficiency
ηengine = 40%
The table shows fuel consumption at different speeds calculated according to presented assumptions calculated with formula (*)

In case of petroleum engine

Ed = 34.0[MJ/ltr]
and peek engine efficiency about
ηengine = 30%.
In real life we can expect much lower engine efficiency, depending on various conditions you can expect larger numbers, it is larger fuel savings. 

Wednesday, October 17, 2012

Profiling energy usage in a household


Energy consumption in my parents house is about 300 kWh per month. We have replaced incandescent light bulbs couple of years from now and we are systematically replacing fluorescent lamps with LED lamps because they consume even less power that fluorescent. We are moving toward energy-saving technologies. We are using solar water heater instead of electric boiler and whole house is equipped with improved thermal insulation. We live in central Europe so in winter it is nothing exceptional when you see -20 Celsius degrees (-4 Fahrenheit).

Yesterday I did a little experiment. When everybody was sleeping I switched off freezer, all computers and TVs, by switching off I mean pulling a plug from a socket. I was wondering how much current do consume devices which are switched on all the time, this devices are:
-microwave oven with nice shiny LED clock display
-conventional electric oven with another shiny LED clock display
-wi-fi router and power-over-ethernet power supply
-amplifier for a TV aerial
-electric stove (it was of course on idle)
-vent hood in a kitchen

We use an old plain electricity meter without digital display so to make total current consumption I had to use stopwatch to measure how much time does it take for a wheel inside the meter to make a whole turn. It was 312 seconds. Considering that 120 turns correspond to a 1kWh I calculated that a total idle power consumption of mentioned devices was around 96W. That is much energy. 96W 24/7 is around 70kWh per month. Idling devices are responsible for a 23% of power on a electricity bill.



Yeah, now I simply have to find out which devices are responsible for a most of this 23% and simply switch them off as often as possible. This devices:
-wi-fi router and power-over-ethernet power supply
-amplifier for a TV aerial
are on an attic and they are not_so_easy_accessible, so to ease my experiments I used a remote controller to switch them off without going to the attic. When I will repeat whole house idle consumption measurement with couple of devices switched off I will easily find power consumption of this two first suspects. I took a look inside the remote receiver, it has got transformerless power supply and it consumes about 1/2W so it will not introduce considerable errors to my measurements.