Arduino UNO as in circuit programmer for AVR

How to use Arduino as AVR programmer
Atmega series Micro controllers  have several benefits like its open source, easy to use, available in a large different types, cheap and most important one, it is easy to begin. It have wide variety of boards available called arduino which are easy to start things. Specially if you are programmer and know a little about electrical then it is a blessing for you. Although it can help you to begin but these are not appropriate for Electrical engineers as they have a lot of essential things skipped or being done under the hood. But still it is of great help if you start with Arduino, so I come with a "cost effective" solution. Yeah! I find out a way to use Arduino programmer to program Atmega Micro controllers. So start with Arduino and slowly switch down to atmega. You don't need a stand alone programmer. So in short, 2 in 1 package.



>> Pre Requisites: Installed WinAVR and compiled hex file of the code
Step 1:
See board configuration. Note Com port number and Programmer.




Step 2:
Choose ArduinoISP from examples and burn it on Arduino.

Step 3:
Connect circuit like this
pin name:    not-mega:         mega(1280 and 2560)
slave reset: 10:               53
MOSI:        11:               51
MISO:        12:               50
SCK:         13:               52


Step 4:
Open command prompt and write AVRdude (It will be already installed if you have installed WinAVR ) otherwise install it and open command prompt and write following command…
avrdude -p m8 -P com11 -c avrisp -b 19200
>> Here after –p is name  of Microcontroller.

Following are atmegas and their name for avrdude command
Valid parts are:
  t10  = ATtiny10        [C:\WinAVR-20100110\bin\avrdude.conf:15443]
  t8   = ATtiny9         [C:\WinAVR-20100110\bin\avrdude.conf:15403]
  t5   = ATtiny5         [C:\WinAVR-20100110\bin\avrdude.conf:15363]
  t4   = ATtiny4         [C:\WinAVR-20100110\bin\avrdude.conf:15323]
  ucr2 = 32UC3A0512      [C:\WinAVR-20100110\bin\avrdude.conf:15302]
  x128a4 = ATXMEGA128A4    [C:\WinAVR-20100110\bin\avrdude.conf:15204]
  x64a4 = ATXMEGA64A4     [C:\WinAVR-20100110\bin\avrdude.conf:15107]
  x32a4 = ATXMEGA32A4     [C:\WinAVR-20100110\bin\avrdude.conf:15010]
  x16a4 = ATXMEGA16A4     [C:\WinAVR-20100110\bin\avrdude.conf:14913]
  x256a3b = ATXMEGA256A3B   [C:\WinAVR-20100110\bin\avrdude.conf:14816]
  x256a3 = ATXMEGA256A3    [C:\WinAVR-20100110\bin\avrdude.conf:14719]
  x192a3 = ATXMEGA192A3    [C:\WinAVR-20100110\bin\avrdude.conf:14622]
  x128a3 = ATXMEGA128A3    [C:\WinAVR-20100110\bin\avrdude.conf:14525]
  x64a3 = ATXMEGA64A3     [C:\WinAVR-20100110\bin\avrdude.conf:14428]
  x256a1 = ATXMEGA256A1    [C:\WinAVR-20100110\bin\avrdude.conf:14331]
  x192a1 = ATXMEGA192A1    [C:\WinAVR-20100110\bin\avrdude.conf:14234]
  x128a1d = ATXMEGA128A1REVD [C:\WinAVR-20100110\bin\avrdude.conf:14137]
  x128a1 = ATXMEGA128A1    [C:\WinAVR-20100110\bin\avrdude.conf:14040]
  x64a1 = ATXMEGA64A1     [C:\WinAVR-20100110\bin\avrdude.conf:13943]
  m6450 = ATMEGA6450      [C:\WinAVR-20100110\bin\avrdude.conf:13754]
  m3250 = ATMEGA3250      [C:\WinAVR-20100110\bin\avrdude.conf:13565]
  m645 = ATMEGA645       [C:\WinAVR-20100110\bin\avrdude.conf:13376]
  m325 = ATMEGA325       [C:\WinAVR-20100110\bin\avrdude.conf:13187]
  usb82 = AT90USB82       [C:\WinAVR-20100110\bin\avrdude.conf:13007]
  usb162 = AT90USB162      [C:\WinAVR-20100110\bin\avrdude.conf:12823]
  usb1287 = AT90USB1287     [C:\WinAVR-20100110\bin\avrdude.conf:12634]
  usb1286 = AT90USB1286     [C:\WinAVR-20100110\bin\avrdude.conf:12445]
  usb647 = AT90USB647      [C:\WinAVR-20100110\bin\avrdude.conf:12257]
  usb646 = AT90USB646      [C:\WinAVR-20100110\bin\avrdude.conf:12068]
  m32u4 = ATmega32U4      [C:\WinAVR-20100110\bin\avrdude.conf:11880]
  t84  = ATtiny84        [C:\WinAVR-20100110\bin\avrdude.conf:11697]
  t44  = ATtiny44        [C:\WinAVR-20100110\bin\avrdude.conf:11515]
  t24  = ATtiny24        [C:\WinAVR-20100110\bin\avrdude.conf:11333]
  m128rfa1 = ATMEGA128RFA1   [C:\WinAVR-20100110\bin\avrdude.conf:11145]
  m2561 = ATMEGA2561      [C:\WinAVR-20100110\bin\avrdude.conf:10951]
  m2560 = ATMEGA2560      [C:\WinAVR-20100110\bin\avrdude.conf:10758]
  m1281 = ATMEGA1281      [C:\WinAVR-20100110\bin\avrdude.conf:10570]
  m1280 = ATMEGA1280      [C:\WinAVR-20100110\bin\avrdude.conf:10381]
  m640 = ATMEGA640       [C:\WinAVR-20100110\bin\avrdude.conf:10193]
  t85  = ATtiny85        [C:\WinAVR-20100110\bin\avrdude.conf:10012]
  t45  = ATtiny45        [C:\WinAVR-20100110\bin\avrdude.conf:9833]
  t25  = ATtiny25        [C:\WinAVR-20100110\bin\avrdude.conf:9653]
  pwm3b = AT90PWM3B       [C:\WinAVR-20100110\bin\avrdude.conf:9472]
  pwm2b = AT90PWM2B       [C:\WinAVR-20100110\bin\avrdude.conf:9289]
  pwm3 = AT90PWM3        [C:\WinAVR-20100110\bin\avrdude.conf:9106]
  pwm2 = AT90PWM2        [C:\WinAVR-20100110\bin\avrdude.conf:8922]
  t2313 = ATtiny2313      [C:\WinAVR-20100110\bin\avrdude.conf:8735]
  m328p = ATMEGA328P      [C:\WinAVR-20100110\bin\avrdude.conf:8547]
  t88  = attiny88        [C:\WinAVR-20100110\bin\avrdude.conf:8361]
  m168 = ATMEGA168       [C:\WinAVR-20100110\bin\avrdude.conf:8173]
  m88  = ATMEGA88        [C:\WinAVR-20100110\bin\avrdude.conf:7987]
  m48  = ATMEGA48        [C:\WinAVR-20100110\bin\avrdude.conf:7800]
  t861 = ATTINY861       [C:\WinAVR-20100110\bin\avrdude.conf:7612]
  t461 = ATTINY461       [C:\WinAVR-20100110\bin\avrdude.conf:7423]
  t261 = ATTINY261       [C:\WinAVR-20100110\bin\avrdude.conf:7234]
  t26  = ATTINY26        [C:\WinAVR-20100110\bin\avrdude.conf:7077]
  m8535 = ATMEGA8535      [C:\WinAVR-20100110\bin\avrdude.conf:6919]
  m8515 = ATMEGA8515      [C:\WinAVR-20100110\bin\avrdude.conf:6761]
  m8   = ATMEGA8         [C:\WinAVR-20100110\bin\avrdude.conf:6600]
  m161 = ATMEGA161       [C:\WinAVR-20100110\bin\avrdude.conf:6460]
  m32  = ATMEGA32        [C:\WinAVR-20100110\bin\avrdude.conf:6285]
  m6490 = ATMEGA6490      [C:\WinAVR-20100110\bin\avrdude.conf:6092]
  m649 = ATMEGA649       [C:\WinAVR-20100110\bin\avrdude.conf:5907]
  m3290p = ATMEGA3290P     [C:\WinAVR-20100110\bin\avrdude.conf:5724]
  m3290 = ATMEGA3290      [C:\WinAVR-20100110\bin\avrdude.conf:5539]
  m329p = ATMEGA329P      [C:\WinAVR-20100110\bin\avrdude.conf:5354]
  m329 = ATMEGA329       [C:\WinAVR-20100110\bin\avrdude.conf:5170]
  m169 = ATMEGA169       [C:\WinAVR-20100110\bin\avrdude.conf:4990]
  m163 = ATMEGA163       [C:\WinAVR-20100110\bin\avrdude.conf:4832]
  m162 = ATMEGA162       [C:\WinAVR-20100110\bin\avrdude.conf:4636]
  m1284p = ATMEGA1284P     [C:\WinAVR-20100110\bin\avrdude.conf:4446]
  m644p = ATMEGA644P      [C:\WinAVR-20100110\bin\avrdude.conf:4254]
  m644 = ATMEGA644       [C:\WinAVR-20100110\bin\avrdude.conf:4064]
  m324p = ATMEGA324P      [C:\WinAVR-20100110\bin\avrdude.conf:3873]
  m164p = ATMEGA164P      [C:\WinAVR-20100110\bin\avrdude.conf:3682]
  m16  = ATMEGA16        [C:\WinAVR-20100110\bin\avrdude.conf:3504]
  c32  = AT90CAN32       [C:\WinAVR-20100110\bin\avrdude.conf:3313]
  c64  = AT90CAN64       [C:\WinAVR-20100110\bin\avrdude.conf:3123]
  c128 = AT90CAN128      [C:\WinAVR-20100110\bin\avrdude.conf:2933]
  m128 = ATMEGA128       [C:\WinAVR-20100110\bin\avrdude.conf:2755]
  m64  = ATMEGA64        [C:\WinAVR-20100110\bin\avrdude.conf:2574]
  m103 = ATMEGA103       [C:\WinAVR-20100110\bin\avrdude.conf:2434]
  8535 = AT90S8535       [C:\WinAVR-20100110\bin\avrdude.conf:2313]
  8515 = AT90S8515       [C:\WinAVR-20100110\bin\avrdude.conf:2199]
  4434 = AT90S4434       [C:\WinAVR-20100110\bin\avrdude.conf:2116]
  4433 = AT90S4433       [C:\WinAVR-20100110\bin\avrdude.conf:1992]
  2343 = AT90S2343       [C:\WinAVR-20100110\bin\avrdude.conf:1868]
  2333 = AT90S2333       [C:\WinAVR-20100110\bin\avrdude.conf:1740]
  2313 = AT90S2313       [C:\WinAVR-20100110\bin\avrdude.conf:1627]
  4414 = AT90S4414       [C:\WinAVR-20100110\bin\avrdude.conf:1514]
  1200 = AT90S1200       [C:\WinAVR-20100110\bin\avrdude.conf:1399]
  t15  = ATtiny15        [C:\WinAVR-20100110\bin\avrdude.conf:1266]
  t13  = ATtiny13        [C:\WinAVR-20100110\bin\avrdude.conf:1093]
  t12  = ATtiny12        [C:\WinAVR-20100110\bin\avrdude.conf:960]
  t11  = ATtiny11        [C:\WinAVR-20100110\bin\avrdude.conf:896]

>> Then after –P  are name of com port on which your Arduino is connected.
>>After –c  is name of compiler which in this case is avrisp or you can also Arduino 

If screen like following appears then it means your Arduino is ready to use like programmer..


Now you can burn your code using following command
$ avrdude -p m8 -P com11 -c avrisp -b 19200 -U flash:w:main.hex


Possible errors:

1)Device signature not found. Once it was 0 ×ffffff which is possibly due to dead chip and another time it was 0 ×00000 possibly due to external or internal oscillator 

A simple Digital CRO (exaggeration)

A simple Digital CRO using Arduino
Idea behind this simple concept is to use Arduino’s serial communication and MATLAB’s serial port function to draw a signal on your computer.  So for generation of signal, I simply use a photo resistor that will vary input voltage according to light incident on it. Arduino code is as below..
Arduino code:
//This code is used to generate a signal and then signal in converted into digital using sampling...
/* Simple Digital CRO using MARTLAB to draw signals. This signal will be sent on com11 pot where MATLAB will read it and plot it..
----------------------------------------------------

           PhotoR     10K
 +5    o---/\/\/--.--/\/\/---o GND
                  |
 Pin 0 o-----------

----------------------------------------------------
*/

int SensorPin = 0;  //define a pin for Photo resistor


void setup()
{
    Serial.begin(9600);  //Begin serial communcation
   
}

void loop()
{
    Serial.println(analogRead(SensorPin)); //Write the value of the photoresistor to the serial monitor.
  
}

MATLAB code:
clear all
clc

arduino=serial('COM11','BaudRate',9600);

fopen(arduino);

x=linspace(1,100);
  
for i=1:length(x)
    y(i)=fscanf(arduino,'%d');
end
   
fclose(arduino);
disp('making plot..')
plot(x,y);

Results:

Some other results:

A servo motor input from controller mapped in simple DCRO
Pulse train


Limitations: 
This is not very precise 'cause we are just using digital pins of ARDUINO, if we use analog pins, and sampling with baud rate of 9600 can give us even more precise output. 

These results were tested when input is no more than 5 volt (Maximum Voltage arduino can bear), if we wanna make it to test for any voltage we need some circuitry to limit current and voltages just as we use in Multi meter. 

Possible errors:


Solution:
Don’t use any device that uses serial pin on which arduino is connected. Like don’t open serial monitor of  ARDUINO IDE like this..
Also take care of  baud rate and  also select correct port both in Arduino IDE and MATLAB code. You  can check port number where arduino is connected using device manger.




Average Monthly energy from solar Insolation for Gujranwala


Estimated Energy Delivered by a 1-kW (dc, STC) PV Array in Gujranwala, Using Average Maximum Monthly Temperatures to Compute Performance Degradation.

Monthly Temperature for Gujranwala:




It was considered that with every increase in 1C temp, dc power decreases by .5%
Month
Insolation
(kWh/m^2-day)
Avg Max
Temp(◦C)
Cell Temp .(◦C)
Array dc
Power
(kW)
Array ac
Power
(kW)
Energy
(kWh/mo)
January
2.6
19.1
52.85
0.86075
0.721377
684.58711
February
3.76
22.1
55.85
0.84575
0.708806
972.76557
March
5.05
27.4
61.15
0.81925
0.686597
1265.57
April
6.01
33.7
67.45
0.78775
0.660198
1448.2423
May
7.13
39
72.75
0.76125
0.637988
1660.3329
June
6.99
40.8
74.55
0.75225
0.630446
1608.4876
July
6.47
36.1
69.85
0.77575
0.650141
1535.3394
August
5.88
34.6
68.35
0.78325
0.656426
1408.8218
September
5.57
35
68.75
0.78125
0.65475
1331.1395
October
4.75
33
66.75
0.79125
0.663131
1149.703
November
3.65
27
60.75
0.82125
0.688273
916.95197
December
2.9
21.2
54.95
0.85025
0.712578
754.2633











Refrences:

Temperature:  http://en.wikipedia.org/wiki/Gujranwala

Study tour of AA Spinning Mill Faisalabad

Study tour of AA Spinning Mill Faisalabad 

Our institution recently organized a study tour of AA spinning mill Faisalabad plant as a part of learning. It was such a wonderful experience to see things being practically implemented what we studied so far as a electrical engineer. Mill is situated 20 km away from Faisalabad in a industrial zone, surrounded by a lot of other fabric mills. This area is also famous for its textile industry and also called Manchester of Pakistan.
Main Website: http://aaspinning.com/


This mill currently producing only Fabrics, have their own small grid, gas power plant and a spinning shed and a electronic lab. Let's look at outline of the mill.


So in short, mill's small grid station is connected with  132 kV lines of FESCO, which is then converted to a 11kv by power transformer. Then there is a power house having 5 gas operated generators having capacity of generating 5 MW. Both FESCO supply and generator's supply is synchronized and send to transformer of mill  where voltages are again step down to 440 V and fed to mill. Now let's see a summary of spinning section. There is Cotton godowm, where cotton from market is placed and cleaned by both manually and by machinery. After proper cleaning and  processing, it is sent to Spinning shed where it is used to make fabrics by machinery. According to head Textile engineer, this is first fully automated textile mill of Pakistan and. There is also a electronics lab, so this mill have capability to solve electronics related problems (circuit maintenance). According to Head Electrical Engineer, they have capability of solving 99.9% electronics related problem of the mill in this lab.
Now lets look at the Mill in detail.

A comprehensive view of AA Spinning Mill Ltd

We will see mill in 4 parts, power transformation, power generation , spinning section and electronics lab.

1)Power Transformation

Grid Station:

Mill was taking 132 kV supply form FESCO feeder but 132 kV very high voltage and it is not usable for any machinery so they need to step down it. As stepping down 132 kV is very dangerous so it requires safety measures, in other words only a transformer is not enough but you also require some sort of safety precautions so they made their own small grid station which was almost exact replica of original gird station. So let's first look at a typical grid station.
Elements of a substationA:Primary power lines' side B:Secondary power line1.Primary power lines
2.Ground wire
3.Overhead lines
   4.Transformer for measurement of electric voltage
5.Disconnect switch
6.Circuit breaker
7.Current transformer
 8.Lightning arrester
9.Main transformer
10.Control building
11.Security fence
    12.Secondary power lines[Wikipedia]
So you can see a lot components here explaining a simple grid station. Real thing that converts 132kV into 11 kV is Power transformer which is 9 and called main transformer. Other components are just for precautionary  and safety measures or metering purposes.
Points to be noted :Substations generally have switching, protection and control equipment, and transformers. In a large substation, circuit breakers are used to interrupt any short circuits or overload currents that may occur on the network. Smaller distribution stations may use recloser circuit breakers or fuses for protection of distribution circuits. Substations themselves do not usually have generators, although a power plant may have a substation nearby. Other devices such as capacitors and voltage regulators may also be located at a substation.[Source:Wikipedia]
Let's come back to our "small grid station". So first of all there was FESCO metering room which measures kilowatts used by factory. Then there was a bus bar then there was some current and Potential transformers for metering and safety. Then there were some SF6 type circuit breakers and some other instruments. Then there was 20 MVA transformer (Mill load is 6 MW). Then there is a control room, having three parts, one is  main control room with control of all the instruments (CT's PT'S and circuit breakers) , measurments of incoming voltages and currents. There is also a tape changer scheme to control transformer output (As they require to have constant 11kV at output side but  some times input  deviates from 132, so automatically changing tap could make output voltages same). Another part of control room is circuit breaker room where high safety is require. Another room which is called battery room where AC is first converted to DC and then stored in batteries for backup of this small grid.

 2. Power Generation

Due to intense load shedding problem, it has become now difficult to rely on FESCO supply so mill make their own generation unit having 5 gas fired generators each 1 MW so a total genration capacity of 5 MW (mill requires 6MW). Let's first look at gas fires generators.

Gas  generators:

Gas generators looks like this (Same like in mill)

A simple digram can show working of a gas genrator. Fuel is fed to combustion chamber where it is burned, also a compressor compresses air and send it to turbine side, both these moves turbine and then a generator produces electricity.

Following diagram shows a simple gas generator.

Okay, lets see our specific generator installed in the mill. These generators are producing 11kV which is then synchronized with 11kV output of small grid station and then fed to transformer of mill which converts this into 440 V usable form. All the generators are placed in a room with cooling system. Currently they are wasting 600 centigrade waste heat so our professor tell them that this heat could be used either to run another steam turbine (steam turbine that work on different temperature are available in market ) or at least for chilling and heating rather than wasting them into environment. This can also reduce price of electricity. Unit cost for generation is 7 rupees but if they take it from FESCO then 14 rupees so they prefer to use their own electricity as much as gas is available (gas is currently available for 6 hours a day ) . Head engineer told us that payback of this plant was expected for 6 to 7 years if it were operated for 24 hours at full capacity but due to gas shortage this did't happen. 
Generator room of Mill

3. Spinning Section

Spinning Process

Spinning is a major part of the textile industry. It is part of the textile manufacturing process where three types of fibre are converted into yarn, then fabrics, which undergo finishing processes such as bleaching to become textiles. The textiles are then fabricated into clothes or other products. There are three industrial processes available to spin yarn, and a handicraft community who use hand spinning techniques. Spinning is the twisting together of drawn out strands of fibres to form yarn, though it is colloquially used to describe the process of drawing out, inserting the twist, and winding onto bobbins. [Wikipedia]

Spinning section is mainly divided in two parts, one is cleaning and basic processing unit also called godwm in the map and another is Spinning shed which is actual part of the whole mill. In first section cotton is delivered from market and clean by local workers which then fed into a machine which process it and send it onto a belt that takes all the cotton to main spinning shed where it is used to make fabrics.
Cotton processing unit (cleaning etc)

Spinning shed have a lot of machinery. Where first of all cotton is mixed with polyestr for strength and some other purposes and then sent to another machine which make its rolls, with very thin fabric, you can say.
Fabric in first level
Then this is further processed and and converted into thin fabric in some steps. All this is done by fully automated machinery. We see some robotic hands ( Not in filmy robotic sense) , some convener belts and a lot of other instruments with very nice control system. Every machine have its own speed and other parameters which is controlled by a control unit.
Processing 

 After fabric is ready, it is checked in ultraviolet room to see contamination and cotton-plyster ratios. Textile engineer (Who was also our guide for this section tour) told us that it is very rare to find a faulty piece but once its found, its checked and back traced to see root of the problem.

How things looks like under ultraviolet checker


 Fabric is then stored into a room also called humidification room where it is exposed to 8-10% moisture to increase its strength for 24 hours and then send to dealers.




Look at a simple animation produced by BBC about working of a spinning mill
http://www.bbc.co.uk/history/interactive/animations/spinning_mill/index_embed.shtml



Electronics Lab

They also developed a electronics lab in order to solve electronic related problems. Electronic lab have 2 engineers and some tecnctions, Head Electrical engineer also told us that they don't have PCB booklets available neither any other thing to get help about specific circuits to repair . They do all this by their own, studying circuits and their components and then doing experiments.

More on it coming soon, so stay connected. Thanks..