Pages

Total Pageviews

Thursday, December 23, 2010

This can be a complete project on its own - a simple DIY digital thermometer with LCD display and only a handful of parts - the PIC18F452, LM35 and a small number of resistors and capacitors running off a regulated 5v supply.
Temperature range - 0 to 150'C
Display type - LCD (can be 16x1, 16x2 or anything larger)
Controller: PIC18F452
Programming Language: BASIC
Compiler: mikroBASIC PRO for PIC v3.20

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
program thermometer452

dim LCD_RS as sbit at RB4_bit
LCD_EN as sbit at RB5_bit
LCD_D4 as sbit at RB0_bit
LCD_D5 as sbit at RB1_bit
LCD_D6 as sbit at RB2_bit
LCD_D7 as sbit at RB3_bit

LCD_RS_Direction as sbit at TRISB4_bit
LCD_EN_Direction as sbit at TRISB5_bit
LCD_D4_Direction as sbit at TRISB0_bit
LCD_D5_Direction as sbit at TRISB1_bit
LCD_D6_Direction as sbit at TRISB2_bit
LCD_D7_Direction as sbit at TRISB3_bit

This can be a complete project on its own - a simple DIY digital thermometer with 7-segment displays and only a handful of parts - the PIC16F88, LM35 and a small number of resistors and capacitors running off a regulated 5v supply.
Temperature range - 0 to 150'C
Display type - 3 digit multiplexed 7 segment or 3 individual 7 segments
Controller: PIC16F88
Programming Language: BASIC
Compiler: mikroBASIC PRO for PIC v3.20

Thursday, December 16, 2010

Single microcontroller based 12v to 230v inverter with intelligent battery charging (Made by me)

Here I describe the circuit as:

*single microcontroller/controller (ATMEGA16/32)
*no op-amps, only chips are the micro, opto-couplers and regulator (7805)
*low-battery/overload/short-circuit protection
*thyristor controlled battery charger, using the MOSFET body diode as the AC-DC rectifier
*charger maintains the battery voltage (top) between 13.2-13.5v (adjustable) to maximize the battery life
*6-LED display
*Only 93 parts in entire control circuit
*Delay between switchover to prevent inrush current

The method used here, described for those who may benefit from it:
-Initialize all ports and peripherals[ADC, Timers, Compare Modules]
-Initialize interrupts for Timer0 and compare module for
-For PWM, use Timer1 and 16-bit Phase and Frequency Correct PWM mode so the PWM runs completely on the hardware level without need for interaction to keep it running
-The AVR senses whether mains is present or not using a standard opto (4N35).
-If mains present, check battery level
-If battery level < 13.5v (this voltage is set using a pot, so can be easily adjusted), charge at the set current(set with a pot)
-If battery level > 13.5v, stop charging
-While battery > 13.2v, stop charging
-If battery voltage drops instantly start charging again
-Triac based, uses Timer0 and compare module with interrupt for phase angle control for fast charge, never overcharges battery, battery hasn't ever heated up till now and 2 year old battery still gives good backup, so charging algorithm is good for battery life
-Check mains
-If mains absent, initialize Timer and start PWM
-Check battery voltage, stop PWM and indicate on LED when battery falls below 10.8v (this is also set with a pot), response time is fast so a short circuit that produces an instant voltage drop is detected
-Check load level, check against preset level (set with pot) and if too high, shut down and indicate
-Check output voltage, adjust as required
-Check mains

This is a quasi-sine wave inverter that I made since it was more demanding than the sine at the time. I have a project with sine as well with a PIC but it's not very organized.

IPS stands for "Intelligent Power Supply", in short the inverter. IPS on means inverter on.
No, they're power MOSFETs. The design here uses IRFZ44N x 5 on each leg for 800W. You can use other MOSFETs as well. I haven't tried though. There are 4 transistors for driving the MOSFETs, on the control board - 2xPN2222, 2xPN2907. There are 2 more transistors on the MOSFET board.
It's 12-30v with changing resistors. For upto 48v, you need to change the 7805 with an auxilary supply, that's the only change.
If battery increases while charging, then there is battery full charged indicator.
Output volt is adjusted to achieve 230V or 220V as required, that is for feedback voltage setting or output voltage setting when running in inverter mode. I set mine at 230V.
Battery max is for battery high cut voltage, to cut off charging when battery reaches a specific voltage. I set mine at around 13.5v.
Charging current is for setting the current at which battery is to be charged. I set mine for 12-15A for 70Ah battery for quick charge.
Overload is for setting the maximum load. A load (800W in this case) is applied while running in inverter mode, and the pot is adjusted slowly till at one point the inverter turns off and the LED shows overload.
Low battery is for setting battery low cut voltage. I set mine for 10.5v.
On the board, the pots are labeled "HI CUT, LO CUT, OVERLOAD, FEEDBACK, CHARGING CURRENT". The one for current is a pot that is adjustable in small units.

The transformer I have is 12-0-12 primary, doesn't need to be accurate, since you can adjust the output voltage using the pot. What I meant is, say you wanted a 12-0-12 transformer, but you got some error, then you can just adjust the preset/pot to set output at 230v. No separate winding, feedback is done on board using diode/cap/resistor and micro. Charging is done using the same MOSFET board, no special capacitor or inductor, just a snubber on the board. Transformer primary is not strict. The one I used has 12-0-12 primary, secondary 0-140-280. 140 is the charger tapping, 280 is the output voltage that is adjusted.

In my circuit, I've tested it numerous time and micro never misfired. Moreover, if you notice the board, you should say a hell lot of .1u ceramic caps, ie, 104pF caps. So since decoupling is so well done, I don't think there will be firing problems. A snubber may be added IF NECESSARY. I've found that the snubber isn't always necessary and gets very hot, so I omitted it, however it may be necessary in some situations so could be added there. This is also one reason I used BTA26, huge triac so that it isn't usually shorted by other factors as I know heat and firing are not issues. All in all, this seems reliable and has run over the last few months under numerous tests.
Yes, MOSFET can be added for a nice design, but I omitted it as it was more demanding to have the MOSFET board separate, in case the MOSFETs burnt. Haven't had a situation till now, but it can easily be made into one nice PCB.

The transformer is rated at 800W power and is a standard transformer used for 800W inverters over here. I don't know about the details as I got it wound by an acquaintance who is an expert in making such transformers. The primary voltage is 12-0-12, secondary voltage is 0-140-280.
This inverter has short circuit protection. It uses the fact that during a short circuit, DC bus voltage significantly decreases. The microcontroller senses that and indicates short circuit.
Reverse voltage protection isn't provided as it's connected to the battery 24/7.

Yes, the battery charging part. My one isn't as complicated. It's a simple charger that doesn't charge the battery to absolutely full charge, but maximum charge so that it can provide optimum backup and good battery life.
The battery is charged at around 16A when near full discharged and charge current slowly decreases to about 10A when battery is near 13.5v, when battery charging is completely terminated to prevent gassing or oxidizing of the plates.
The battery charging is phase angle control based and the charging is stopped every 13 seconds when battery voltage is checked. Then charging is resumed again. I initially implemented trickle charging but later discarded it as I found it unnecessary in this case, because whenever battery voltage falls charging is again resumed for a few minutes to make sure battery is fully charged, or at least apparently fully charged.
I've had the test unit running for 8 months, but the final version as shown in the pictures has been running for about 6 months. The battery has never become hot. Moreover, it was about a year old when I started using this inverter. The battery hasn't inflated yet and provides good backup. I don't even have to replace the water frequently, so that shows that the water isn't vaporizing.
I'm using a 12v 70Ah battery. As mentioned earlier, I can run a 40W fluorescent lamp, 80W ceiling fan and computer (around 250W when not at 100% load) for about 2 hours before the unit indicates low battery. From there it takes about 6-7 hours to fully charge the battery and the charging termination to become stable. Usually after running the inverter with 80W fan and 40W lamp, it takes an hour to get it to full charge.
The unit is designed for 150-250v.

The charging current changes with battery rating. The values mentioned are for 70A battery with initial charging current set manually.

The output voltage here is in the form of pulses not a complete analog value.

Eg. When frequency is 100Hz, duty cycle is 50% and supply voltage to AVR is 5v, then output from AVR pin is 2.5v. However, this does not mean that the output will be 2.5v DC. The output will be a pulsating output with frequency = 100Hz, 50% on, 50% off, with high state or on state voltage = 5v, low state or off state voltage = 0v. Therefore output = 2.5v, but actually 5v with 50% on and 50% off. This CAN be converted to pure DC by placing an RC or LC filter, which will convert the pulsating DC to a clean fixed DC voltage.

I will refer to ATMEGA8 for example, as this seems to be one of the most popular AVRs.

There are 3 timers – Timer/Counter 0, Timer/Counter 1 and Timer/Counter 2. I will refer to Timer/Counter as TC, so TC0 means Timer/Counter 0.

TC0 and TC2 are 8-bit timers. This means that the timers will count from 0 to (2^8) – 1 = 255. TC2 has one associated compare module. TC1 is 16-bit, so it counts from 0 to (2^16)-1 = 65535. It has two compare modules attached and provides a rich set of PWM functions.

I’ll start off with TC0.

TC0 has 4 registers associated with it that we need to work with. The most important is Timer/Counter 0 Control Register – TCCR0.

Take a look at the registers below:

The CS2, CS1 and CS0 bits determine the rate at which the value of the TC increments. Say we have a clock of 10MHz. Therefore we have a clock cycle = T = 1/F = 1/10MHz = 100ns. Prescaler extends this time by a specific amount. So, looking at TCCR0, if we write 0 to it, we have no clock source, this means the TC is stopped and will not increment. It retains its current value.

If we set CS[2…0] to 1, we have no prescaler, that means that the TC increments each 100ns, ie each clock cycle. If we assign prescaler 8, by writing 2 to CS[2…0], we extend the time at which TC increments by 8. With no prescaling it would take 1 clock cycle for each increment, therefore with a prescaler of 8, the time would be extended 8 times, ie, it would now take 8 clock cycles for each increment, ie 800 ns.

The same follows for prescaler values of 64, 256 and 1024.

Eg. With a clock cycle of 10MHz, prescaler = 1024, the time taken by TC0 for one increment is:

The last associated register is TIFR – Timer/Counter Interrupt Flag Register. Here bit 0 is what is associated with TC0. TOV0 = Timer/Counter Overflow Flag 0. This flag is set whenever the timer overflows (this has been shown in the above example). Writing one to this bit clears it.

There's more to come about the Timer PWM modes and Timer1 and Timer2 and all PWM modes.

Recent Posts

Translate this blog

Search This Blog

Follow by Email

About Me

I am Syed Tahmid Mahbub, from Dhaka, Bangladesh, born on August 1, 1994.
Electronics is my passion and from class V, I have been learning electronics. I learnt and worked mostly on SMPS, power electronics, microcontrollers and integration of microcontrollers with SMPS and power electronics. I've used PIC and AVR microcontrollers - PIC 10F, 12F, 16F, 18F, 24F, dsPIC 30F, 33F, PIC32, ATmega and ATtiny, integrating them with various SMPS and power electronics circuits.
I have completed my Bachelor's degree from Cornell University (Class of 2017) in Ithaca, New York, USA, majoring in Electrical and Computer Engineering (ECE).
I am a member of the forum www.edaboard.com, where I am an "Advanced Member Level 5" (the highest level attainable) and also the forum allaboutcircuits.com, where I am a "Senior Member". I post to help solve electronics-related problems of engineers and engineering students from all over the world.
I love watching and playing cricket and football (soccer), and listening to music.
I am now a hardware engineer at Apple in Silicon Valley, California, USA.