Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ADC in free running mode

Status
Not open for further replies.

lienara

Newbie level 5
Joined
Dec 21, 2010
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,327
hi everybody
i work in frequency meter project which required adc with free running mode and interrupt(how i can setting this)
plz any one give me c code for this project
 

which ADC you are using.

---------- Post added at 14:59 ---------- Previous post was at 14:58 ----------

or which microcontroller you are using..
you have ADC in the microcontroller or you are using seperate chip
 

for free running mode you set bits 765 of SFIOR to 0 SFIOR&=0x1F;
bit5 of ADCSRA =1 to enable auto triggering, and bit3 =1 to enable the interrupt and bit7 =1 to enable the adc ADCSRA|=0xA8;
You also need to set the ADC clock divider (prescaller), voltage reference, select input channel and start the first conversion.
I can't give you the complete code because i don't know your reference voltage source, clock frequency and adc channel.

Alex
 
clock frequency=4mhz and we use channel0
adc clock=1Megahz

---------- Post added at 11:50 ---------- Previous post was at 11:40 ----------

also voltage reference=5v
 

You can't use 1Mhz for the ADC clock, the datasheet says that you should use 50-200KHz for 10 bit,
for 8 bit it can be a little higher but i don't think 1MHz, i haven't tried.
Also note that a normal convertion takes 13 ADC clock cycles which means that the sampling rate will be ADC clock/13.
For a system clock or 4Mhz the ADC clock can only be set to 125Khz (division factor 32), the next option is 250 (division factor 16) which is above the 200Khz limit for 10 bit.

for 125Khz ADC clock, free running, with interrupt, Vcc reference,input 0, the code is


ADMUX=0x40;
ADCSRA=0xAD;
SFIOR&=0x1F;


You need to start the first conversion using ADCSRA|=0x40;

Alex
 
Last edited:
plz can give me more explianation
or full code this
 

In which part you want more explanation?
Each register is described in the avr datasheet, the timings are there too, i have set up the values for what you have asked.
The lines i have given you is the actual code to initialize and run the ADC converter,and these register names are usually common
to different compilers, you still need to write the interrupt function.
I don't know which compiler you are using.
I can't write the frequency meter code for you,
I'm trying to help you with the adc initialization so that you can proceed with your project.

Alex
 

frequency meter using fourier transform

hi every body.............
i wrote program measure the frequency using fourier transform.i am using atmega 16 with adc(to sample signal) and lcd. the problem that it represent incorrect value plz help me
the code attached with this theardView attachment freqmetr.txtView attachment freqmetr.txt
 

May I ask why do you use an array of doubles instead of char for data[max],
data stores the 8bit result of the ADC conversion so unsigned char data[max] would be apprpriate,
you are actually wasting 150 bytes and also slowing down the execution speed because the cpu has to do calculations using two 32bit numbers instead of one 8bit and 0ne 32bit.

You don't specify your problem, what value should the display show and what is it actually showing?

Alex
 

the program must represent the frequency of each signal entered to MCU via adc channel
 

What error are you getting?
with a specific frequency input what do you see on the screen, for example with 100Hz what is the value you see on the screen.

Alex
 

if the input signal has frequency=100hz. the program must represnt this value exactly
 

You are not getting a correct ADC reading because the result is right adjusted as default,
this means that bits 8-9 are in ADCH and bits 0-7 are in ADCL.
You read ADCH to get the 8bit result and this is wrong,
you have to left adjust the result first so that bits 2-9 move in ADCH, use the following to get a correct 8 bit result.

Code:
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff)[COLOR="red"] | 0x20; // set ADLAR bit to 1 to left adjust the result[/COLOR]
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCH;
}
and
Code:
/ ADC initialization
// ADC Clock frequency: 62.500 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE & 0xff [COLOR="red"] | 0x20; // set ADLAR bit to 1 to left adjust the result[/COLOR]
ADCSRA=0x87;

Alex
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top