C program to convert string to integer without using atoi function...

C program to convert string to integer without using atoi function...

C program to convert string to integer without using atoi function

C program to convert string to integer: It is frequently required to convert a string to an integer in applications. String should consists of digits only and an optional '-' (minus) sign at beginning for integers. For string containing other characters we can stop conversion as soon as a non digit character is encountered but in our program we will handle ideal case when only valid characters are present in string. Library function atoi can be used to convert string to an integer but we will create our own function.

C programming code

// C program to convert string to integer without using atoi function
#include <stdio.h>
 
int toString(char []);
 
int main()
{
  char a[100];
  int n;
 
  printf("Input a valid string to convert to integer\n");
  scanf("%s", a);
 
  n = toString(a);
 
  printf("String  = %s\nInteger = %d\n", a, n);
 
  return 0;
}
 
int toString(char a[]) {
  int c, sign, offset, n;
 
  if (a[0] == '-') {  // Handle negative integers
    sign = -1;
  }
 
  if (sign == -1) {  // Set starting position to convert
    offset = 1;
  }
  else {
    offset = 0;
  }
 
  n = 0;
 
  for (c = offset; a[c] != '\0'; c++) {
    n = n * 10 + a[c] - '0';
  }
 
  if (sign == -1) {
    n = -n;
  }
 
  return n;
}
Similarly you can convert string to long.
Output of program:
C program to convert string to integer
Compiler used: 
GCC

Let a look at this "Harmonic filtering"

Let a look at this "Harmonic filtering"
In cases where the preventive action presented above is insufficient, it is necessary to equip the installation with filtering systems.
There are three types of filters:
  • Passive
  • Active
  • Hybrid

Passive filters

Typical applications

  • Industrial installations with a set of non-linear loads representing more than 500 kVA (variable-speed drives, UPSs, rectifiers, etc.)
  • Installations requiring power-factor correction
  • Installations where voltage distortion must be reduced to avoid disturbing sensitive loads
  • Installations where current distortion must be reduced to avoid overloads

Operating principle

An LC circuit, tuned to each harmonic order to be filtered, is installed in parallel with the non-linear load (see Fig. M28). This bypass circuit absorbs the harmonics, thus avoiding their flow in the distribution network.
Generally speaking, the passive filter is tuned to a harmonic order close to the order to be eliminated. Several parallel-connected branches of filters can be used if a significant reduction in the distortion of a number of harmonic orders is required.
FigM20.jpg
Fig. M28: Operating principle of a passive filter

Active filters (active harmonic conditioner)

Typical applications

  • Commercial installations with a set of non-linear loads representing less than 500 kVA (variable-speed drives, UPSs, office equipment, etc.)
  • Installations where current distortion must be reduced to avoid overloads.

Operating principle

These systems, comprising power electronics and installed in series or parallel with the non-linear load, compensate the harmonic current or voltage drawn by the load.
Figure M29 shows a parallel-connected active harmonic conditioner (AHC) compensating the harmonic current (Ihar = -Iact).
The AHC injects in opposite phase the harmonics drawn by the non-linear load, such that the line current Is remains sinusoidal.
FigM21.jpg
Fig. M29: Operating principle of an active filter

Hybrid filters

Typical applications

Industrial installations with a set of non-linear loads representing more than 500 kVA (variable-speed drives, UPSs, rectifiers, etc.)
  • Installations requiring power-factor correction
  • Installations where voltage distortion must be reduced to avoid disturbing sensitive loads
  • Installations where current distortion must be reduced to avoid overloads
  • Installations where strict limits on harmonic emissions must be met

Operating principle

Passive and active filters are combined in a single system to constitute a hybrid filter (see Fig. M30). This new filtering solution offers the advantages of both types of filters and covers a wide range of power and performance levels.
FigM22.jpg
Fig. M30: Operating principle of a hybrid filter

Selection criteria

Passive filter

It offers both power-factor correction and high current-filtering capacity.Passive filters also reduce the harmonic voltages in installations where the supply voltage is disturbed. If the level of reactive power supplied is high, it is advised to turn off the passive filter at times when the percent load is low.
Preliminary studies for a filter must take into account the possible presence of a power factor correction capacitor bank which may have to be eliminated.
Fig M31.jpg
Fig. M31 : Example of MV passive filter equipment

Active harmonic conditioners

They filter harmonics over a wide range of frequencies and can adapt to any type of load. On the other hand, power ratings are limited.
Fig M32.jpg
Fig. M32 : Active Harmonic Conditionner (AccuSine range)

Hybrid filters

They combine the performance of both active and passive filters.
Fig M33.jpg
Fig. M33 : Example of hybrid filter equipment

ZIGBEE (Tarang F4) interfacing with microcontroller ...

ZIGBEE (Tarang F4) interfacing with microcontroller

                         When there is a need of long range two way communications in hobby electronics most of the people prefer "ZIGbee" modules. there are several zigbee modules available in the market...with several ranges and qualities..

Tarang F4 is also a similar module.....
So let's see how to use these modules for normal full duplex serial communication with UART:
  1.  This module can be easily interfaced with  any 8 bit microcontroller with all standard baud-rates between 1200 to 115200.   
  2. Each module consists of a 16 bit address. So user must provide a source address and destination address while configuring the module. which means only the destination module with matched address can only receive the data.
  3. User can select the RF channels among 16 channels with addresses from 0x00 to 0x0F. The modules must be in same channel to establish the communication between them. 
 lets check the pin configuration of this module


Tarang module works on 3.3v  power supply. so sufficient voltage regulator must be used.
WORKING PROCESS:

By default the tarang F4 module: works at baud-rate of : 9600
                      source address : 0x1000   (hexadecimal)     
destination address : 0x1000            
RF channel : 0x00     
it means :
"by default any tarang F4 module can communicate with any other module".
 So tarang modules can be directly interfaced with microcontroller with baudrate of 9600. The connection circuit will be as follows.

 


NOTE: if your microcontroller is working at 3.3V then you can directly interface it to the microcontroller. if your microcontroller is working at 5V connect a resistor of 100ohms between TXD pin of MCU and Din pin of Tarang F4.

How to use Arduino Mega 2560 as Arduino isp ???

How to use Arduino Mega 2560 as Arduino isp ???

 

 

Step 1: Uploading the ArduinoISP sketch

Now open the latest version of the Arduino IDE (currently 0022) .
Goto Tools
                     -> Board
                                      ->  Arduino Mega 2560

Now choose the correct Com port via Tools -> Serial port -> select the port used by you're arduino mega 2560.

Goto File
                -> Examples
                                       -> ArduinoISP

The ArduinoISP sketch will open up and now click upload to upload the sketch to the Arduino Mega 2560.

When the sketch is fully uploaded  Put a 100nF Capacitor Between +5V and RESET pin on the Arduino Mega 2560 to disable auto reset. (whitout this tutorial wont work !)

Step 2: Time to Burn the bootloader

Picture 1: First: select the board you want to upload to.
Ex. for my Atmega328 chip and an external 16MHz crystal i chose: Arduino Duemilanove or Nano /w Armega 328 ( see pic 1 )

Picture 2:  Goto Tools -> Burn Bootloader -> w/ Arduino as ISP
The board will begin bootloading.

Picture 3: When bootloading is successful you can enjoy your new homemade Arduino.

If you get errors :

1. Make sure you selected the correct board ( Picture 1 )
2. When getting this error:  avrdude: stk500_getsync(): not in sync: resp=0x00
You did not put an 100nF capacitor between +5v and RESET pin on the Arduino Mega 2560
3. IF you still get another error search on google
4. If you still find no solution goto arduino forum : http://arduino.cc/forum/index.php/board,67.0.html
and post your problem + a link to this instructables.



 

 

 

 

 

 Step 3: Finally uploading the programs to your new arduino

When your arduino is not set up whit auto-reset (DTR) you will have difficulties uploading new programs to the arduino.
And you will get this error: " avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51 "

This means the arduino IDE could not reset the arduino and so the upload has failed.

To fix this you can try (depends on hardware etc...) :
1. Press reset button on your arduino when "Binary sketch size: xxxx bytes (of a xxxxxxx byte maximum)" appears.
2. If that does not work you can try to put the usb cable in the computer but not in the arduino. When the "binary sketch" stuff appears you quickly put the usb cable in the arduino and see if it uploads without and error.
3. If that still doesn't work you can try to hold the reset button on the arduino , press upload in the arduino IDE and release the reset button when the "binary sketch size ... " stuff appears.
4. If that still doesn't work you can try to press reset after the " binary sketch size ... " and hod it for 2-10 seconds ( it depends on hardware how long you need to hold it)
5. If that still doesn't work you can try to bootload it again and see if it was an error in the primary bootloading.
6.If that still doesn't work you can try to use ur other arduino ( if you have another) to program the second arduino
   This link for more info: http://www.arduino.cc/en/Hacking/Programmer .
7. If that still doesn't work you can ask for help on the arduino.cc forum , maybe ur arduino microchip is dead ?
or a fake .  http://arduino.cc/forum/

i hope i could help you!
Greetz spike

How to burn Bootloader for Atmega 328 using Another Arduino as ISP....

How to burn Bootloader for Atmega 328 using Another Arduino as ISP....

Using an Arduino as an AVR ISP (In-System Programmer)

This tutorial explains how to use an Arduino board as an AVR ISP (in-system programmer). This allows you to use the board to burn the bootloader onto an AVR (e.g. the ATmega168 or ATmega328 used in Arduino). The code in this example is based on the mega-isp firmware by Randall Bohn.

Instructions

To use your Arduino board to burn a bootloader onto an AVR, you need to follow a few simple steps.
  1. Open the ArduinoISP firmware (in Examples) to your Arduino board.
  2. Note for Arduino 1.0: you need to make one small change to the ArduinoISP code. Find the line in the heartbeat() function that says "delay(40);" and change it to "delay(20);".
  3. Select the items in the Tools > Board and Serial Port menus that correspond to the board you are using as the programmer (not the board being programmed).
  4. Upload the ArduinoISP sketch.
  5. Wire your Arduino board to the target as shown in the diagram below. (Note for the Arduino Uno: you'll need to add a 10 uF capacitor between reset and ground.)
  6. Select the item in the Tools > Board menu that corresponds to the board on which you want to burn the bootloader(not the board that you're using as the programmer). See the board descriptions on the environment page for details.
  7. Use the Burn Bootloader > Arduino as ISP command.

Circuit (targeting Arduino Uno, Duemilanove, or Diecimila)

An Arduino board serving as an ISP to program the ATmega on another Arduino board. On the Arduino Uno, you'll need to connect a 10 uF capacitor between reset and ground (after uploading the ArduinoISP sketch). Note that you need access to the reset pin on the target board, which isn't available on NG or older boards.

Circuit (targeting Arduino NG or older)

On NG or older boards, connect the reset wire to pin 1 of the Atmega chip on the board, as shown above.

Circuit (targeting an AVR on a breadboard)

See the Arduino to Breadboard tutorial for details.
Using an Arduino board to program an ATmega. Because no external clock source is connected, the ATmega must be configured to use its internal clock.Using an Arduino board to program an ATmega, with external crystal and associated capacitors (18 or 22 picofarads).

Effect of Inductors in Parallel...

Effect of Inductors in Parallel...

Inductors in Parallel

Inductors are said to be connected together in “Parallel” when both of their terminals are respectively connected to each terminal of the other inductor or inductors. The voltage drop across all of the inductors in parallel will be the same. Then, Inductors in Parallel have aCommon Voltage across them and in our example below the voltage across the inductors is given as:
VL1 = VL2 = VL3 = VAB …etc
In the following circuit the inductors L1L2 and L3 are all connected together in parallel between the two points A and B.

Inductors in Parallel Circuit

inductors in parallel
In the previous series inductors tutorial, we saw that the total inductance, LT of the circuit was equal to the sum of all the individual inductors added together. For inductors in parallel the equivalent circuit inductance LT is calculated differently.
The sum of the individual currents flowing through each inductor can be found using Kirchoff’s Current Law (KCL) where, IT = I1 + I2 + I3 and we know from the previous tutorials on inductance that the self-induced emf across an inductor is given as: V = L di/dt
Then by taking the values of the individual currents flowing through each inductor in our circuit above, and substituting the current i for i1 + i2 + i3 the voltage across the parallel combination is given as:
inductor currents
By substituting di/dt in the above equation with v/L gives:
derative reduction
We can reduce it to give a final expression for calculating the total inductance of a circuit when connecting inductors in parallel and this is given as:

Parallel Inductor Equation

parallel inductance
Here, like the calculations for parallel resistors, the reciprocal ( 1/Ln ) value of the individual inductances are all added together instead of the inductances themselves. But again as with series connected inductances, the above equation only holds true when there is “NO” mutual inductance or magnetic coupling between two or more of the inductors, (they are magnetically isolated from each other). Where there is coupling between coils, the total inductance is also affected by the amount of coupling.
This method of calculation can be used for calculating any number of individual inductances connected together within a single parallel network. If however, there are only two individual inductors in parallel then a much simpler and quicker formula can be used to find the total inductance value, and this is:
parallel inductors
One important point to remember about inductors in parallel circuits, the total inductance ( LT ) of any two or more inductors connected together in parallel will always be LESS than the value of the smallest inductance in the parallel chain.

Inductors in Parallel Example No1

Three inductors of 60mH, 120mH and 75mH are connected together in a parallel combination with no mutual inductance between them. Calculate the total inductance of the parallel combination.
inductors in parallel example 1

Mutually Coupled Inductors in Parallel

                When inductors are connected together in parallel so that the magnetic field of one links with the other, the effect of Mutual Inductance either increases or decreases the total inductance depending upon the amount of magnetic coupling that exists between the coils. The effect of this mutual inductance depends upon the distance apart of the coils and their orientation to each other.
Mutually connected inductors in parallel can be classed as either “aiding” or “opposing” the total inductance with parallel aiding connected coils increasing the total equivalent inductance and parallel opposing coils decreasing the total equivalent inductance compared to coils that have zero mutual inductance.
Mutual coupled parallel coils can be shown as either connected in an aiding or opposing configuration by the use of polarity dots or polarity markers as shown below.

Parallel Aiding Inductors

parallel aiding inductors
The voltage across the two parallel aiding inductors above must be equal since they are in parallel so the two currents, i1 and i2 must vary so that the voltage across them stays the same. Then the total inductance, LT for two parallel aiding inductors is given as:
parallel aiding inductor equation
Where: 2M represents the influence of coil 1 on 2 and likewise coil 2 on 1.
If the two inductances are equal and the magnetic coupling is perfect such as in a toroidal circuit, then the equivalent inductance of the two inductors in parallel is L as LT = L1 = L2 = M. However, if the mutual inductance between them is zero, the equivalent inductance would be L ÷ 2 the same as for two self-induced inductors in parallel.
If one of the two coils was reversed with respect to the other, we would then have two parallel opposing inductors and the mutual inductance, M that exists between the two coils will have a cancelling effect on each coil instead of an aiding effect as shown below.

Parallel Opposing Inductors

parallel opposing inductors
Then the total inductance, LT for two parallel opposing inductors is given as:
parallel opposing inductor equation
This time, if the two inductances are equal in value and the magnetic coupling is perfect between them, the equivalent inductance and also the self-induced emf across the inductors will be zero as the two inductors cancel each other out. This is because as the two currents, i1 and i2 flow through each inductor in turn the total mutual flux generated between them is zero because the two flux’s produced by each inductor are both equal in magnitude but in opposite directions.
Then the two coils effectively become a short circuit to the flow of current in the circuit so the equivalent inductance, LT becomes equal to ( L ± M ) ÷ 2.

Inductors in Parallel Example No2

Two inductors whose self-inductances are of 75mH and 55mH respectively are connected together in parallel aiding. Their mutual inductance is given as 22.5mH. Calculate the total inductance of the parallel combination.
inductors in parallel example 2

Inductors in Parallel Example No3

Calculate the equivalent inductance of the following inductive circuit.
inductive circuit
Calculate the first inductor branch LA, (Inductor L5 in parallel with inductors L6 and L7)
first inductive branch
Calculate the second inductor branch LB, (Inductor L3 in parallel with inductors L4 and LA)
second inductive branch
Calculate the equivalent circuit inductance LEQ, (Inductor L1 in parallel with inductors L2 and LB)
equivalent parallel inductance
Then the equivalent inductance for the above circuit was found to be: 15mH.

Inductors in Parallel Summary

As with the resistor, inductors connected together in parallel have the same voltage, V across them. Also connecting together inductors in parallel decreases the effective inductance of the circuit with the equivalent inductance of “N” inductors connected in parallel being the reciprocal of the sum of the reciprocals of the individual inductances.
As with series connected inductors, mutually connected inductors in parallel are classed as either “aiding” or “opposing” this total inductance depending whether the coils are cumulatively coupled (in the same direction) or differentially coupled (in opposite direction).
Thus far we have examined the inductor as a pure or ideal passive component. In the next tutorial about Inductors, we will look at non-ideal inductors that have real world resistive coils producing the equivalent circuit of an inductor in series with a resistance and examine the time constant of such a circuit.