Pages: [1]   Go Down
Author Topic: shiftOut Timing Issue  (Read 857 times)
0 Members and 1 Guest are viewing this topic.
CT, USA
Offline Offline
Sr. Member
****
Karma: 3
Posts: 446
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am wondering if shiftOut method (defined in wiring_shift.c) could add a delay parameter since not all devices can handle the default tight timing.

In a project I did recently, the shifted output was sometimes garbled. And I had to modify the code to add a slight delay between the writes to get it working.

Code:
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val)
{
        int i;

        for (i = 0; i < 8; i++)  {
                if (bitOrder == LSBFIRST)
                        digitalWrite(dataPin, !!(val & (1 << i)));
                        delay(5);
                else                        
                        digitalWrite(dataPin, !!(val & (1 << (7 - i))));
                        delay(5);
                digitalWrite(clockPin, HIGH);
                delay(5);
                digitalWrite(clockPin, LOW);
                delay(5);
        }
}

If the next version of the library could take a delay parameter, it would definitely be more useful.
Logged

Norway
Offline Offline
Sr. Member
****
Karma: 4
Posts: 423
microscopic quantum convulsions of space-time
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would think most shiftregisters can handle say 20 MHz just fine. For example the 74HC595 states 100 MHz as a typical shift out frequency. A datasheet for 74LS164 states a clock frequency of 36 MHz. The (normal) arduino at 16 MHz don't really approach those values for shifting out data.

Of course I don't know anything about your project, but I would think this has something to do with your schematics. There are a lot of things that can affect performance. Like long wires, noise, capacitance, load... to name a few.

I don't really know if a delay argument to shiftOut() would be useful except on rare occations, and also yet another argument to pass to the function. But on the other hand it could probably be educational if used with some example code to shift things out very slowly (like once a second or so). Then again this is not under my control smiley
Plus, you managed to hack your own version just fine.
Logged

Pages: [1]   Go Up
Jump to: