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.

_delay_us() function is incorrect for ATMEGA128 connected to LTC1799 External clock

Status
Not open for further replies.

kunal5959

Junior Member level 3
Joined
Jul 26, 2011
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,644
I am using LTC1799 IC to generate a clock signal of 1.832 MHz for my project. The fuse settings seem to be right . when i use following code for test i get inaccurate value of delay
# define F_CPU 1843200UL
# define SCLK_ON PORTA|=(1<<PORTA0)
# define SCLK_OFF PORTA&=~(1<<PORTA0)
#define SCLK_tick _delay_us(100)
int main(){
for(;;){
SCLK_OFF; SCLK_tick ;
SCLK_ON; SCLK_tick ;
}
}

For the above code i get a clock signal with period as 214 us instead of 200 us. Is it due to the fact that _delay_us() is not working properly, clock is not set properly in code, fuse settings or a deviation of 14 us is acceptable/quite normal in microseconds range.?
 

There is more involved in timing than the delay function. You need to look at the assembler listing for the code and find out how many clock cycles are used for each instruction used to run the "for loop", turn the port pin on and off, call the delay subroutine and return, etc. It would take about 26 clock cycles to add up to the 14 extra Us.
 

Also, looking at the delay.h file comments, it states that it rounds up fractions of clock cycles to ensure that the minimum delay is met. So, the delay will be 100 Us or longer. With the clock speed you are using there will be fractions because it does not divide evenly into 100 Us,
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top