Interesting. Using SPI on arduino works really well, but I've just realized that the MISO/MOSI/SS/SCK pins are fixed on that platform(?) - I have been using ESP8266 for a long time now and go to some lengths on that platform to avoid interrupts while shifting data out.
I assume that it would be a good idea to wrap the code in cli()/sei() to mitigate that possibility if you are doing your own shifting? Also worth pointing out that this is a clocked protocol. You can have pauses between chunks of data, you just need to keep the clock and data signals in sync. I am also almost certain that the shifting code should not be bracketed by toggling the LE pin. Before you shift any data, do this: digitalWrite(PIN_LE, LOW); // In this state we can write data to the shift register without it affecting output pin state Shift the data out - this fills ups the HV5530 shift register - and when you are done do this: digitalWrite(PIN_LE, HIGH); // Transfer data from the Shift register to the latch digitalWrite(PIN_LE, LOW); // Store the data in the latch - i.e. set the output pin state to match what is in the latch This way, you can take as long as you like filling up the shift register with the data you want. On Monday, October 8, 2018 at 2:31:21 PM UTC-4, SWISSNIXIE - Jonathan F. wrote: > > I'm using HV5122/HV5222 in all my applications, and im pretty sure most of > the microchip HV series are identical only differ in voltage and some > protocol types. > > They can be driven at 5V, but 'm using a Level Shifter (CD4504) to shift > from 5 to 12V > > How ever, one major issue with these IC's is that if you use arduino, > flicker can occur depending on your arduino and code. > If you translate the "digitalWrite()" to assembler code, you get about 55 > assembler commands. > > To shift out 64bit of data, you need around 130 "digitalWrite()"'s if you > do it sloppy, if you check for following 0 or 1 you can save some, but lets > figure you need 130. > > 130 digitalWrite() * 55 Assembler commands = 7150 commands. > If your Arduino runs at 16Mhz one command takes about 62ns > If your Arduino runs at 8Mhz one command takes about 124ns > > To run 7150 commands, it would take 443us for 16Mhz and 886us for 8Mhz. > And this calculation does not include delays in execution that are created > by interrupts! So in some case you will se flickering in the digits! It > happened to me alof of times, so i created the follwing function that can > be way faster than digital write: > > https://github.com/sgtJohnny/sunix/blob/master/sunix.ino > > #define DATA PD5 //define Dataline >> #define OE 6 //define latch pin >> #define CLK PD7 //define clockline >> #define thePort PORTD //define Hardware port where Shift-Registers are >> connected >> > > >> void setOutputs(unsigned long val_one, unsigned long val_two) { //Function >> to shift out 2 x 32bit fast enough to prevent flicker! >> > // ------------WARNING!-------------------- >> // This functions operates directly on ports, not via digitalWrite() >> // because digitalWrite() would be to slow, and display would flicker >> // if different pins are used, you maybe hav to change the variable >> "thePort" >> // to the matching I/O port letter of the controller! >> >> digitalWrite(OE, LOW); //Disable Outputs to prevent flicker >> >> //Send first 32-bit variable value >> >> for (int i = 0; i < 32; i++) { >> thePort &= ~_BV(DATA); //Data LOW >> if ( bitRead(val_one, i) == 1) { >> thePort |= _BV(DATA); //Data HIGH >> } >> thePort |= _BV(CLK); //CLK HIGH >> thePort &= ~_BV(CLK); //CLK LOW >> } >> >> //Send second 32-bit variable value >> for (int i = 0; i < 32; i++) { >> thePort &= ~_BV(DATA); //Data LOW >> if ( bitRead(val_two, i) == 1) { >> thePort |= _BV(DATA); //Data HIGH >> } >> thePort |= _BV(CLK); //CLK HIGH >> thePort &= ~_BV(CLK); //CLK LOW >> } >> digitalWrite(OE, HIGH); //Enable Outputs >> >> } >> > > If one would use a Arduino Mega or STM32 you could use the second SPI Port > to shift out to the Registers > > >> -- You received this message because you are subscribed to the Google Groups "neonixie-l" group. To unsubscribe from this group and stop receiving emails from it, send an email to neonixie-l+unsubscr...@googlegroups.com. To post to this group, send an email to neonixie-l@googlegroups.com. To view this discussion on the web, visit https://groups.google.com/d/msgid/neonixie-l/78f0c3f0-165d-4bc4-9f36-59606001564d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.