Thursday, December 31, 2015

Au Revoir 2015 (2015 in retrospect )


                   There are only few hours left to say good bye to 2015 and welcome 2016. The whole world is busy getting ready to welcome another new year. I’m pretty sure we all got new hopes ,wishes and challenges to complete in next year and it will be great to realise that we are very fortunate to looking in to 2016 since some of the people who celebrated 2015 with us are no longer with us to celebrate 2016. I thought writing down what I feel about how was my 2015 year went will be a good idea. Someday, may be at the end of 2016 I can look back  at this post and compare how I spent my 2016. I believe it’s always important to improve yourself at least a bit .That’s what make you feel you have achieved something in your life.
                    
                    When I am looking back at how I spend 2015 I can honestly say I was able to improve myself over all. It’s been a great year for my studies at Curtin and I have finished 3 years in my engineering degree and looking forward to start my final year next year. I was fortunate to have great friends who were always helped me in my studies and who always got my back when things aren’t going well. 2015 was my 3rd year in Australia and it’s been great life experience so far. Living in a strange country with people who I never met before was a big challenge and overcoming the obstacles and hardships I went through made me a stronger person. Now I feel I’m ready to face my life all by myself and I’m pretty excited about upcoming years.


                     Spending 3 years as an undergraduate was a great experience. I started studying at Curtin in 2013 and I slowly became good at what I love to do. Engineering was not one of my favourite field until I actually started to learn it and now Engineering has become the love of my life. I believe it’s not just a profession but a way of life if you are serious about it. 2015 was the climax of that as I started to specialise in electrical power engineering. I was fortunate to me lot of smart, brilliant people in electrical engineering field from different cultures, social back grounds and different viewpoints. It really made my experience at university more pleasant and challenging. I recon next year will be more challenging but I’m pretty confident me and my friends are ready to face it and win it.

                       2015 year was an important year even for my personal life. After going through some painful experiences in my life I finally overcame them and started to enjoy being alive and healthy. I realised it’s not the hopes that make you a human being but working hard and constantly adopting to the situation makes you a survivor. Hopes just give you a momentarily pleasure but working towards achieving them gives you more pleasure and satisfaction. At the beginning of every year we determine to change our way of life for the betterment of our selves but only few of us are strong enough to believe in them and chase them. For me it was a mixed experience in 2015. I had couple of things determined to do but I couldn't achieve all of them but I’m happy that I was able to achieve some of the most important things in the list.
                           
                                                 
                          In 2015, I started my internship as a trainee electrical engineer at Western Power, the electrical utility company in Western Australia. It was like a dream come true and I enjoy every morning going there, doing something that actually relate to what I study ,meeting some brilliant people who excel at what they do and taking advices and guidance from them. I’m thankful to my supervisor, Mr. Chathura Karunaratna who gave me the opportunity to work there and always find time to guide me in his busy schedule. My other team mates are also a big help for me at office and especially I want to thank Mr. Charles Mnyanjagha and Mrs.Nadee Jayasekara who are always kind enough to help me. I have been working there since 1st of December and I have two more months there to complete my internship and gather some good professional experience and lots of sweet memories.

                             Sometimes I wonder that I have already spent about 1/3 of my life time and I have become an adult who have some responsibilities. It’s been nice to see my friends have changed so much and doing well. During school time we all were trained to do the same thing without giving much attention to what everyone is capable of. But now I have friends who took different paths in life and enjoying the life and what they do. I’m thankful to every friend of mine who was a part of my life during some stage in my life. We may not meet again but it’s been great to spend time with them and it’ll always be preserved as a good memory.

                               
                                 I would like to thank to my parents, my brother and sister who were always there for me when I need them. 2015 was a year which I understood the importance of family bond to life. It gives me a great pleasure to see the next generation of my family (my 3 nephews) growing well in both physically and mentally. I’m sure our parents and relative must have had the same kind of feelings towards us when we were small kids. I t’s so amazing to see how repetitive is life. So I realised the best way to live life is to live at the moment and enjoying it to the fullest.
 
                                  
                                 No matter what happens life goes on. It’s the way of life. In 31st of December 2016 we’ll look back at 2016 and will have a laugh at about the silly yet lovely stuff we did. It’s good to have hopes but as I said it won’t make a human out of you. In every morning we have 2 choices, stay in bed and keep dreaming or get out of the bed and chase your dreams. It’s up to us to make the correct choice. I wish all of you a happy new year. 2016 will be a new challenge to each one of us but we are defined by how we face them. I feel 2016 going to be an amazing year for myself in both academically and personally and hope same for you.

                                    
                                    And also I would like to thank to people who come here to read my blog. I will do my best to add more useful content to my blog and hopefully everyone who spend their valuable time reading my blog will find something useful to them . I would like to thank you my brother Uchitha Ranasinghe and his friend Mr. Chaminda Serasinghe whose constant feedback give me the courage to write what I know. Hope to see you all in New Year with a good attitudes towards 2016.  












Thursday, December 17, 2015

Control LCD display using shift registers (74HC595N)

This post is pretty much a continuation of my post using shift registers in Arduino projects .Please have a look at it first if you haven’t read it since I assume you are already familiar with how shift registers work and how to use them in a project. Therefore I'm not going to explain how the shift register chip works in this post. As you might already know I was trying to build a robot during my last summer vacation. Unfortunately I had to postpone it  due to lack of technical knowledge and lack of time to learn them .but I'm having a long summer break after another successful year at university and hopefully this time I think I’ll be able to finish what I started. This project is also a side project of that project. My goal was to build an obstacle avoiding robot using Arduino platform. I wanted to use a LCD display to display the distance to an obstacle in real time since it helps a lot in debugging when your Arduino is not connected to the computer and you don’t have access to the serial input readings. But one major problem with that was the number of I/O pins the display required in order to do that. An LCD display wanted at least 6 I/O pins. I had other components like a servo motor (1 data pin) ultrasound distance (2 data pins) measuring unit and my motor controlling unit (4 data pins)  and I couldn't use 0th pin of Arduino board since it deals with the communications of the board . So I ran out of pins. Then this 74HC595N shift register IC came for the rescue. The advantage of using shift register was connecting LCD to Arduino through shift register cost me only 3 pins. That was a huge advantage when it comes to working with micro controllers. However it wasn’t straight forward since the Arduino LiquidCrystal library is not compatible with using shift registers. So I had to find a way to go through it. Fortunately I was able to find this article about how to achieve this.  This is done by using a technology called Serial Peripheral Interface (SPI) which uses a synchronous serial data protocol to communicate with 74HC595 IC. In here Arduino micro controller acts as the master device and shift register acts as the slave device. LCD display is connected to the outputs of the Shift register IC. Then SPI.h and a modified version of conventional LiquidCrystal.h header files can be used to write programs to use LCD display.

The following schematic shows the connection of the components and the connection required are listed below. You should keep in mind to use only compatible LCD displays (Such as Hitachi HD44780) with the LiquidCrystal.h header file.


                      IC Pins (1-8)
                  LCD Display pins
1(Q1)
4(RS)
2
-
3
6 (E)
4-7
11-14
8
GND


LCD Display  Pin
Connection
1
GND
2
+5v
3
10K trimpot variable leg
5
GND
7-10
-
15
+5V through 220 ohms resistor
16
GND

IC pins 9-16
Arduino I/O pins
9
-
10
+5V
11(Sh_CP/SPI clock signal)
13
12(ST_CP/Latch Pin)
9
13
GND
14 (DS/Serial Data input)
11
15
-
16
+5V

Remember to connect the fixed legs of the trimpot (Trimmer/variable potentiometer) to +5V and GND.
The following image is a schematic of the circuit.
Image retrieved from http://42bots.com

After connecting all the components We can replace the old LiqudCrystal.h file with new header file which supports use of shift register. Please go through the following steps to setup the necessary files.
  1. Download this new version of the LiquidCrystal.h from here.
  2. Close Arduino IDE if you are currently using it.
  3. Find the directory where the library folder is located. It should be inside the directory where you install Arduino IDE.
  4. Replace the older version of header file with the newer one.( keep of copy of the older one as a backup )
  5. Open Arduino IDE and Go to Files à Examples à LiquidCrystal and select Hello World SPI.
. If you can see an Arduino sketch it means the new SPI supporting header file has been recognised by the IDE and you are ready to go. Just connect your Arduino board and upload the sketch to board and run it. If you can see the output “Hello world” on your LCD all good (you can replace this to anything you like in the sketch). If it’s not working please check your connections first. Most people (including me) sometimes make wrong connections that causes malfunction or not working at all. Sometimes you might see some random characters on screen . Press reset button few times to get of this and run your code. Now you can use your LCD with Arduino just using 3 pins and saving 3 more precious pins for other components.


Please go to following links since those web pages have lots of useful details about this.

If you need my sketch you can have it from here.










Saturday, December 12, 2015

Challenges to the Power quality of modern electricity grids

It's been a long time since my last post due to a busy semester in  university and my recently started internship but I am looking forward to write more posts in upcoming months since I have some free time due to summer vacation of university. Sharing the knowledge I got from my studies always help me appreciate what I learnt and I think it's my duty to share them as much as possible because in university I realised how important to share knowledge. In almost every unit we used world wide web to learn more often we use textbook. So I think by doing somebody might find it useful.
Today I am going to present you few points about power system quality. This is not a detailed post but rather an entry point to upcoming posts under this topic. I will talk about each and every topic in this post in upcoming posts.

Modern power transmission and distribution is done by using alternative current (AC).  There are several advantages using AC transmission over DC transmission like ability step down or step up voltage as required, Ability to use high voltages in long distance transmission and almost all generators (Synchronous generators) are AC machine is another reason that AC transmission is used. But in recent years HVDC (High voltage DC) technology proved it’s capability for long distance transmission and to connect grids that use different frequency levels are quite useful. We might see HVDC more in future but at the moment all our grids are used to transmit AC.  In an ideal case these currents (including voltages) would be purely sinusoidal waves which have a frequency of 50 or 60 Hz depending on the country.  But this is impossible to achieve as we all aware.  Since the advancements in electronic devices and large demand for power by numerous types of customers on daily basis the utility companies face numerous challenges to keep their power close to the ideal case mentioned above. There are several problems associated with quality of power.
  •         Voltage dips
  •          Voltage swells and spikes
  •          Over  voltages
  •          Harmonics
  •          Variations in frequency
  •          Voltage fluctuations
  •          Voltage unbalance
  •          Supply interruptions
  •      Transient behaviour 

Voltage dips
Voltage dips are decrease in magnitude of the supply voltage for short time period. Voltage dips can happen due to various reasons such as,

  •          Tripping of sensitive protection equipment.
  •          Resetting of large computer systems.
  •          Inductive loading
  •          At the starting of a large inductive motor.

When activating large industrial loads such as large motors, they draw large currents. These are called inrush currents and this happens due to the transient nature of the motor. This causes a sudden voltage drop in line until the load (motor) starts to operate in steady state. This period could be few seconds but during this period other equipment that is connected to same node might not be able to operate. In an industrial site there may be lot of other motor as well that are connected to same node. In order to prevent motors operating under low voltage they can be equipped with under voltage relay protection which isolates the motor if such things happened.

Voltage Swells/Spikes
This is the opposite phenomena of voltage dips. Equipment can be damaged due to failure of insulation, destruction of sensitive electronic devices and electromagnetic interference caused by sudden change in voltage. Voltage spikes are often caused by lightning strikes and during switching operations of circuit breakers.
Voltage abnormalities (Image retrieved from:http://assets.tequipment.net)


Over voltages
Over voltages exceed the nominal voltage of a system over a period of time. They are mainly caused by malfunctioning voltage regulators on generators.

Voltage unbalance
Voltage unbalance occurs due to unbalance loading. Unbalance voltage supply creates zero sequence currents in wires which is responsible of heating the components. This is a serious problem in motor operating. Therefore it’s a common practice to use phase unbalanced relays to detect and unbalance cases and protect the motors against them.





Frequency variations
Frequency variations often happen in isolated networks due to faults and malfunctions of governors in power plants. Frequency variations can cause problems. Motor drives will not work properly, power generation may goes out of synchronism if the frequency has changed a lot from it’s nominal value. This may require isolating generators and reconnect them again. So having the nominal frequency value at all times over the whole network is critical.

Harmonics
A very common problem in power systems is effect of harmonics. The main cause for having harmonics in power systems are power electronic devices such as rectifiers, inverters, uninterruptable power suppliers (UPS) ,variable frequency drives(VFDs) and computers etc... In general any non-linear loads (loads where the voltage waveform is different than current waveform) are responsible for creating harmonics. The effect of harmonics is significant when loads are motors. Harmonics consists of negative sequence voltages which cancel the positive sequence voltages which creates the required flux to operate the torque of the motor. Since a negative sequence component creates a negative flux (which is responsible for creating negative torques) this will reduce the amount of positive torque available to operate the load. Besides negative sequence components, triplet harmonics (3rd 9th 15th) which are responsible for creating zero sequence currents in neutral wire causes heating problems and eventually degrades the machine.   











I suggest the following links might be useful if you need more details.
Harmoincs
In depth details about harmonics and it's effects
Voltage abnormalities

Friday, July 10, 2015

Stability of a control system

Stability is something we all need in our lives .You may have a different perspectives about what exactly meant by being in a stable state but we all have some common aspects about it. In control systems engineering it’s essential to have a stable system otherwise the system will be impractical to setup in real world no matter how elegant is your design. When we are talking about the stability of a control system it corresponds the ability of a system to produce bounded output signals to bounded input signals. When we are talking about bounded signal I would think it as a signal with a finite energy (magnitude).When I first learn about BIBO systems (Bounded Input Bounded Output) I always had a confusion what is actually meant by bounded in real case, especially with the impulse signal .The definition tells us that it has an infinite magnitude at t=0 (when the duration is close to zero) so I wondered how could be the impulse signal is bounded signal but if we relate it to real world cases we can see this concept can model lots of forces like impulse force which acts on a body for a very short time and has a very high magnitude compared to a conventional force . Impulse signals always have a finite energy therefore I consider a bounded signal means the signal has a finite amount of energy, It can’t be infinite. So if a system is a BIBO system it will not produce an unbounded signal to a bounded signal. we only consider about BIBO systems. As well as that, all the systems we consider are LTI system (Linear Time invariant signals) which means that there is only single output to a single input(one to one relation) for all t and if a system has an output value other than zero at t=0 the system is not considered as a linear in control system. Time invariant means the system will produce the same output regardless of the time difference if the inputs and the initial conditions are identical in two instances. I mentioned those concepts here although they are not relevant here since we talk about LTI, BIBO system only.


Before I proceed to talk about the stability of a system it may be good to explain few things about a typical control system. Most of the time all the analysis of control systems are done using transfer functions of real system. Laplace transformation converts all the time varying functions to frequency varying functions in complex domain(s domain) and this transformation make the analysis very easy to carry out. The following diagram shows a typical block diagram of a control system.




Plant: Plant is the system we need to control described as a transfer function(s domain). It would be any physical system and several very different physical systems can be modelled using the same transfer function.
Sensor: The sensor component measures the value of an output specified by the design and sends it as a feedback to the controller.  

Controller:  Controller is a computing device (A computer) that compares the sensor output and reference provided as the input to the system and generates control signals to Actuator using PLCs.

Actuator: A device or a mechanism that controls the plant in a desired manner.
Now back to stability, 

having a stable system is a good and essential thing in control engineering but finding the perfect stable state for a given system will be impossible since we can’t predict how the system will be behaving in future. Any physical system change it’s qualities with time and these changes might cause the system to behave in an unpredictable manner. For example, a motor will not output it desired torque after some years due to mechanical ware and a motor control system might behave unexpectedly if this doesn’t take into account. Therefore rather than using just one stable state engineers design the system with stability margins. So system will be able to handle small parameter changes to input.  This helps to tackle any unpredictability in system and makes it more robust.
How do we determine the stability of a system? The method is easy to understand but very hard to do it without using a computer  most of the time. It’s not that difficult to determine the stability nowadays with the help of advanced computer softwares like MATLAB. But before the arrival of computers people had to find methods to determine the stability of a system by hand. Few methods are listed below. I’m hoping to discuss these topics in future. Each of this method has it’s own pros and cons and becomes handy according the problem you are dealing with.  Although using computer programs are the wildly used method in control engineering, an engineer should have an in depth knowledge about those methods in order to understand and interpret the results.

  • ·         Root locus method.
  • ·         Bode Plots.
  • ·         Nyquist plots.
  • ·         Routh-Hurwitz criterion.

Determining the stability

As I mentioned above in order to assess the stability of a system all we have to know is whether the poles of the system (closed loop) is located at the right or left side of s plane.                                          If all the poles are located in left half plane then the system will be stable.
If a single pole is located on right half s plane then the system will be unstable.
Furthermore if there is at least single multipole on the imaginary axis the system will be unstable.
If there is at least single pole on the imaginary axis then the system is said to be critically stable. It’s on the verge of being unstable.

















Let’s take a simple example .Let G(s) = N(s)/P(s) = 1/(s+2)(s+3) . G(s) is the open loop transfer function . So the poles of the system are -2 and -3. And these values(poles ) are negative and therefore they are located on left half plane of s plane. Therefore the system will be stable. If we convert into time domain this result will be obvious.

By taking partial fractions of G(s),             G(s) = 1/(s+2)- 1/(s+3)

And By taking Laplace inverse of G(s) ,   g(t)= exp(-2t)-exp(-3t). 

So it is obvious when t goes to infinity g(t) will decay in an exponential manner. Therefore this system will be a stable system. But instead of the system poles were +2 and +3 then g(t) = exp(2t)-exp(3t) and when t goes to infinity t this system will produce unbounded (infinite)results, which cause malfunctions in a realistic system.

If above system (g(t)) was connected to a unity feedback system , the system’s new transfer function will be H(s)=G(s)/1+G(s) and all we have to do is to solve the denominator for roots and the roots will be new poles of the system. This 1+G(s) =0 Is called the characteristic equation of the system since it will determine the stability of the system.

In conclusion it is very important to know whether a system will be able to stabilize itself and fortunately there are many tools we can use to verify the stability and the stability margins of the systems. It is an essential aspect in Control engineering .  


Friday, July 3, 2015

Electrical power industry trends in Australia and the problems associated with it

Electrical energy is the main energy type we use in our almost every aspect of our lives. It is impossible to imagine a world without it. Although is a very basic need in modern society most people take it for  granted but generating electricity power and distributing it with a good efficiency to the places where it’s been used is a very complex and carefully designed process. I recently read a report by climate council of Australia (“Australia’s electricity sector: ageing inefficient and unprepared”) and as the title implies it focuses on the matters related to Australia electricity industry and propose the solutions for them .So I thought to share some key points I read in that report and share with you. I personally believe that it’s a responsibility of engineering community to educated general public about how science and technology is important for a better future and for a sustainable development. All the facts and data I go thorough in this article were extracted from that report and all the credit should go to the writer and the climate council of Australia.

Globally the energy sector accounts for the largest proportion of greenhouse gas emissions which is the main cause for climate change around the world as scientists speculate. In order to avoid the effects of climate changes countries have agreed to keep the temperature rise below 2 degrees and in order to achieve this goal every country has to reduce their greenhouse gas emissions it needs large scale changes to how countries produce their electricity and other energy methods.

Figure 1-Global energy related CO2 emission




The above graph shows how the energy sector is responsible for the emission of CO2 one of the main component of greenhouse gases has increased over the time. As the graph shows it is an exponential growth. Coal is the main reason for this and as everybody knows coal is one of the main source for conventional electricity production. Australia places as 9th country in the top ten countries that emit greenhouse gases in electricity production. In 2011/2012 about 91% of Australia’s electricity was generated using fossil fuels.75% of the portion was from coal and 25% from natural gas. Australia’s per capita CO2 emission is the world highest in 2011.So it is obvious that electricity generation in Australia is not ecofriendly as people might think. Australia produces 60% of emissions per MWh than USA. Even Australia is well behind China when reducing the emission of GHG (greenhouse gases) .Over the decade to 2012, China has reduced the GHG emission by electricity up to 16% but Australia was able to reduce that by less than 4%.As a result electricity sector responsible 33% of GHG emissions in Austalia.

Table 1-Global Emitters of CO2



The reason behind this is the way electricity is generated in Australia. As mentioned above coal and natural gas are the main sources used to generate electricity .Coal and gas power plants operates in Australia are getting old. Currently the average age of coal power plants in Australia is over 30 years where it is less than 2 years in the global scale and by 2030 over 65% of coal power plants will be over 40 years old. The age of the plant is an important parameter when it comes to it’s efficiency since an old plant operates on technology which is established over decades ago. The technology related with electricity generation is developing rapidly since these plants operates on low efficiency it becomes very expensive to produce electricity it’s and waste of natural resource. Some might see this is not a problem since we have time but building a megawatt scale power station will take at least a decade to plan, finance and build and operate in the required manner. Various much efficient technologies were introduced during the past decades in order to reduce the Carbon emission from plants but the old power plants are unable to adopt to these relatively new technologies since it’s not economically beneficial and those plants are constructed on old technology hence they are locked down to use that instead of moving to more efficient new technologies. One parameter to measure the emissions from a plant is cycle efficiency. It is determined by the steam temperature and the pressure conditions at the limits of a cycle. These efficiency are divided in to 3 categories, Subcritical, Super critical and ultra-critical. Most Australian coal power stations are subcritical hence they have become one of the least inefficient power stations in world.

Figure 2-Fuel usage for electricity generation in Australia 2012-13




Figure 3-Electricity production in Australia





As people realise the negative effects of using fossil fuel based electricity generation the world is slowly moving towards replacing fossil fuel with renewable energy sources like solar, wind, hydro and fuel cell (H2) technologies. Hydro power is the leading renewable source in the world at the moment. AS it can be seen in above graphs it is the same trend in Australia. In Australia hydro power has supplied 8186MW (16.1% of total capacity) .New South Wales got the biggest portion of hydro power stations (55%). In global scale hydro power has supplied around 15% of electrical energy needs.

Table 2-Hydro power generation distribution worldwide



Wind power is also another emerging renewable source since it’s large reductions in costs associates with installation and equipment .Australia got one of the best wind fields in the world and Australia was able to generate over 6000 GWh in 2012/13 at an average capacity factor of 34%.(Capacity factor measures the ability to extract and store energy from wind by a turbine over a period of time).South Australia is the leading state is wind energy production. It is expected that there would be more 8900 MW of wind energy will be available by 2020 but still Australia is well behind most developed countries.
Solar power is another wildly used renewable energy source. It’s becoming more popular than wind because of it’s domestic use. While coal and other fossil fuels are expected to become expensive in future it’s obvious that solar energy will be less expensive than coal in near future because of the rising demand for solar PV. The advantage of solar is it can act as a distributed power source in houses and commercial premises or it can be scaled up to MW size and feed to the grid.
Over 1 157 000 Australian households had installed 3039 MW of solar PV by 2013. South Australia has the largest proportion of power generated by Solar. Although there is a decline in installing new solar PV in houses due to reductions in Feed in tariff rates it is expected that by 2020 the power generated by solar PV could be doubled. Although household solar PV is a popular alternative to grid power, Australia has only few field scale solar power stations. A 10 MW station at Greenough River in WA and 1MW project at Uterne in Northern territory. Besides these existing projects there are several new projects that are under construction. A 20 MW project at Royalla in ACT. A 102 MW project at Nyngan in NSW. A 3 MW project at Brokenhill.
The popularity of PV has caused them to reduce it’s price and more affordable to households. Furthermore many solar markets around the world getting closer to achieving ‘Socket parity’ point, where it is more economical to produce electricity using solar rather than buying it from the grid. Nowadays it’s more economically beneficial if people use electricity generated by solar for their needs rather than feeding into the grid. Because in that way they will reduce the amount of electricity they consume from grid. One of the major drawbacks of solar PV is it is unable to provide power when it is needed most. In generally the maximum solar insolation is received during noon time but the electrical peak arrives during evening times and most of the time solar power is unable to supply the demand. Therefore households have to use more grid generated power during this period. Therefore solution is to use battery system to store excess energy produced during day time and consume it during peak time. The price of the battery systems are relatively high but it’s becoming cheaper because of it’s popularity and with new battery designs like Tesla Power Wall it has become a worthy investment.    
There is no doubt that sooner or later the whole world has to change their way of producing energy therefore earlier is better. It could be cheaper to use fossil fuels at present but in about 20 years it won’t so nations should start planning and implementing renewable energy plants from now. It is a fact that Australia’s existing fossil fuelled plants can’t compete with renewable energy methods in long term because it’s obvious that price of fossil fuel is becoming higher while the cost of renewable energy solution becoming cheaper. According to the studies wind is the most suitable energy source for Australia along with field scale solar PV.

Table 3-Cost reduction potential for onshore wind systems

Table 4-Cost reduction potential for PV modules and systems


Although Solar, Wind, Hydro and other renewable energy sources are very promising technologies one problem associating with them is they are very sensitive to climate changes. It is very difficult to predict what would be the climate conditions in a region by 10 or 20 years. If the conditions changed dramatically in future the expected output will not be achieved by those plants and the investments done will be wasted. Therefore these aspects has to be taken into account when planning a large scale renewable plants .On the other hand when more renewable sources have been used , governments and other corresponding authorities will be forced to take environment protection more seriously. It will be helpful for a more sustainable and greener development. In conclusion, the fate of future generations in Australia and the rest of the world depends on how we address the energy crisis and take necessary steps to switch to renewable energy. 

References:












Sunday, February 22, 2015

Using shift registers in Arduino projects

If  you are using an Arduino board(like Uno) you get about 12 digital pins for your projects .this number is fairly enough if your  project is a simple one that won’t consume no more than few pins but as the complexity of your projects increase soon you will run out of pins. There are few solutions for this.
  • You can buy a board like mega and expand your number of digital I/O pins.
  • You can use multiplexing/ demultiplexing chips to read and write to pins.
  • You can use shift register chips to expand the I/O pins.

It’s obvious that the first solution shouldn't be your first choice since it will cost you few bucks and it’s probably is not the best solution as well. Eventually you will run out the pins if your project needs more than 54 digital I/O pins .So keep that option ,optional!!!.

Today I’m going to discuss about the 3rd solution I mentioned. I will discuss the 2nd (mux and demux) solution in future when I get a chance. Shift registers are used to expand the I/O capabilities in an electronic circuit. In Arduino domain using only 3 pins of the board and a single chip you will be able to control up to 8 outputs. And by cascading the shift registers you will be able to control thousands of outputs only using 3 arduino pins. In order to do this I have used 74HC595N chip which has 8 outputs. For this instance I used 3 595 chips to control 24 LEDs.

Figure1 74HC595 chip


Figure2-Pin configuration














Q0-Q7   are the output pins that connected to LEDs anode.74HC595 is capable of sourcing current to               LEDs  but there are different chips that use sinking current(current is drawn into the chip)                  method to drive LED. So make sure you check the data sheet if you are not using this chip.

VCC/GND   +5v supply and ground.

DS   serial data input to the chip. This pin is connected to one of the digital output pins in Arduino              and if you cascade several of them, you have to connect the DS pin of the second chip to the                Q7’ pin of the first chip.

OE      output enable .the horizontal piece of line indicates that it’s active low. That means you                      have to make the pin low in order to make the output enabled. So connect that to the                           ground to make that pin low .

ST_CP   storage register clock input .this pin is also called latch pin since it’s the pin that is used to                  transfer the data stored in the chip to the output pins. The value loaded into the chip won’t                    get pass through unless this pin gets a LOW to HIGH transition.

SH_CP  shift register clock input. This pin is used to insert the serial data into the chip register.                         When the pin’s state gets a transition from LOW to HIGH it reads the value of the DS pin                  and sends the value to register.


MR         Master reset.(active low )this pin can reset the whole chip when activated. The values                         stored in the chip will be erased .So connect this pin to +5v supply to avoid resetting the                       chip.

Q7’         This pin is used to cascade several chips together and further expand the outputs.
               Please read the data sheet I provide carefully to understand the functionality and the                            autonomy of the chip better.   And also I have add some links to some youtube videos  that I               referred in order to learn about shift registers. I highly recommend you to watch them to get                 more understanding how this chip works.

Writing the program

There is a function called shiftOut() defined in Arduino to use in shift registers but I will present you another way of implementing the functionality and later I’ll give the code I wrote using shiftOut() function. As a first instance we’ll look how to implement a single shift register.  Use the above diagram to construct the circuit. If you want you may avoid the 1uF capacitor ,it is used to remove the flickering .

Figure3-Circuit Diagram 
















Now we’ll look at the code. I have attached the source file at the end of the post. So you  may have a  look at it or you can use it in your project.

Figure4-Initializing code












Initialising is done as usual in first place. In there I have assigned pins 8,9 and 10 to the serial data pin, clock pin and latch pin of the chip. And also I created an array consists of 24 elements in order to store the status of each LED. It’s type is Boolean ,therefore I can store a HIGH or  LOW  value in each element. time_const  is used to control the speed of the LED on and off. Writereg()  is a function which defined to shift the data into the chip.


Figure5-Writereg() function














At the beginning of the function the latch pin is set to low and at the end (when the data has been transferred to the chip) it is set to high. In that way we can give a LOW to HIGH transition and data has been sent to output pins. As I mentioned  above the clock pin is used to distinguish between data bits .First the clock pin set to low then the data bit is sent to a storage register in the chip .and again clock pin is set to high and this transition stores the bit in storage register this happens in all 3 chips. The first 8 bits stored in the chip which connected directly to the Arduino. When we moved the next  byte to the first chip the previous byte get shifted to the next shift register .Like that we can shift any amount of bytes as long as we have enough chips and the first byte that shifted will be stored in the last shift register that cascaded.  

Using shiftout() function in sketches 


Arduino community has provided a built in function to handle shift functions easily.

Syntax

Shiftout(Data pin,clock pin,bitorder,value)

Data pin -  serial data input  pin of the chip is assigned to this pin.
Clock pin – SHCP pin of the chip is assigned to the this pin.
Bitorder- For this you can assign two values. They are MSBFRIST or MSBLAST .

MSBFIRST 

setup the least significant bit of the value you pass to Q0 pin. For example if you send value 6       (110 in binary) to the shift register, it will be represented as follows,

Q0 – 0
Q1 – 1
Q2 –  1 

LSBFIRST 

This is the opposite of MSBFIRST ,it will assign the LSB bit to Q7 pin and  MSB bit to Q0.

 Most of the time we are only going to use MSBFIRST since it’s much convenient .So if something is not displayed as you wish when you are executing the code try replace MSB with LSB or LSB to MSB that might solve the problem. There is a tutorial in Arduino site that explains this function in more details. Please read that as well.
Shift registers are very useful way to expand the I/O capabilities of your microcontroller. I found about this technique when I was looking for a way to control a LCD display by Arduino without compromising 6 pins. I haven’t tried it yet but I hope to write another about that in some other time. Please use the links I provide below to get to know more about shift registers.

Links


following links are few tutorials I referred in order to learn Shift registers.