Skip to content

3.5MHZ SPI Clock

June 13, 2014

I stuffed the 20MHZ resonator in the avr board and adjusted the code a bit. I couldn’t get bang on 4mhz for the SPI clock so I chose 3.5MHZ rather than be over 4. The adjustment is coarse because I’m adding a noop to each half cycle at .05us(50 NANO-seconds!). I also shortened the delay between the trigger pulse from the AVR and the start of the pulse string. The result is in the image below. The 1802 is firing a write to the shift register every 2.5us and the 8 clock pulses are easily finished before the next request.
14-06-13 new timing

I haven’t actually tried driving a peripheral at this speed but I’m going to solder the 74165 in place and try my various bits and pieces.

The clock code in the AVR now looks as follows(olduinoII_ISPV4F). It’s worth noting that the AVR is polling for the 1802’s N0 line which is a 1 instruction loop with interrupts off. It doesn’t have to catch that small pulse that loads the shift register though – the N0 line stays high for well over a microsecond.

inline void justclock(){ //just run the spi clock
    clockport=clockbv;//clock up, notclock down
    asm("nop\n");
    clockport=notclockbv;//clock down, notclock up
    asm("nop\n");asm("nop\n");
    clockport=clockbv;//clock up, notclock down
    asm("nop\n");asm("nop\n");
    clockport=notclockbv;//clock down, notclock up
    asm("nop\n");asm("nop\n");
    ...
    clockport=notclockbv;//clock down, notclock up
}
...
    state1802=running;
    noInterrupts();
    while(true){ //loop for 1802 program output
        while (PIND&0x40); //wait for SPI signal to go low
        pindsave=PIND; //grab the n0 line while it's valid
        while (0==(PIND&0x40)); //wait for trailing edge - signal goes high again
        if (pindsave&0x04){ //if it's for me ** have to test this now
            char1802=busin(); //grab the character and clock the SPI bus
            cout<<char1802; //send it to the host
        } else{ //not for me, have to do this fast
             justclock(); //just clock the SPI bus
        }
    }
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: