• 1

    ..

  • 2

    ...

  • 3

    ...

Thursday, 27 November 2014

VHDL IEEE PACKAGES - DATA TYPES – DATA CONVERSIONS

VHDL IEEE PACKAGES - DATA TYPES – DATA CONVERSIONS
IEEE PACKAGE:
The IEEE library contains several packages, including the following:
  • std_logic_1164: Specifies the STD_LOGIC (8 levels) and STD_ULOGIC (9 levels) multi-valued logic systems.
  • std_logic_arith: Specifies the SIGNED and UNSIGNED data types and related arithmetic and comparison operations. It also contains several data conversion functions, which allow one type to be converted into another: conv_integer(p), conv_unsigned(p, b), conv_signed(p, b), conv_std_logic_vector(p, b).
  • std_logic_signed: Contains functions that allow operations with STD_LOGIC_VECTOR data to be performed as if the data were of type SIGNED.
  • std_logic_unsigned: Contains functions that allow operations with STD_LOGIC_VECTOR data to be performed as if the data were of type UNSIGNED.
  • std_logic_textio: Contains functions text i/o, file read & write, etc.

Pre-Defined Data Types
VHDL contains a series of pre-defined data types, specified through the IEEE 1076 and IEEE 1164 standards. More specifically, such data type definitions can be found in the following packages / libraries:
  • Package standard of library std: Defines BIT, BOOLEAN, INTEGER, and REAL data types.
  • Package std_logic_1164 of library ieee: Defines STD_LOGIC and STD_ULOGIC data types.
  • Package std_logic_arith of library ieee: Defines SIGNED and UNSIGNED data types, plus several data conversion functions, like conv_integer(p), conv_unsigned(p, b), conv_signed(p, b), and conv_std_logic_vector(p, b).
  • Packages std_logic_signed and std_logic_unsigned of library ieee: Contain functions that allow operations with STD_LOGIC_VECTOR data to be performed as if the data were of type SIGNED or UNSIGNED, respectively.




DATA CONVERSIONS:
Several data conversion functions can be found in the std_logic_arith package of
the ieee library. They are:
  • conv_integer(p) : Converts a parameter p of type INTEGER, UNSIGNED, SIGNED, or STD_ULOGIC to an INTEGER value. Notice that STD_LOGIC_VECTOR is not included.
  • conv_unsigned(p, b): Converts a parameter p of type INTEGER, UNSIGNED, SIGNED, or STD_ULOGIC to an UNSIGNED value with size b bits.
  • conv_signed(p, b): Converts a parameter p of type INTEGER, UNSIGNED, SIGNED, or STD_ULOGIC to a SIGNED value with size b bits.
  • conv_std_logic_vector(p, b): Converts a parameter p of type INTEGER, UNSIGNED, SIGNED, or STD_LOGIC to a STD_LOGIC_VECTOR value with size b bits.


The following are the examples for converting interger to std logic vector, unsigned, singed and std logic vector to integer, and integer to real & complex, and integer to string. By converting std logic vector to integer, and that integer value to string, we can convert std logic vector to string.
INTEGER TO SLV/UNSIGNED/SIGNED
num is integer
USE IEEE.NUMERIC_STD.ALL;
dat <=std_logic_vector(to_unsigned(55,dat'length));

use ieee.std_logic_arith.all;--NEVER USE STD LOGIC ARITH & NUMERIC_STD TOGETHER
slv<= conv_std_logic_vector(num,slv’length);
unsignd := conv_unsigned(num,unsignd’length);
signd := conv_signed(num,signd’length);

SLV TO INTEGER
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
variable inte:natural;
--dat= std_logic_vector 11 downto 0
inte:=conv_integer(dat); -- to integer
INTEGER TO STRING
report "dat= " & integer'image(inte); --to string

INTEGER TO REAL/COMPLEX
num is integer
USE IEEE.MATH_REAL.ALL;
real_num := real(inte);
complx := complex(inte);

Coming soon: Basic VHDL Syntaxes & Constructs, Detailed and latest file read write with hexadecimal, octal, binary data types….. Stay tuned.


If you enjoyed this post plz let us know your views via comments.
This helps us to do much more better.
Thankyou.


Thursday, 14 August 2014

Renesas eclipse embedded studio



Renesas eclipse embedded studio, known as e² studio, is a complete development and debug environment based on the popular Eclipse CDT project. Essentially open source, the Eclipse CDT covers build (editor, compiler and linker control) as well as debug phase based on an extended GDB interface




Features


Memory Usage
Visual Expressions
Integrated Code Generation
Eclipse CDT Editor


Target Devices


e² studio has been developed to support the key promotion families of Renesas controllers:
  • RL78 Family
  • RX Family
  • RH850 Family*
  • SuperH Family (SH-2 and SH-2A)
As new devices are released from Renesas, e² studio can easily be updated to add the necessary support files and debugger extensions.
* Note, The working sample for RH850 is supported. (Debug support only)

To know More click here




Saturday, 2 August 2014

POINTERS IN C - Part1

POINTERS IN C - Part1


For any beginner in C programming, the most intriguing and confusing part will be pointers (you can ask any novice C programmer).  The following will be a simple attempt to explain pointers for a beginner.

A pointer in its simplest of terms is a variable which points to the address of other variable.





Let us consider integer variable 'a' and initialize it as follows:

int a=1;

Variable a will be stored in a memory location and as we all know every memory location has an address. Let us assume "a" is stored at address 20.

i.e.,

int a=1; (address of a is 20)

Now we are introducing one more variable ptr, which is declared as:

int *ptr;

Let us see each word separately of the above declaration.

Int represents integer.

*ptr represents a pointer variable, which points to another variable of integer type (bit confusing isnt it? it should be, let us come to this a bit later), we are using * to indicate that what is following * is a pointer variable (to make the compiler understand).

We can store the address of another variable in pointer variable,  i.e., the content of the pointer variable can be the address of another variable.

Let us assume address of variable "ptr" as 30;

And now, let us consider

 ptr = &a;

the above statement indicate the compiler to assign the address of variable 'a' to the variable 'ptr' (just like how we are assigning 1 to variable 'a').

The '&' operator is known as "address of" operator (remember scanf?).

Now let's do some printing.

1. printf("%d",a); 1
2. printf("%d",&a); 20
3. printf("%d,ptr); 20
4. pritnf("%d,&ptr); 30
5. printf("%d",*ptr); 1

Understandably, we do not have any problems with first 2 printf statements.  Problem starts from the third...

The third statement prints the value 20, which is the address of variable 'a' (remember?), this is because we are assigning the address of variable 'a' to 'ptr' (ptr=&a).

Fourth statement is an usual statement which prints the address of the variable 'ptr.'

Fifth one is the most confusing, but important of all, where the printed value is 1, which is actually the value of variable 'a'.  This is happening because of * operator preceds 'ptr' variable.  * is called as derefencing operator.

What is happening here actually?!  When we are using deferencing operator *, the content of variable 'ptr' is considered (by the compiler obviously) as address of another variable and the corresponding value in that address will be printed.

So as per our example, the address of the variable 'a' is stored in variable 'ptr' (remember ptr=&a?), and when the printf statement gets executed, the value stored in address 20 (which is 1) is printed.

we just tried to give a toast of pointers in this introductory part and will explore more of pointers in detail in the coming days...happy programming.

Sakthi
nsakthivelu@gmail.com





Flashing LED Using IC555





Flashing Leds Using IC555


This simple circuit using IC555 will generate on/off signal through which we can do Led blinking . 

the Duty Cycle of the square wave is depending on R1,R2,C1 Values .
 This is kind of one channel pulse generator . If we want more than one channel to generate different square wave signals with different Duty Cycles, we can use IC4017 .
 
  

Friday, 18 July 2014

Standard Resistor & Capacitor values - Table

The following are the Standard Resistor & Capacitor values.
NOTE:  Use this as references for design calculations. Real time application may have differences. These values are std fixed. But actual values may vary depending on the manufacturer's tolerance. 



Friday, 11 July 2014

Steps to Create "God Mode" In Windows 7

Steps to  Create  "God Mode" In Windows 7
1. Create a New folder


2 Rename the New folder in to      " God Mode.{ED7BA470-8E54-465E-825C-99712043E01C}"


3. Here its your God Mode in Windows 7



4. Double Click  the God Mode and you will see the All the Setting control of Windows 7 :-)



Created By
Kali Sankar . V
Ethical Hacking Editor
Elecdude.com

Monday, 7 July 2014

DIFFERENCES IN CMOS 4000 SERIES, 74LS, 74HC, 74HCT SERIES IC

DIFFERENCES OF CMOS 4000 SERIES, 74LS, 74HC, 74HCT SERIES IC

Integrated Circuit (IC) is fastly growing and different technologies have been developed and being developed. Most commonly available IC families are CMOS 4000, 74LS, 74HC, 74HCT. Now let us see the characteristics of those families and their differences.



4000 Series CMOS
        This family of logic ICs is numbered from 4000 onwards, and from 4500 onwards. They have a B at the end of the number (e.g. 4001B) which refers to an improved design introduced some years ago. Most of them are in 14-pin or 16-pin packages. They use CMOS circuitry which means they use very little power and can tolerate a wide range of power supply voltages (3 to 15V) making them ideal for battery powered projects. CMOS is pronounced 'see-moss' and stands for Complementary Metal Oxide Semiconductor. 

       However the CMOS circuitry also means that they are static sensitive. Touching a pin while charged with static electricity (from your clothes for example) may damage the IC. In fact most ICs in regular use are quite tolerant and earthing your hands by touching a metal water pipe or window frame before handling them will be adequate. ICs should be left in their protective packaging until you are ready to use them. For the more sensitive (and expensive!) ICs special equipment is available, including earthed wrist straps and earthed work surfaces.

74LS, 74HC, 74HCT
There are several families of logic ICs numbered from 74xx00 onwards with letters (xx) in the middle of the number to indicate the type of circuitry, eg 74LS00 and 74HC00. The original family (now obsolete) had no letters, eg 7400. 

The 74LS (Low-power Schottky) family (like the original) uses TTL(Transistor-Transistor Logic) circuitry which is fast but requires more power than later families. The 74 series is often still called the 'TTL series' even though the latest ICs do not use TTL! 

The 74HC family has High-speed CMOS circuitry, combining the speed of  TTL with the very low power consumption of the 4000 series. They are CMOS ICs with the same pin arrangements as the older 74LS family. Note that 74HC inputs cannot be reliably driven by 74LS outputs because the voltage ranges used for logic 0 are not quite compatible, use 74HCT instead.

The 74HCT family is a special version of 74HC with 74LS TTL-compatible inputs so 74HCT can be safely mixed with 74LS in the same system. In fact 74HCT can be used as low-power direct replacements for the older 74LS ICs in most circuits. The minor disadvantage of 74HCT is a lower immunity to noise, but this is unlikely to be a problem in most situations. 

The CMOS circuitry used in the 74HC and 74HCT series ICs means that they are static sensitive. Touching a pin while charged with static electricity (from your clothes for example) may damage the IC. In fact most ICs in regular use are quite tolerant and earthing your hands by touching a metal water pipe or window frame before handling them will be adequate. ICs should be left in their protective packaging until you are ready to use them. 

CMOS 4000 series family characteristics:
  • Supply: 3 to 15V, small fluctuations are tolerated.
  • Inputs have very high impedance (resistance), this is good because it means they will not affect the part of the circuit where they are connected. However, it also means that unconnected inputs can easily pick up electrical noise and rapidly change between high and low states in an unpredictable way. This is likely to make the IC behave erratically and it will significantly increase the supply current. To prevent problems all unused inputs MUST be connected to the supply (either +Vs or 0V), this applies even if that part of the IC is not being used in the circuit!
  • Outputs can sink and source only about 1mA if you wish to maintainthe correct output voltage to drive CMOS inputs. If there is no need to drive any inputs the maximum current is about 5mA with a 6V supply, or 10mA with a 9V supply (just enough to light an LED). To switch larger currents you can connect a transistor.
  • Fan-out: one output can drive up to 50 inputs.
  • Gate propagation time: typically 30ns for a signal to travel through a gate with a 9V supply, it takes a longer time at lower supply voltages.
  • Frequency: up to 1MHz, above that the 74 series is a better choice.
  • Power consumption (of the IC itself) is very low, a few µW. It is much greater at high frequencies, a few mW at 1MHz for example.

74HC and 74HCT family characteristics:
  • 74HC Supply: 2 to 6V, small fluctuations are tolerated.
  • 74HCT Supply: 5V ±0.5V, a regulated supply is best.
  • Inputs have very high impedance (resistance), this is good because it means they will not affect the part of the circuit where they are connected. However, it also means that unconnected inputs can easily pick up electrical noise and rapidly change between high and low states in an unpredictable way. This is likely to make the IC behave erratically and it will significantly increase the supply current. To prevent problems all unused inputs MUST be connected to the supply (either +Vs or 0V), this applies even if that part of the IC is not being used in the circuit! Note that 74HC inputs cannot be reliably driven by 74LS outputs because the voltage ranges used for logic 0 are not quite compatible. For reliability use 74HCT if the system includes some 74LS ICs.
  • Outputs can sink and source about 4mA if you wish to maintain the correct output voltage to drive logic inputs, but if there is no need to drive any inputs the maximum current is about 20mA. To switch larger currents you can connect a transistor.
  • Fan-out: one output can drive many inputs (50+), except 74LS inputs because these require a higher current and only 10 can be driven.
  • Gate propagation time: about 10ns for a signal to travel through a gate.
  • Frequency: up to 25MHz.
  • Power consumption (of the IC itself) is very low, a few µW. It is much greater at high frequencies, a few mW at 1MHz for example. 

74LS family TTL characteristics:
  • Supply: 5V ±0.25V, it must be very smooth, a regulated supply is best. In addition to the normal supply smoothing, a 0.1µF capacitor should be connected across the supply near the IC to remove the 'spikes' generated as it switches state, one capacitor is needed for every 4 ICs.
  • Inputs 'float' high to logic 1 if unconnected, but do not rely on this in a permanent (soldered) circuit because the inputs may pick up electrical noise. 1mA must be drawn out to hold inputs at logic 0. In a permanent circuit it is wise to connect any unused inputs to +Vs to ensure good immunity to noise.
  • Outputs can sink up to 16mA (enough to light an LED), but they can source only about 2mA. To switch larger currents you can connect a transistor.
  • Fan-out: one output can drive up to 10 74LS inputs, but many more 74HCT inputs.
  • Gate propagation time: about 10ns for a signal to travel through a gate.
  • Frequency: up to about 35MHz (under the right conditions).
  • Power consumption (of the IC itself) is a few mW.

Also see more:




Saturday, 24 May 2014

Bharat Electronics Limited - application for Probationary Engineers with BE/B.Tech, B.Sc

Bharat Electronics Limited invites application for the recruitment of Probationary Engineers with BE/B.Tech, B.Sc degree

Company Name: Bharat Electronics Limited
Position: Probationary Engineers
Education: BE/B.Tech, B.Sc
Experience: FRESHERS
Location: Across India



Post Name : Probationary Engineers

Qualification :For Probationary Engineers, GEN / OBC candidates with first class in B.E / B.Tech / B.Sc Engineering Graduate from AICTE approved Colleges in Electronics / Electronics and Communication / Electronics & Telecommunication / Communication / Telecommunication / Mechanical / Civil/ Electrical/Electrical & Electronics / Computer Science / Computer Engineering/ Computer Science and Engineering. Candidates with first class in AMIE / AMIETE, in the above disciplines are also eligible to apply. SC/ST/PWD candidates with pass class in the above degree / disciplines are eligible to apply.Candidates currently studying in the final semester / final year of BE / B.Tech / B.Sc Engineering in the specializations mentioned above and who will be appearing for their final semester/final year exams in the month of May/June 2014 are also eligible to apply.

No.of Post : 200
     Electronics-100, Mechanical - 75, CS - 20, Civil - 03, Electrical - 02
Age: as on 01.05.2014 :25 years
Pay Scale : Rs.16400-40500


The above openings are for all/any of the Units/Offices of BEL at of the following locations: Bangalore (Karnataka), Ghaziabad (UP), Pune (Maharashtra), Hyderabad (Andhra Pradesh), Chennai (Tamil Nadu), Machilipatnam (Andhra Pradesh) Panchkula (Haryana), Kotdwara (Uttarakhand) Navi Mumbai (Maharashtra)


Application Fee:
Candidates belonging to GEN/OBC category are required pay an application fee of 500/-. The mode of payment is through SBI Challan. Candidates are required to download and print the bank challan (Click here to download challan). The challan (in triplicate) is to be filled by the applicant and submitted to the nearest SBI Branch, with an application fee of Rs.500/- plus bank charges. On submission of the challan unique transaction number (Journal Number) will be generated and the same would be written by the staff at the Bank.



Service Agreement :
Selected candidates will be required to undergo an Orientation / On-the-Job training for a period of 6 months. They will be required to execute a Service Agreement to serve the Company for a period of 3 years after training and should be willing to serve in any of the Units / Offices of BEL. The amount payable for breach of Service Contract is Rs.3, 00,000/-


Method of Selection:
Selection will be through written test and interview of shortlisted candidates based on performance in the written test.


How to apply:
Last date for applying on line is 05.06.2014. Send the duly completed Printed Version of Application Form having Auto Generated Online Application No. alongwith requisite amount of Bank Challan (wherever required) to "Post Box No.3076, Lodi Road, New Delhi-110003 " (To be sent through ordinary post only) so as to reach on or before 10th June 2014.


Last date to apply : June 05, 2014

For More details click here: https://jobapply.in/BEL2014/DetailsAdv.htm

Saturday, 26 April 2014

FREQUENCY MEASUREMENT USING AVR ATMEGA8

     Often frequency measurement is needed, but one cannot afford a DSO or an appropriate meter for that. So we have designed it in AVR microcontroller which is easily available and much easier to program.

    This frequency measurement uses Input Capture module in Timer1 via ICP pin PB0. For ease of programming, we have designed a low frequency measurement for frequencies lesser than 1KHz, but can be increased upto several 100KHz, through prescalar.

       The circuit diagram is

LCD 4 BIT INTERFACING WITH AVR MICROCONTROLLERS ATMEGA8,16,32,64

LCD 4 BIT INTERFACING WITH AVR MICROCONTROLLERS ATMEGA8,16,32,64

   This is the header file for LCD 4-bit mode interfacing with AVR Microcontroller series such as Atmega 16, 32, 64, 8, etc. It is coded in GCC & supports all AVR GCC compliers.

   This is designed for 16×2 LCD, but can be exteneded upto 20×4 LCD.
   Contains all functions with different cursor styles, string display from ram & flash rom, bcd, signed & unsigned  integer 8-bit and 16-bit numbers, shift left, shift right, etc.

Wednesday, 23 April 2014

FREE ELECTRONIC ANDROID APPS



          Electronics has much more complex calculations than basic maths. More tools are available for these electronics calculation but they are mostly windows or linux based application.



          Android, an opensource smartphone OS, enables anyone to design an app for it. So it is easy for any common person who knows the electronics & basic programming can build an app.

          Lets see the commonly available free Android apps for Electronic designs, such as ohm’s law, KCL, KVL, resistor colour code calculations, series-parallel calculations, etc,etc,etc,,,,

·         Ohm's Law
Ohm's law calculator and the Watt's Law calculator.

·         Electronics Toolkit
Electronic tool kit calculates unknown quantities in the field of electrical and electronics engineering. It provides a resistor color code, power calculator, and Ohm’s Law, Series, Parallel, and Series/Parallel combination of inductors, capacitor and resistors, resistivity, Power factor triangle, i.e. active, reactive and apparent, magnetic fields, reactances and much more.

·         Every Circuit
    This is another recommended android Smartphones app for electrical and especially for electronics engineers and students. EveryCircuit app lets you understand that how do design different important electronic circuits and how they work.
     This app is handy in circuit like Logic gate, LED flashing
circuits, Resistive, inductive, capacitive, operational amplifier and other electrical & electronics circuits and can view dynamic charge, current and voltage colorful animations with waveforms.

·         DroidTesla
DroidTesla is a simple SPICE tool. Its permit you to solve, simulate and analyze different electrical and electronic circuits by using KCL and KVL. It has the ability to solve both linear and nonlinear circuits like resistive, capacitive, inductive and BJT, Transistor, Diode, AC/DC Voltage and Current sources, 555, MOSFETS, Logic gate and lots more…

·         ElectroDroid
ElectroDroid is a simple and powerful collection of electronics tools and references. It has a variety of tools & calculators, pin description, SMD details, etc,etc. This app is also available in pro version which can be bought from the Play store. Pro version supports the developer, unlocks more features and contains no ads.


·         Electrical calculations
It has the ability to identify the unknown values of different quantities of electrical and electronics circuits. There are lots of electrical calculators available in this app at once.


·         Electrical LV Calculator
It allows to design electrical system which reduces the reactive power, that is it improve power factor, the maximum allowable power installation, calculates current in a short circuit, Voltage drop, the automatic switch current in A, calculate the minimum and maximum cable and wire size, calculate the number of earth electrodes and earth resistance etc

·         Electrical Engineering
This app contains 3 of the most useful Electronic tools, the electrical calculator, the Electrical circuit calculator and the Electrical formulas. It also provides you a list of few electronics resources and ebooks that can be bought through the app.





Friday, 11 April 2014

12V BATTERY HEALTH INDICATOR

This circuit is simple and easy to build & has only a few discrete components.
This indicates the 12V battery safe operating voltage.




Diode D1 protects the circuit when the battery polarity is reversed.
The LED glows with full brightness when the battery voltage is above the set threshold.

The threshold is set with the zener diode D2. for this circuit the threshold will
 Vds+VBEq1 ~= 11.5V

When the Battery voltage is above 10.8V the LED glows with very little brightness & increases with increase in battery voltage.
When it is above 11.5V the LED glows with full brightness.

The resistance R1 limts the current flow through the LED, R2 limits base current.
The current consumption is very less. Approx 10mA for battery voltage above 13V & very lesser current consumption (in few uA) when battery voltage drops below 10.5V.







Wednesday, 9 April 2014

Rectangular Wave - PWM Waveform - Generation using 555

This simple circuit that produces a rectangular waveform using the most commonly available analog timer IC 555.

The on time and off time are controlled by the resistances Ra & Rb, which are variable to get the required value.

The formula for the time calculations are
The Circuit diagram is


The rectangular/pwm output is at pin 3 of the IC.
Resistance R1,R2 protects the device from shorting the terminals to VCC and ensure a minimum resistance available between the terminals.

The time delay depends on C2, RV1 & RV2. Change the values for desired output.

To get a square wave output, the condition is Ra=Rb. To get this, set the both pots to extreme left of right.



Monday, 7 April 2014

SY-HS 220 Humidity Sensor Interfacing with AVR Atmega (8/16/32)

SY HS220 is the Relative Humidity Sensor with near linear output reference to relative humidity.
Its opereating RH percentage is 30-90% with Output Voltage range 990-2970mV.

Here we've interfaced SY HS220 with AVR ATMEGA8 microcontroller and display %RH in LCD.

Circuit Diagram:

undefined
ElecDude: HS220 AVR Circuit
Code:
/* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Author: ElecDude
         admin@elecdude.com      

Copyright - 2014 - ElecDude

DISCLAIMER:

 THIS SOURCE FILE MAY BE USED AND DISTRIBUTED WITHOUT      
 RESTRICTION PROVIDED THAT THIS COPYRIGHT STATEMENT IS NOT 
 REMOVED FROM THE FILE AND THAT ANY DERIVATIVE WORK CONTAINS
 THE ORIGINAL COPYRIGHT NOTICE AND THE ASSOCIATED DISCLAIMER.

 This is provided without any  express or implied warranties,
 including, but not limited  to, the implied warranties of merchantability
 and fitnessfor a particular purpose. FOR EDUCATIONAL PURPOSE ONLY.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
                          SY-HS 220 Humidity Sensor
     Input voltage = 5.0V                    Operating Temperature = 0-60'C
    Operating Humidity = 30-90% RH        Output Voltage = 990-2970mV
    Std.output = 1.98V   at 25`C 60%RH    Accuracy = +/-5%RH  at 25'C & 60%RH

Normal Values
%RH   mV
 30      990
 40     1300
 50     1650
 60     1980
 70     2310
 80     2640
 90     2970

    V-RH RATIO = 0.30301    by linear slope
    %RH = RATIO * Vout

ADC    Vadc = Vref * adcval/1024

If Vref= Vcc= 4.96, then
    %RH= Vout * 0.30301
       = Vref * adcval/1024 * 0.30301
    %RH= 0.0001467 * adcval
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~*/


#define F_CPU 1000000UL
/*****************MACRO's DEFINITION*********************************/
#ifndef BIT
#define BIT(x)    _BV(x)
#endif
#ifndef SETBIT
#define SETBIT(x,b)     x|=_BV(b);
#endif
#ifndef CLEARBIT
#define CLEARBIT(x,b)     x&=~_BV(b);
#endif
#ifndef TOGGLEBIT
#define TOGGLEBIT(x,b)     x^=_BV(b);
#endif
#ifndef CHECKBIT
#define CHECKBIT(x,b)     (x & _BV(b))
#endif

#include <avr/io.h>
#include <util/delay.h>
void WaitMs(unsigned int ms) // waits (pauses) for ms milliseconds
{
    unsigned int m;
    for(m=0;m<=ms/10;m++)
    {
        _delay_ms(10);
    }
}

#include "ADCHEAD.H"
#include "lcd.c"

#define PRT PIND
#define sw1 0
#define sw2 1
#define sw3 2
#define TIME 100
register unsigned char i asm("r17");

#define R 0.148
unsigned char count=0x00,chng=1;
unsigned int val,th;
char d2[]="00.0%";
void UpdateVal()
{
    float rh;
    uint16_t x;
    rh=R*val; //xx.y
    x=rh*10; //xxy
    d2[3]= (x%10) | 0x30;//ones
    x/=10;
    d2[1]= (x%10) | 0x30;//tens
    x/=10;
    d2[0]= (x%10) | 0x30;//hund
}

int main()
{
      CLEARBIT(DDRC,4)//set as i/p for adc
    CLEARBIT(DDRC,5)
    DDRD=0xF8;//enable PD as i/p & en pull ups
    PORTD=0x07;
    SETBIT(DDRB,7)
    SETBIT(PORTB,7)
   
    _delay_ms(10);
    LCD_init(COFF);
    _delay_ms(100);
    LCD_putsPXY(3,0,"Welcome to");
    LCD_putsPXY(4,1,"ElecDude");
    ADC_init();
   
    WaitMs(800);//wait for some time to initialise
    LCD_clear();
    SetCH(0x05); //PC5=HS220's Vout
    val=0;i=0;
    LCD_putsPXY(0,0,"Relativ Humidity");
    while(1)
        {
            TOGGLEBIT(PORTB,7)
            val+=ADC_readcurch();
            i++;       
            if(i==4)
             {
                val=val/4;
                UpdateVal();
                LCD_putsXY(5,1,d2);
                i=0; val=0; //clear after update
             }// endof if(i==4)
         WaitMs(200);
        }//end of while
return 0;
}

ADCHEAD.H

#define ADC_ENABLE()         SETBIT(ADCSRA,ADEN)        //Macro to enable ADC Module.
#define ADC_DISABLE()         ADCSRA &= 0x7F            //Macro to disable ADC MOdule.
#define ADC_START_CONV()     SETBIT(ADCSRA,ADSC)        //Macro to start ADC conversion.
//#define ADC_STOP_CONV()        CLEARBIT(ADCSRA,ADSC)    //Macro to stop ADC conversion.
#define ADC_CLEAR_ADIF()     CLEARBIT(ADCSRA,ADIF)        //Macro to clear ADC Interrupt flag.

#define VREF 4.96        //Defines the VREF used.
/*            Value in Volts = ADC Value * (VREF/1024)
            ADC resolution = 4.96/1024 = 4.84mV            */
/*************************************************************************************
                    ACD initialization routine
*/

void ADC_init(void)    //Function used to initialise the ADC Module.
{
    ADMUX = 0x45;         //Select the channel ADC5, AVcc, ADC right adjust, chn=0-5
    ADCSRA = 0x83;     // 

    _delay_ms(150);     //Provide adequate delay to initialise the analog circuitry.

}


#define ADC_read() ADC
/* To read & return adc value from a channel (chn=> 0 to 5)    */
#define SetCH(chn) ADMUX=(ADMUX & 0xF0) | (chn & 0x07)
                                        // 07- because Max 5 channels for ATM8
int ADC_readch(unsigned char chn)       
{
    ADMUX= (ADMUX & 0xF0) | (chn & 0x0F);
    ADC_CLEAR_ADIF(); //Clear ADC Interrupt Flag
    ADC_START_CONV(); //Start ADC Conversion.
    while(!(CHECKBIT(ADCSRA,ADIF)));//wait for conversion complete
    return(ADC_read());//----read values & return
}

/* TO READ FROM CURRENTLY SET CHANNEL IN ADCMUX.
    Note: This function doesn't change the ADC channel & uses the value set in ADCMUX
          So set the required channel before calling this function   */

int ADC_readcurch()       
{
    ADC_CLEAR_ADIF(); //Clear ADC Interrupt Flag
    ADC_START_CONV(); //Start ADC Conversion.
    while(!(CHECKBIT(ADCSRA,ADIF)));//wait for conversion complete
    return(ADC_read());//----read values & return
}

/***/


Output:

Search Here...