Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 22 of 22

Thread: Tinsy 4.0 SPI Shift Register Circuit for Active Inductor Controller

  1. #1
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16

    Tinsy 4.0 SPI Shift Register Circuit for Active Inductor Controller

    Hello all;

    I am new to Arduino and especially SPI protocol and would be very thankful for any such help on my project.

    what i am attempting to do is switch taps on an active inductor controller electronically that exactly mimic a rotating brush assembly. the active inductor controller has 46 taps that need to be switched in a make before break scenario on a continuous basis. what i mean by make before break is the next channel needs to be on before the previous channel switches off. this way current is never interrupted which can cause a reverse inductive spike. the inductive controller uses self inductance or rather inductive reactance like a variac except with DC to control the current flow of two feeds in complete unison at 180 degrees from each other, one increasing in current and the other decreasing in current.
    the below circuit is 6 shift register ic's that will have a Tensy 4.0 attached and below that is the previous work on the code that has been done so far. i have had other help from outside sources but this is as far as i have gotten. the code needs to first run at a slow speed so i can visualize with LED's to verify all is working then change the speed to a working model. the code then must switch at 180 microseconds on each tap.

    Click image for larger version. 

Name:	74HC595B Shift Register Circuit.png 
Views:	11 
Size:	43.7 KB 
ID:	21752

    Code:
      // This sketch controlls multiple 74HC595 shift regiters in cascade to electronically control Figuera's active inductor
      // controller by switching on taps located on part G connected to transistors in a "Make Before Break" scenario. by changing
      // tap locations continuously changes inductance which controls current flow of the primaries.
      // this sketch utilizes timing overlap to eliminate bsck Bemf or Cemf that would ocurr with single on off tap. it mimics
      // the brush rotation of a mechanical rotating brush thus creates a continuous increase/decrease current through the primaries.
      // Created by D Livesay aka Marathonman  with the help of Paul RB 9/19/2019.
      // this sketch is distributed freely but if you use this program then post build on line give credit where credit is 
      // due and not claim as your own design.
      // to adapt to your build change pin numbers, delay time and Array sequences.
    
    #include <SPI.h>
    
    unsigned long long int registerBuffer = 0b11;
    const unsigned long long int bit45 = 1ULL<<45;
    unsigned long int lastUpdate;
    const unsigned long updatePeriod = 10000UL;
    const byte latchPin = (10);   // SS or CS output to STCK latch pin 12 on 74HC595
    const int clockPin = (13);  // SCk to Seial Clock SHCP Shift Clock pin 11 on 74HC595 
    const int dataPin =  (11);  // Mosi to DS in pin 14 on 74HC595
    
    void setup() {
      Serial.begin(115200);
      SPI.begin();
      SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
      pinMode(latchPin, OUTPUT);
      pinMode(clockPin, OUTPUT);
      pinMode(dataPin,  OUTPUT); 
    }
    
    void loop() {
      if (millis() - lastUpdate > updatePeriod) { //Is it time to update the registers?
        lastUpdate = millis();
        byte wrap = (registerBuffer & bit45) != 0; //Copy bit 45 from the buffer
        registerBuffer <<= 1; //Shift all bits in the buffer 1 place to the right
        if (wrap) registerBuffer |= 1; //Paste the copied value from bit 45 into bit 0
        unsigned long long int temp = registerBuffer; //Take a copy of the buffer
        SPI.transfer(&temp, 6); //Send the buffer to the registers
        digitalWrite(latchPin, HIGH); //Latch the updated values into the register's output pins
        digitalWrite(latchPin, LOW);
      }
    }

  2. #2
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    Unfortunately i am unable to figure out how to get the code to shift to left when it hits the last tap. i need it to shift right then left on a continuous basis.
    sorry for the mistake on code above const unsigned long updatePeriod = 10000UL; should be const unsigned long updatePeriod = 180UL; at least i think so.

  3. #3
    Senior Member
    Join Date
    Jul 2020
    Posts
    398
    Use 12 shift registers, with every other output routed to the switches. Then feed the bit pattern '111' through.

    595's are not bidirectional - you'll need something else for that, I think 74HC299's might be suitable (they lack output
    latch, but I don't think you need that for this application).

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,642
    Note: I have never used unsigned long long int before, my understanding is it should create 64 bit variable, but guessing.

    So did a quick and dirty using uint64_t instead as then I know it should be 64 bits. Your bit to test if you are at end is off by one...
    Here is a quick and real dirty test showing

    Code:
    uint64_t registerBuffer = 0b11;
    const uint64_t bit45 = 1ULL << 44;
    
    void setup() {
      while (!Serial) ;
      for (int i = 0; i < 100; i++) {
        uint64_t temp = registerBuffer;
        for (int j = 0; j < 64; j++) {
          Serial.print((temp & (1ULL << 63)) ? "1" : "0");
          temp <<= 1;
        }
        Serial.println();
        uint8_t wrap = (registerBuffer & bit45) != 0; //Copy bit 45 from the buffer
        registerBuffer <<= 1; //Shift all bits in the buffer 1 place to the right
        registerBuffer &= 0x1fffffffffffull;
        if (wrap) registerBuffer |= 1; //Paste the copied value from bit 45 into bit 0
      }
    }
    
    void loop() {
    }
    And Output:
    Code:
    0000000000000000000000000000000000000000000000000000000000000011
    0000000000000000000000000000000000000000000000000000000000000110
    0000000000000000000000000000000000000000000000000000000000001100
    0000000000000000000000000000000000000000000000000000000000011000
    0000000000000000000000000000000000000000000000000000000000110000
    0000000000000000000000000000000000000000000000000000000001100000
    0000000000000000000000000000000000000000000000000000000011000000
    0000000000000000000000000000000000000000000000000000000110000000
    0000000000000000000000000000000000000000000000000000001100000000
    0000000000000000000000000000000000000000000000000000011000000000
    0000000000000000000000000000000000000000000000000000110000000000
    0000000000000000000000000000000000000000000000000001100000000000
    0000000000000000000000000000000000000000000000000011000000000000
    0000000000000000000000000000000000000000000000000110000000000000
    0000000000000000000000000000000000000000000000001100000000000000
    0000000000000000000000000000000000000000000000011000000000000000
    0000000000000000000000000000000000000000000000110000000000000000
    0000000000000000000000000000000000000000000001100000000000000000
    0000000000000000000000000000000000000000000011000000000000000000
    0000000000000000000000000000000000000000000110000000000000000000
    0000000000000000000000000000000000000000001100000000000000000000
    0000000000000000000000000000000000000000011000000000000000000000
    0000000000000000000000000000000000000000110000000000000000000000
    0000000000000000000000000000000000000001100000000000000000000000
    0000000000000000000000000000000000000011000000000000000000000000
    0000000000000000000000000000000000000110000000000000000000000000
    0000000000000000000000000000000000001100000000000000000000000000
    0000000000000000000000000000000000011000000000000000000000000000
    0000000000000000000000000000000000110000000000000000000000000000
    0000000000000000000000000000000001100000000000000000000000000000
    0000000000000000000000000000000011000000000000000000000000000000
    0000000000000000000000000000000110000000000000000000000000000000
    0000000000000000000000000000001100000000000000000000000000000000
    0000000000000000000000000000011000000000000000000000000000000000
    0000000000000000000000000000110000000000000000000000000000000000
    0000000000000000000000000001100000000000000000000000000000000000
    0000000000000000000000000011000000000000000000000000000000000000
    0000000000000000000000000110000000000000000000000000000000000000
    0000000000000000000000001100000000000000000000000000000000000000
    0000000000000000000000011000000000000000000000000000000000000000
    0000000000000000000000110000000000000000000000000000000000000000
    0000000000000000000001100000000000000000000000000000000000000000
    0000000000000000000011000000000000000000000000000000000000000000
    0000000000000000000110000000000000000000000000000000000000000000
    0000000000000000000100000000000000000000000000000000000000000001
    0000000000000000000000000000000000000000000000000000000000000011
    0000000000000000000000000000000000000000000000000000000000000110
    0000000000000000000000000000000000000000000000000000000000001100
    0000000000000000000000000000000000000000000000000000000000011000
    0000000000000000000000000000000000000000000000000000000000110000
    0000000000000000000000000000000000000000000000000000000001100000
    0000000000000000000000000000000000000000000000000000000011000000
    0000000000000000000000000000000000000000000000000000000110000000
    0000000000000000000000000000000000000000000000000000001100000000
    0000000000000000000000000000000000000000000000000000011000000000
    0000000000000000000000000000000000000000000000000000110000000000
    0000000000000000000000000000000000000000000000000001100000000000
    0000000000000000000000000000000000000000000000000011000000000000
    0000000000000000000000000000000000000000000000000110000000000000
    0000000000000000000000000000000000000000000000001100000000000000
    0000000000000000000000000000000000000000000000011000000000000000
    0000000000000000000000000000000000000000000000110000000000000000
    0000000000000000000000000000000000000000000001100000000000000000
    0000000000000000000000000000000000000000000011000000000000000000
    0000000000000000000000000000000000000000000110000000000000000000
    0000000000000000000000000000000000000000001100000000000000000000
    0000000000000000000000000000000000000000011000000000000000000000
    0000000000000000000000000000000000000000110000000000000000000000
    0000000000000000000000000000000000000001100000000000000000000000
    0000000000000000000000000000000000000011000000000000000000000000
    0000000000000000000000000000000000000110000000000000000000000000
    0000000000000000000000000000000000001100000000000000000000000000
    0000000000000000000000000000000000011000000000000000000000000000
    0000000000000000000000000000000000110000000000000000000000000000
    0000000000000000000000000000000001100000000000000000000000000000
    0000000000000000000000000000000011000000000000000000000000000000
    0000000000000000000000000000000110000000000000000000000000000000
    0000000000000000000000000000001100000000000000000000000000000000
    0000000000000000000000000000011000000000000000000000000000000000
    0000000000000000000000000000110000000000000000000000000000000000
    0000000000000000000000000001100000000000000000000000000000000000
    0000000000000000000000000011000000000000000000000000000000000000
    0000000000000000000000000110000000000000000000000000000000000000
    0000000000000000000000001100000000000000000000000000000000000000
    0000000000000000000000011000000000000000000000000000000000000000
    0000000000000000000000110000000000000000000000000000000000000000
    0000000000000000000001100000000000000000000000000000000000000000
    0000000000000000000011000000000000000000000000000000000000000000
    0000000000000000000110000000000000000000000000000000000000000000
    0000000000000000000100000000000000000000000000000000000000000001
    0000000000000000000000000000000000000000000000000000000000000011
    0000000000000000000000000000000000000000000000000000000000000110
    0000000000000000000000000000000000000000000000000000000000001100
    0000000000000000000000000000000000000000000000000000000000011000
    0000000000000000000000000000000000000000000000000000000000110000
    0000000000000000000000000000000000000000000000000000000001100000
    0000000000000000000000000000000000000000000000000000000011000000
    0000000000000000000000000000000000000000000000000000000110000000
    0000000000000000000000000000000000000000000000000000001100000000
    0000000000000000000000000000000000000000000000000000011000000000

  5. #5
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    MarkT;
    You would be incorrect 595's can be shifted both directions so i only need 6 - 595's for 46 taps. many Youtube video's state this as a fact.Sorry !

    KurtE;
    Not sure what you mean about being one off. your code is only one way from 0 to 45 not 0 - 45 - 0 continuously like i need similar to the old night rider series.
    see below.
    byte dataArray[] = (
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, // will send out groups of 6
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, // 0b indicates binary data
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, // bite zero is on three times at beginning and end
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100, // two byte on at a time for Make Before Break (overlap)
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000, // except on end 0 & 45
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011,
    }
    }
    Last edited by Marathonman; 09-16-2020 at 09:07 PM.

  6. #6
    Senior Member
    Join Date
    Jul 2020
    Posts
    398
    Let me repeat, the '595 is _not_ bidirectional, you need something like the '299 if you want to shift in either
    direction. If you don't believe me, read the datasheets.

  7. #7
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    Let me repeat,
    Youtube video https://www.youtube.com/watch?v=s97TUARBc2U please watch whole video most informative.
    Youtube video https://www.youtube.com/watch?v=ou3WP3Hp5X0
    Youtube video https://www.youtube.com/watch?v=NIPxSCUH6NQ
    Youtube video https://www.youtube.com/watch?v=oHpjl2CAE0A ping pong effect
    Youtube video https://www.youtube.com/watch?v=L_JAxXybQiQ
    Youtube video https://www.youtube.com/watch?v=EEacd7CKsQE
    Youtube video https://www.youtube.com/watch?v=8RgwYOW8Ww0
    and many more.
    as you were saying.
    all that is happening is the bit is either 1 or 0 causing it to appear to shift left and shift right. the only way to get that many bits is using SPI unsigned long long at the speed i need.
    Last edited by Marathonman; 09-17-2020 at 02:01 AM.

  8. #8
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    Here is another very informative video please watch the whole thing.
    https://www.youtube.com/watch?v=h84c...&frags=pl%2Cwn

    this guy nails it very well.

  9. #9
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,642
    Sorry was simply trying to answer your original question as best as I understood it. Sorry I am not going to watch 8 videos...


    A very Simple, don't have to think much way to, do this is with your table, that you show above...
    Simply do something like:
    Code:
    uint8_t dataArray[] = (
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, // will send out groups of 6
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, // 0b indicates binary data
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, // bite zero is on three times at beginning and end
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100, // two byte on at a time for Make Before Break (overlap)
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000, // except on end 0 & 45
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110,
    0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011,
    }
    uint32_t array_index = 0;
    
      // This sketch controlls multiple 74HC595 shift regiters in cascade to electronically control Figuera's active inductor
      // controller by switching on taps located on part G connected to transistors in a "Make Before Break" scenario. by changing
      // tap locations continuously changes inductance which controls current flow of the primaries.
      // this sketch utilizes timing overlap to eliminate bsck Bemf or Cemf that would ocurr with single on off tap. it mimics
      // the brush rotation of a mechanical rotating brush thus creates a continuous increase/decrease current through the primaries.
      // Created by D Livesay aka Marathonman  with the help of Paul RB 9/19/2019.
      // this sketch is distributed freely but if you use this program then post build on line give credit where credit is 
      // due and not claim as your own design.
      // to adapt to your build change pin numbers, delay time and Array sequences.
    
    #include <SPI.h>
    unsigned long int lastUpdate;
    const unsigned long updatePeriod = 10000UL;
    const byte latchPin = (10);   // SS or CS output to STCK latch pin 12 on 74HC595
    const int clockPin = (13);  // SCk to Seial Clock SHCP Shift Clock pin 11 on 74HC595 
    const int dataPin =  (11);  // Mosi to DS in pin 14 on 74HC595
    
    void setup() {
      Serial.begin(115200);
      SPI.begin();
      SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
      pinMode(latchPin, OUTPUT);
      pinMode(clockPin, OUTPUT);
      pinMode(dataPin,  OUTPUT); 
    }
    
    void loop() {
      if (millis() - lastUpdate > updatePeriod) { //Is it time to update the registers?
        lastUpdate = millis();
    
        SPI.transfer(&dataArray[array_index], 6); //Send the buffer to the registers
        array_index += 6;  // increment to the next one...
        if (array_index >= sizeof(dataArray)) array_index = 0; // wrap back to first item
    
        digitalWrite(latchPin, HIGH); //Latch the updated values into the register's output pins
        digitalWrite(latchPin, LOW);
      }
    }
    Not very eloquent, but could get it done...

  10. #10
    Senior Member
    Join Date
    Jul 2020
    Posts
    398
    Shifting a new pattern in is not the same as shifting in reverse... I think we were at odds because you happened
    to be shifting in a shifting pattern to a set of shift registers. With non-latched shift registers you cannot hide the
    intermediate changes in state, but with the '595 you can shift in an arbitrary new pattern and then reveal using
    the latch pin.

    You said
    MarkT;
    You would be incorrect 595's can be shifted both directions
    Which simply isn't true, but turns out wasn't the issue anyway, as the problem was in generating the patterns,
    not shifting them out.

    If you wanted to update the registers every microsecond, then you would need bidirectional shift registers as
    refreshing the whole pattern couldn't happen in the time available.

  11. #11
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    KurtE;
    Video's are not ment for you. thank you for your help. what about the original code i posted, it seems it is less complicated then an array.??? i do have to ask you can i slow this down enough to get a visual with LED's then speed it up for 180 microseconds which is somewhere in the 330 khz range i think.

    that table was just to give you a visual on the shifting i need.

    MarkT;
    Agreed, i know the registers are not bidirectional but it is how you shift the bits into the register giving the apperence of being bidirectional. then one can use them to give the night rider type of switching which is exactly what i need to do.

    using the SPI function is the only way i can attain the speeds i need whether it be the original code i posted or using an array. using the 4.0 does change things a little as the massive speed increase and single clock processing.
    i ordered a Tensy 4.0 to be able to handle multiple functions at a time which came in today. i will also be using it for two voltage and two current sensors but i can use another Arduino for that if it is to complicated to assimilate into the shift code.

    i do have a valid question, do i need to desolder the LED on pin 13 as i need that pin for my 6 shift registers and i do not want any problems from the LED draining precious current. ?

    PS. update time and millis will be changed to a fasted time. i just need it to be slow enough to get a visual with LED's before faster update.
    Last edited by Marathonman; 09-17-2020 at 06:43 PM.

  12. #12
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    Code would not compile, massive errors to many to list. the original code i posted does compile though.

  13. #13
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,642
    As always when typed in on the fly you can run into issues. Especially for stuff I simply copied from your previous post...

    After fixing your dataArray... (Also moved it after the previous defines... It builds (built where it was as well, but needed to change your ( to a {
    git rid if , after last item, add ; ...

    Code:
    // This sketch controlls multiple 74HC595 shift regiters in cascade to electronically control Figuera's active inductor
    // controller by switching on taps located on part G connected to transistors in a "Make Before Break" scenario. by changing
    // tap locations continuously changes inductance which controls current flow of the primaries.
    // this sketch utilizes timing overlap to eliminate bsck Bemf or Cemf that would ocurr with single on off tap. it mimics
    // the brush rotation of a mechanical rotating brush thus creates a continuous increase/decrease current through the primaries.
    // Created by D Livesay aka Marathonman  with the help of Paul RB 9/19/2019.
    // this sketch is distributed freely but if you use this program then post build on line give credit where credit is
    // due and not claim as your own design.
    // to adapt to your build change pin numbers, delay time and Array sequences.
    
    #include <SPI.h>
    unsigned long int lastUpdate;
    const unsigned long updatePeriod = 10000UL;
    const byte latchPin = (10);   // SS or CS output to STCK latch pin 12 on 74HC595
    const int clockPin = (13);  // SCk to Seial Clock SHCP Shift Clock pin 11 on 74HC595
    const int dataPin =  (11);  // Mosi to DS in pin 14 on 74HC595
    
    uint8_t dataArray[] = {
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, // will send out groups of 6
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, // 0b indicates binary data
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, // bite zero is on three times at beginning and end
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100, // two byte on at a time for Make Before Break (overlap)
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000, // except on end 0 & 45
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011, 0b00000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b11000000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b01100000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00110000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00011000,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001100,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000110,
      0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000011
    };
    
    uint32_t array_index = 0;
    
    void setup() {
      Serial.begin(115200);
      SPI.begin();
      SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
      pinMode(latchPin, OUTPUT);
      pinMode(clockPin, OUTPUT);
      pinMode(dataPin,  OUTPUT);
    }
    
    void loop() {
      if (millis() - lastUpdate > updatePeriod) { //Is it time to update the registers?
        lastUpdate = millis();
    
        SPI.transfer(&dataArray[array_index], 6); //Send the buffer to the registers
        array_index += 6;  // increment to the next one...
        if (array_index >= sizeof(dataArray)) array_index = 0; // wrap back to first item
    
        digitalWrite(latchPin, HIGH); //Latch the updated values into the register's output pins
        digitalWrite(latchPin, LOW);
      }
    }

  14. #14
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    Quote; "Note: I have never used unsigned long long int before, my understanding is it should create 64 bit variable, but guessing."

    That would be a big 10-4, 64 bit variable. sorry i missed it.

    That was not what i was trying to convey as my data array, i was merely trying to get you to understand visually what i was trying to accomplish. if the array thing works then by all means i will try it but i really wanted to get the original code to work.
    i have a huge bag of LED's and i am assembling as we speak to test it out. granted it needs to run slow in order to accomplish this visually.
    thank you immensely for your help.

    WOW ! my Tensy 4.0 is on the bench and man it is small for such a power house. compiled and uploaded sketch and it says zero % of program storage and 7 % of dynamic memory. i am really impressed Paul nice Arduino. to bad about the pin 13 LED though.
    Last edited by Marathonman; 09-17-2020 at 09:36 PM.

  15. #15
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    In function `main': C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy4/main.cpp:51: undefined reference to `setup' C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy4/main.cpp:53: undefined reference to `loop' collect2.exe: error: ld returned 1 exit status Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI Error compiling for board Teensy 4.0

  16. #16
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    KurtE ;
    The code finally compiled but will changing the update period to a longer time will it effect the function of SPI.? i do need to visualize it's functioning properly.
    i realized what you said about code being one off and yes i caught that and fixed/added last line.
    Last edited by Marathonman; 09-20-2020 at 11:09 PM.

  17. #17
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    Here is the updated code using SPI shifted left then right. unfortunately there is no overlap so i might have to use the array example KurtE presented as that has overlap if i can not get the below code changed. i could of course use a cap on the high side driver to have it stay on longer if needed.
    This code is the night rider effect on 46 taps or LED's using SPI compliments of PaulRB of Arduino forum.
    Code:
    #include <SPI.h>
    
    unsigned long long int registerBuffer = 0b11;
    byte shiftPos = 0;
    bool shiftingLeft = true;
    unsigned long int lastUpdate;
    const unsigned long updatePeriod = 177UL;
    const byte latchPin = 10;
    
    void setup() {
      Serial.begin(115200);
      SPI.begin();
      SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
      pinMode(latchPin, OUTPUT);
    }
    
    void loop() {
      if (millis() - lastUpdate > updatePeriod) { //Is it time to update the registers?
        lastUpdate = millis();
        //Shift the register left or right
        if (shiftingLeft) {
          registerBuffer <<= 1; //Shift 1 place to left
          if (++shiftPos == 44) shiftingLeft = false; //Time to switch direction?
        }
        else {
          registerBuffer >>= 1; //Shift 1 place to right
          if (--shiftPos == 0) shiftingLeft = true; //Time to switch direction?
        }
        unsigned long long int temp = registerBuffer; //Take a copy of the buffer
        SPI.transfer(&temp, 6); //Send the buffer to the registers
        digitalWrite(latchPin, HIGH); //Latch the updated values into the register's output pins
        digitalWrite(latchPin, LOW);
      }
    }
    KurtE;

    These lines in the code are not needed as SPI takes care of that since i will be using SPI 0.

    const int clockPin = (13); // SCk to Seial Clock SHCP Shift Clock pin 11 on 74HC595
    const int dataPin = (11); // Mosi to DS in pin 14 on 74HC595


    and

    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);


    my mistake sorry.
    Last edited by Marathonman; 09-21-2020 at 03:52 AM.

  18. #18
    Senior Member
    Join Date
    Aug 2013
    Location
    Gothenburg, Sweden
    Posts
    306
    The following fairly simple code generates the shifted patter, SPI is replaced with prints

    Code:
    uint64_t registerBuffer;
    uint64_t pattern =  0b11;
    /* This will give two identical outputs as start */
    int shiftPos=1, shiftDir=-1;
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      while (!Serial) ;
      Serial.println();
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
      /* shift the pattern one position according to shiftDir */
      shiftPos += shiftDir;
      if (shiftPos<0) { /* change direction if lower end is reached */
        shiftDir = 1;
        shiftPos = 0;
      }
      if (shiftPos>44) { /* change direction if upper end is reached */
        shiftDir = -1;
        shiftPos = 44;
      }
      /* Now shift pattern to current position */
      registerBuffer = (pattern << shiftPos);
      
      /* Print instead of sending SPI */
      uint64_t temp = registerBuffer;
      for (int j = 0; j < 64; j++) {
        Serial.print((temp & (1ULL << 63)) ? "1" : "0");
        if ((63-j)%8==0) Serial.print(' ');
        temp <<= 1;
      }
      Serial.println();
      delay(1000);
    }

  19. #19
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    "/* This will give two identical outputs as start */
    int shiftPos=1, shiftDir=-1;:

    I do not understand what you mean by two identical outputs ? i am also confused as to print instead of SPI, can you explain a little please.
    thanks everyone involved so much.
    Oh, and is this code able to shift at 184us when i need it to? for testing purposes it needs to be slow enough to visualize.

    one last question, on the Tensy 4.0 what 3.3 line do i use as there are two.? i am assuming the upper right one is an output and the one on bottom is input next to the ground.
    Last edited by Marathonman; 09-21-2020 at 03:47 PM.

  20. #20
    Senior Member
    Join Date
    Aug 2013
    Location
    Gothenburg, Sweden
    Posts
    306
    As it says, this is one way to generate the sequence of 64 bit pattern, and can be adapted for other patterns. The code only generates the bit patterns and displays them for inspection. It does not initiate SPI or try send the sequence to the external 595 shift registers.

    The two identical outputs at start is visible if you run the test sketch and watch the output on the serial monitor.
    The details are: the code is initialized to shiftPos=1, shiftDir=-1.
    At the start of first loop shiftPos is updated to 0, while shiftDir is at -1. Giving the first pattern at position 0.
    At the start of the second loop shiftPos is updated to -1 triggering the shift direction change and setting shiftDir = 1; shiftPos = 0; so we get the second pattern also at position 0.

  21. #21
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    I get it now as it makes more sense from your description when i go through the code.
    the only reason i was going to use LED's with the shift registers is if they work out that circuit and code is the actual circuit i will be using at high speed. also the fan73611 high side drivers i will be using are 5 and 3.3 volt logic compatible and i have 100, 405 watt T0-3P IGBT's on the shelf that are dying to to use.

  22. #22
    Junior Member
    Join Date
    Sep 2020
    Location
    Texas, USA
    Posts
    16
    Well since there was no response to the question about the 3.3 volt pins i did some investigating of my own and finally found on another thread. according to the schematic on the 4.0 (thanks Paul) it seems the 3.3 volt pin between the ground and pin 23 as well as the one on the back side is an output. the 3.3 volt pin at the bottom between the vbat and ground is an input. so according to the suggested advice when i put the 4.0 in production i need to cut the usb tether correct ? as i will be using an external 3.3 volt supply to the Tensy as well as the shift registers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •