I have a project where I controle 18 LEDS with 3 74HC595 IC's.
When I upload my code and connect the LEDs to the Arduino uno & nano, everyting works fine.
But when I connect it to the Teensy 4.0 (the controller I want to use in my project) the LEDs don't do what they are expected too.
In this sipmle code, all the LEDs will turn on one by one till it reaches the end. Then they turn off one by one. This repeats itself.
This works perfectly when I connect it to an arduino uno & nano. But when connected to a Teensy 4.0 (with the same pin numbers) the LEDs follow a different pattern/ appear to be random.
Has anyone got a clue why the Teensy reacts this way, or what causes this issue?
In the attachment is a quick diagram of my circuit. I use a powersupply instead of the arduino / teensy power to give it enough Amps but I can't show this in the circuit diagram.
There is no point/need to slow the master clock of the Teensy down just to write to some shift registers. It’s sort of like driving a Porsche at 10 km/hr on the Autobahn. Makes no sense.
The following code fragment is a hack but it should illustrate my point. You only need to fix the pulses being written to the 74LS595’s. It’s untested but I would expect it should work at full clock speed of the Teensy 4.0.
There are far better hardware based ways to do what you’re achieving there. Give us some more details about the project and we can probably give far better solutions that bit banging shift registers.
Edit:
Not sure if Teensy 4.0 supports the shiftOut() function. If it does, that would be a far cleaner solution.
Each 74hc595 should have a 0.1uF ceramic bypass cap. Also with 330R series resistors, you may be exceeding the maximum current of the '595, if only by a little (~77mA vs 70mA).
It might be better to use hardware SPI on the Teensy, then you can set that to run at a suitable speed for the '595s without slowing down the CPU.