$begingroup$
We will go for 2nd option, i.e. Our reference voltage will be Vcc(5v). So we set
You have to connect a LDR (light dependant resistor) as shown above. After burning the code on chip use a light source to throw some light on LDR, the ADC will show a value between 0-1024 depending on light. For dark the value should be close to 0 while for bright condition the value will become close to 1000.
How to Implement an Analog Ground Plane. Ask Question 8. 2 $begingroup$. I have to imagine that the Analog Ground plane has to be connected to the digital ground plane somehow on the PCB, or does that happen internally in the AVR? Is the dashed line meant to be taken literally in terms of the shape and extents of the Analog Ground plane. Any floating pin will act as an antenna, and may interfere with values around it, this is one of the major disadvantages of using analog. To get the most accurate readings with minimal amount of interference, you can pull all unused inputs to ground. The accuracy will not change, as the accuracy is determined by the sensor itself.
While working with circuit simulators, I often come across two separate grounds:
- Ground
- Digital Ground
What is the difference between these two?
Dharmaputhiran
DharmaputhiranDharmaputhiran36722 gold badges66 silver badges2020 bronze badges
$endgroup$2 Answers
$begingroup$Digital Ground usually refers to the reference voltage of digital logic ICs. This means that no analog signals are coupled into this reference plane.
You can often see analog and digital ground where digital ground will be the reference for any logic and analog ground will be the return path for any analog circuits.
Imagine an Atmel AT32UC3C. It has both an analog and a digital ground. The analog ground is intended as reference voltage for the ADCs and DACs or Analog Compare interfaces whereas all other logic is considered to be digital.
You will also often see that analog and digital ground are connected to each other directly or via a ferrite. 'Ground' is just a name for the reference net in your circuit.
The main reason for having multiple (different) grounds is that effects of one application do not affect the other (e.g. analog vs. digital).
Tom L.Tom L.6,79011 gold badge1212 silver badges2929 bronze badges
$endgroup$$begingroup$It's not uncommon to see multiple grounds in a circuit and it's normal for these to be joined together at some point: either directly, or with a zero ohm resistor, or small ferrite.
The reason you have multiple grounds is to control the return path for various currents. Digital circuits for example may contain fast edges and so have the potential of introducing significant noise. Separating the digital from analog ground allows you to keep the analog signals clean of any noise from the digital switching. The digital ground will contain noise but this matters less as you are only interested in logic high or low; the exact voltage is less important.
The two grounds will be 'starred' together at some point perhaps directly at the capacitor lead of the power supply.
JYelton16.6k2828 gold badges9494 silver badges195195 bronze badges
Warren HillWarren Hill
$endgroup$Not the answer you're looking for? Browse other questions tagged simulationground or ask your own question.
Most of the physical quantities around us are continuous. By continuous we mean that the quantity can take any value between two extreme. For example the atmospheric temperature can take any value (within certain range). If an electrical quantity is made to vary directly in proportion to this value (temperature etc) then what we have is Analogue signal. Now we have we have brought a physical quantity into electrical domain. The electrical quantity in most case is voltage.To bring this quantity into digital domain we have to convert this into digital form. For this a ADC or analog to digital converter is needed. Most modern MCU including AVRs has an ADC on chip. An ADC converts an input voltage into a number. An ADC has a resolution. A 10 Bit ADC has a range of 0-1023. (2^10=1024) The ADC also has a Reference voltage(ARef). When input voltage is GND the output is 0 and when input voltage is equal to ARef the output is 1023. So the input range is 0-ARef and digital output is 0-1023.Fig: ADC Theory |
Inbuilt ADC of AVR
Now you know the basics of ADC let us see how we can use the inbuilt ADC of AVR MCU. The ADC is multiplexed with PORTA that means the ADC channels are shared with PORTA. The ADC can be operated in single conversion and free running more. In single conversion mode the ADC does the conversion and then stop. While in free it is continuously converting. It does a conversion and then start next conversion immediately after that.
ADC Prescaler.
The ADC needs a clock pulse to do its conversion. This clock generated by system clock by dividing it to get smaller frequency. The ADC requires a frequency between 50KHz to 200KHz. At higher frequency the conversion is fast while a lower frequency the conversion is more accurate. As the system frequency can be set to any value by the user (using internal or externals oscillators)( In xBoard™ a 16MHz crystal is used). So the Prescaler is provided to produces acceptable frequency for ADC from any system clock frequency. System clock can be divided by 2,4,16,32,64,128 by setting the Prescaler.
ADC Channels
The ADC in ATmega32 has 8 channels that means you can take samples from eight different terminal. You can connect up to 8 different sensors and get their values separately.
ADC Registers.
As you know the registers related to any particular peripheral module(like ADC, Timer, USART etc.) provides the communication link between the CPU and that peripheral. You configure the ADC according to need using these registers and you also get the conversion result also using appropriate registers. The ADC has only four registers.
- ADC Multiplexer Selection Register – ADMUX : For selecting the reference voltage and the input channel.
- ADC Control and Status Register A – ADCSRA : As the name says it has the status of ADC and is also use for controlling it.
- The ADC Data Register – ADCL and ADCH : The final result of conversion is here.
(Please Read the Tutorial “Internal Peripherals of AVR” before using ADC of AVRs.)
Using the ADC.
In this sample we will setup and use the ADC in single conversion mode. We will connect a LDR( light dependent resistor) which is a light sensor to input. The result will be shown in LCD.
Initialization.
We have to configure the ADC by setting up ADMUX and ADCSRA registers. The ADMUX has following bits.
ADMUX Register.
REFS1 REFS0 selects the reference voltage. See table below –
REFS1 | REFS0 | Voltage Reference Selection |
0 | 0 | ARef internal Vref Turned off |
0 | 1 | AVCC |
1 | 0 | Reserved |
1 | 1 | Internal 2.56 Voltage Reference |
The ADCSRA Register.
- ADEN – Set this to 1 to enable ADC
- ADSC – We need to set this to one whenever we need adc to do a conversion.
- ADIF – This is the interrupt bit this is set to 1 by the hardware when conversion is complete. So we can wait till conversion is complete by polling this bit like The loop does nothing while ADIF is set to 0, it exits as soon as ADIF is set to one, i.e. conversion is complete.
- ADPS2-ADPS0 – These selects the Prescaler for ADC. As I said the ADC frequency must be between 50KHz to 200KHz.
We need to select division factor so as to get a acceptable frequency from our 16Mhz clock. We select division factor as 128.So ADC clock frequency = 16000000/128 = 125000 = 125KHz (which is in range of 50KHz to 200KHz). So we set ADCSRA as
Reading an analog value.
Now every thing is set up. We now write a routine that will ReadADC. We can call this function from any where from our code and simply need to pass 0-7 as for which channel we need to read.Sample Code.
The following is complete code to Read Channel 0 and display its value on LCD.Hardware
Fig: LDR Connected to ADC of AVR |
Fig: Screenshot of ADC Test App. |
Downloads
Note:- I used the xBoard for testing the application but you can use your own development board. See Home Made AVR Devboard.
- You can also get a low cost ATmega8 based board and “USB AVR Programmer” for quick start.
- Please Read the Tutorial “Internal Peripherals of AVR” before using ADC of AVRs.
More AVR ADC Applications
ADC Data On PC (Click to Read More …) |
JLCPCB Prototype: $2 for 10 pcs PCBs, 48 Hours Quick Turn
Facing problem with your embedded, electronics or robotics project? We are here to help!
Post a help request.
Post a help request.