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.

timing problem in serial ADC reading

Status
Not open for further replies.

bhoomi_shah2906

Member level 1
Joined
Oct 2, 2009
Messages
40
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,589
hi..

i am using serial ADC for converting the analog signal in digital...

in this I am using follow code....

for(i=12;i>0;i++)
{
clk_low;
asm("nop");
if ((PINB & 0x01)==0x01) data|=(1<<i);
else data&=~(1<<i);
clk_high;
}


i am reading the data at proper time...
now my problem is it takes so much time for jump and for loop.

it takes around 1.2us after clk_high to go up to clk_low signal..

i want to read the data at faster rate...
so ca anyone suggest me the code which can read the data faster than my this code..

i am using the atmega32 controller with 16MHz crystal frequency..
 

you have a few choices:

1) running the chip at a higher clock frequency;
2) using a faster chip;
3) using hardware spi;
4) coding better;
5) using assembly for this routine.
...

if you look at your code, it has one fatal error, and the body of the for loop is poorly structured and you can certainly speed it up significantly, simply by doing a better coding job.
 

thanks for the reply and that is what i am asking..
how can i code for this in another way??


can u please guide me to make new code???
give some idea of doing this SPI without for loop so can make it faster..
 

hey no one is there who can help me???

its too urgent for me to solve....

the above code takes 50us for reading the 12bit data..
i want to read this 12bit data with 1MHz rate..

so how it can be done????
 

Look at the ADC time constraints. It needs a certain amount of time to 'measure' the voltage and calculate the value, and unless you can shorten that time (I think it's substantial compared to the rest of the code) you won't be able to speed it up.

Now, I don't know about the Atmel chips, but PIC18F45K20 has an ADC acquisition time of a dozen or so microseconds (less than 20uS).

Perhaps a higher performance external ADC may be able to do it at a faster rate.
 

There are several options:
- learn about the purpose and operation of the atmega's hardware SPI interface
- analyze your code and understand what's ineffective with it.
You should think about the difference between
Code:
data|=(1<<i)
and
Code:
data >>1 | 0x800
The former is involving a repeated shift with an AVR

The for loop is more or less required for the code, there are more effective optimization options in using register variable, depends on your C-compiler's features. For best results, it's always suggested to review the assembler output and possibly correct the source or use inline assembler for critical instructions.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top