Boo0ns / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

shiftIn misses input 8 #467

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use the circuit on the shiftin tutorial page
2. Use the new shiftIn function included since 0021
3. Notice the lack of input of the 8th button

After switching the code from the previous shift in method to the newly 
included version I noticed that it wasn't picking up my 8th button.

I looked at the code in wiring_shift.c and noticed that it was pulling the 
clock high then low, whereas the previous function (used in the tutorial) 
pulled it low then high...

While I have yet to read the datasheet of various 4021's I can only assume 
there is an error in the code and not in the 4021...

If others operate inversely I would add a parameter to switch things around.

Patch attached.

Original issue reported on code.google.com by nic...@gmail.com on 25 Jan 2011 at 1:55

Attachments:

GoogleCodeExporter commented 9 years ago
Oops, messed up the patch... here's the right one...

--- wiring_shift_old.c  2011-01-24 20:46:32.000000000 -0500
+++ wiring_shift.c  2011-01-24 20:47:04.373648000 -0500
@@ -29,12 +29,12 @@
    uint8_t i;

    for (i = 0; i < 8; ++i) {
-       digitalWrite(clockPin, HIGH);
+       digitalWrite(clockPin, LOW);
        if (bitOrder == LSBFIRST)
            value |= digitalRead(dataPin) << i;
        else
            value |= digitalRead(dataPin) << (7 - i);
-       digitalWrite(clockPin, LOW);
+       digitalWrite(clockPin, HIGH);
    }
    return value;
 }

Original comment by nic...@gmail.com on 25 Jan 2011 at 1:58

Attachments:

GoogleCodeExporter commented 9 years ago
We need to look into this, so I'm marking it as 1.0.

Original comment by dmel...@gmail.com on 9 Feb 2011 at 2:48

GoogleCodeExporter commented 9 years ago

Original comment by dmel...@gmail.com on 12 Feb 2011 at 8:04

GoogleCodeExporter commented 9 years ago
Were you able to confirm this issue?

I re-downloaded the install from the site for a new notebook and used it to 
upload an unchanged sketch for a midi controller (16 buttons), as soon as I 
did, buttons 8 and 16 stopped working.  I re-patched the core using the above 
patch, reuploaded and all was right again :)

The only potential issue I can see would be if there are different methods of 
shifting in depending on what IC is being used... I have limited knowledge in 
that area though...

Original comment by nic...@gmail.com on 12 Feb 2011 at 8:30

GoogleCodeExporter commented 9 years ago
I'm using the 74HC165 shift register, the same thing happens to me and by 
changing the clockPin as per the patch, it resolves the issue.

Without the patch it actually thinks that D0 is D1, D1 is D2, etc. E.g. D0 as 
high would output 00000010, D1 as high would output 00000100, which is why D7 
gets missed.

Original comment by a...@insidegadgets.com on 10 Apr 2011 at 5:41

GoogleCodeExporter commented 9 years ago
I am also using the 165 and it needs a inverted clock from the 595 on the same 
bus. I would assume that that is what this patch is doing.

Some chips read on high->low transition and some from low->high?

Original comment by swur...@gmail.com on 21 Apr 2011 at 11:30

GoogleCodeExporter commented 9 years ago
I have noticed this issue too using a 74LS165.  Looking at the datasheets, I 
think the problem is that the '165 loads the first bit when the LOAD pin is 
taken high, while the '595 needs to be clocked before it loads the first bit.  
So the current shiftIn loses the first bit when it clocks before reading.  Not 
sure how to fix this without another input parameter or a second set of 
functions.

Original comment by eric.e.l...@gmail.com on 6 Jun 2011 at 7:44

GoogleCodeExporter commented 9 years ago

Original comment by dmel...@gmail.com on 24 Aug 2011 at 6:50

GoogleCodeExporter commented 9 years ago

Original comment by dmel...@gmail.com on 16 Dec 2011 at 10:08

GoogleCodeExporter commented 9 years ago
ShiftIn in Arduino 1.0.1 doesn't work correctly with the 4021. I had to use the 
shiftIn function declared in the code here: 
http://arduino.cc/en/Tutorial/ShftIn11

I'd like to look into this matter, but I'm a total nood with code.google.com so 
I need some time to find my way

Original comment by b...@seremetis.net on 1 Aug 2012 at 4:43

GoogleCodeExporter commented 9 years ago
Also made a forum post before I found out about this issue:
http://arduino.cc/forum/index.php/topic,116835.0.html

Original comment by b...@seremetis.net on 1 Aug 2012 at 4:44

GoogleCodeExporter commented 9 years ago
There is a workaround:
If you turn the clock on before turning the control flag down, you avoid the 
extra positive clock transition.
 digitalWrite(shiftClock, HIGH);
 digitalWrite(shiftControl, LOW);
I'm not sure if this is a bug or a missing feature. The problem is that the 
first bit is already on the Q8 output when first positive clock transition 
happens in shiftIn. I think this is what is described in the datasheet as "In 
the HCC/HCF4021B, the CLOCK input of theinternal stage is ”forced” 
whenasynchronous parallel entry is made".

Original comment by fodber on 8 Mar 2013 at 11:55

GoogleCodeExporter commented 9 years ago
fodber's workaround works like a charm - for reference "shiftControl" is the 
latch pin. The IC also has a clock inhibit pin, but there is no need to use it. 
Putting the latch high blocks the clock, so the first transition from low to 
high is missed.

Original comment by MarkRGod...@gmail.com on 18 Oct 2014 at 9:45