Getting increasing delay in consecutive clock cycles?

Status
Not open for further replies.

savvej

Member
In the following code I am trying to send 6 bits of data serially(synchronously) ,with data to be latched on the peripheral on falling edge of clock.
I am using atmega8 with internal oscillator of 1MHz.Using win-avr compiler library and optimization O2 in AVR studio(4.18).

The following is the function:

void Send_Command(unsigned char command)
{
unsigned char i,temp=0;
//setting DATA PIN as OUTPUT
CRTL_PORT_DIR|=(1<<DATA);

for(i=0;i<6;i++)
{

//~~~Changing Data~~~
CRTL_PORT|=(1<<CLOCK);//clock=1
temp=((command>>i) & 0x01);//on DATA(PD0) pin
if(temp)
CRTL_PORT|=(1<<0);
else
CRTL_PORT&=~(1<<0);
_delay_us(1);
CRTL_PORT&=~(1<<CLOCK);//clock=0
_delay_us(1);


}
}


Now when i send "command=0b00000010" ans argument,and simulate the function in Proteus ,I get increasing delay in consecutive clock cycles which is not understandable by me.
I have attached the "Digital Analysis " snapshot with the post. also my c code(which is actually partially complete code to program PIC16f628A).
 

Attachments

  • pic_prog_dig_analysis.JPG
    61.8 KB · Views: 278
  • pic_programmer.c
    3.3 KB · Views: 246
I have attached as said by john blue(on chat saying that maybe using pic may not cause the problem),trying out same code with pic.but heere too they is increasing delay in successive clock cycles.

snapshot & pic project file attached.Code is compiled using PIC C18 compiler and written using MPLAB IDE(8.7).
 

Attachments

  • pic_programmer_using_avr_debugging.zip
    16.9 KB · Views: 235
  • pic_prog_dig_analysis_using_pic.JPG
    69.2 KB · Views: 272
Last edited:
I ran through this in ISIS the problem here is
Code:
        command >> i ;
each iteration is one bigger i = 0 through 5 you should use
Code:
        CRTL_PORT|=(1<<CLOCK);//clock=1
	temp &= 0x01;//on DATA(PD0) pin
	if(temp)
		CRTL_PORT|=(1<<0);
	else
		CRTL_PORT&=~(1<<0);
	Delay1TCY();
	CRTL_PORT&=~(1<<CLOCK);//clock=0
	Delay1TCY();
	command >>= 1;
 
Last edited:
Nice one Sir..Good observation...
Thanks....

PS:shouldn't it be "temp=(command & 0x01)" instead of "temp&=0x01" in second line of code you suggested?
 
Oh yeah sorry, load temp first!! At least you got me thinking. I love a problem
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…