Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
    pic_prog_dig_analysis.JPG
    61.8 KB · Views: 274
  • pic_programmer.c
    3.3 KB · Views: 243
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: 232
  • pic_prog_dig_analysis_using_pic.JPG
    pic_prog_dig_analysis_using_pic.JPG
    69.2 KB · Views: 269
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:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top