Skip to content

More Clocking Around

April 3, 2014

I’ve had another yet another go at the SPI clock. I had been using SBI/CBI to set the clock bits which is much faster than digitalWrite() but was still giving me a frequency around 1 mhz. I decided to dedicate port C to the clock & not-clock lines so I could trigger them with PORTC=xx which should translate to a single instruction. I actually had to add a no-op between the assignments to keep the frequency around 2 MHZ. The 4021 shift register wants a pulse of at least 180 uS and I was below that without the no-op. I may look at a faster shift register for a later version but i think this will make enough of a difference for now. In the picture below you see the new 2mhz clock waveform and the old 1mhz. the code below is the output of objdump showing the c source and generated assembly.

      PORTC=0x02;//clock up, notclock down
     158:	82 e0       	ldi	r24, 0x02	; 2
     15a:	88 b9       	out	0x08, r24	; 8
      PORTC=0x01;//clock down, notclock up
     15c:	91 e0       	ldi	r25, 0x01	; 1
     15e:	98 b9       	out	0x08, r25	; 8
     160:	00 00       	nop
      PORTC=0x02;//clock up, notclock down
     162:	88 b9       	out	0x08, r24	; 8
     164:	00 00       	nop

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: