Go Down

Topic: 64-bit counter with 8 registers (Read 288 times) previous topic - next topic

hypertroxics

May 12, 2019, 03:00 pm Last Edit: May 12, 2019, 05:06 pm by hypertroxics
Hello.

I want to send a LOW signal to each frame sequentially for smart chess that I chose as my final project.
8 * 8 I believe that the matrix will not be.
because it needs an AND gate to connect the data from two sides.
32 bit shifting is doing well.
but when I extend the code to 64 bit, it works up to 32bit and the remaining 32led doesn't respond.

in figure.1
I'm trying to create a 64-bits version of the 32-bits version.
I'll add other stages I did.
I'm glad if you could help me troubleshoot this problem.

The original code is seen in figure.2
As I said, 32-bits works smoothly.
a little bit to change and I said 64 bit try and;

I made it in figure.3, but in vain.
After 32-bits no matter what I do, I do not get results.
If you have information about the subject I'm waiting for your help

PaulRB

#1
May 12, 2019, 04:43 pm Last Edit: May 12, 2019, 04:45 pm by PaulRB
Please read the forum guide to learn how to post code and what else you must include in your question if we are to be able to help you.

PaulRB

#2
May 12, 2019, 05:27 pm Last Edit: May 12, 2019, 05:27 pm by PaulRB
hello Paul,
new in the forum,
I ask you to tell me about my mistakes.
I just saw and corrected the problem in my title.
If there is an error you can see, other than that, please inform me.
thank you.
Is it difficult for you to read the forum guide because it is written in English? What is your preferred language? Perhaps there is a forum section for your language where you can get help more easily.

Grumpy_Mike

Code as a screen dump is useless, it needs to be posted as text using the </> icon in the top left corner of the reply box.

Code without a hardware schematic is useless. So post a schematic. This is a real schematic not a Fritzing physical layout diagram.

GolamMostafa

@OP
Please, use code tag (</>) to post your codes online in this post/reply page. To do so, follow these steps:
(1)  Open your sketch in the IDE and make a copy of it by pressing 'Ctrl+A and then Ctrl+C'.
(2) Open the post/reply page.
(3)  Click on the symbol (</>) in the tool bar of the post page. You will get: [ code ] and [/code ].
(4)  Place the cursor in the middle of [ code ] and [/ code ] and then press Ctrl+V in the Keyboard.
(5)  Your code will appear like this:

Code: [Select]
void setup()
{

}

hypertroxics

Is it difficult for you to read the forum guide because it is written in English? What is your preferred language? Perhaps there is a forum section for your language where you can get help more easily.

I'm new to the forum, as I said. I could not see where the forum guide were originally. Then I found it and corrected my mistake.
I'm sorry I got your time by texting you.
I could not find my preferred language in the forum.

hypertroxics

#6
May 13, 2019, 02:30 am Last Edit: May 13, 2019, 03:01 am by hypertroxics
@OP
Please, use code tag (</>) to post your codes online in this post/reply page. To do so, follow these steps:
(1)  Open your sketch in the IDE and make a copy of it by pressing 'Ctrl+A and then Ctrl+C'.
(2) Open the post/reply page.
(3)  Click on the symbol (</>) in the tool bar of the post page. You will get: [ code ] and [/code ].
(4)  Place the cursor in the middle of [ code ] and [/ code ] and then press Ctrl+V in the Keyboard.
(5)  Your code will appear like this:

Code: [Select]
void setup()
{

}

Code: [Select]


const int tDelay  = 15;  
const int tDelayUs = 625;       // 64 * 15,625 msec = 1 sec
const int dataPin  = 12;      
const int latchPin = 11;  
const int clockPin = 10;  

void setup()
  {
    pinMode(latchPin, OUTPUT);
    pinMode(dataPin,  OUTPUT);  
    pinMode(clockPin, OUTPUT);
  }

unsigned long int leds1=0;
unsigned long int leds2=0;

void updateShiftRegister()
  {
    unsigned int leds16 = int(leds1);
    unsigned int leds32 = int(leds1>>16);
    unsigned int leds48 = int(leds2);
    unsigned int leds64 = int(leds2>>16);
    
    byte A  = lowByte(leds16);    
    byte B  = highByte(leds16);
    byte C  = lowByte(leds32);
    byte D  = highByte(leds32);
    byte E  = lowByte(leds48);    
    byte F  = highByte(leds48);
    byte G  = lowByte(leds64);
    byte H  = highByte(leds64);

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, LSBFIRST, A);  
    shiftOut(dataPin, clockPin, LSBFIRST, B);  
    shiftOut(dataPin, clockPin, LSBFIRST, C);  
    shiftOut(dataPin, clockPin, LSBFIRST, D);
    shiftOut(dataPin, clockPin, LSBFIRST, E);  
    shiftOut(dataPin, clockPin, LSBFIRST, F);  
    shiftOut(dataPin, clockPin, LSBFIRST, G);  
    shiftOut(dataPin, clockPin, LSBFIRST, H);  
    digitalWrite(latchPin, HIGH);
  }


void loop()
{
  int k;
  for (int i=0;i<8;i++ )
    {
      for(int j=0; j<8; j++)
        {
          updateShiftRegister();
          leds1 = pow(2,32)-1;
          leds2 = pow(2,32)-1;    
          if (k%32 ==0)
            {
              {
                leds1 = pow(2,32)-1;
                leds2 = pow(2,32)-1;
                bitClear (leds1, k);
                
                updateShiftRegister();
                k++;
              }
            }
            
          else (k%32 !=0);
            {
              {
                leds1 = pow(2,32)-1;
                leds2 = pow(2,32)-1;  
                bitClear (leds2,k);
                
                updateShiftRegister();
                k++;
              }
            }
          delay (tDelay);
          delayMicroseconds (tDelayUs);
          
        }
    }
}



hypertroxics

Code as a screen dump is useless, it needs to be posted as text using the </> icon in the top left corner of the reply box.

Code without a hardware schematic is useless. So post a schematic. This is a real schematic not a Fritzing physical layout diagram.

hypertroxics

#8
May 13, 2019, 02:54 am Last Edit: May 13, 2019, 03:02 am by hypertroxics
Code: [Select]

const int tDelay  = 15; 
const int tDelayUs = 625;       // 64 * 15,625 msec = 1 sec

const int dataPin1  = 12;     
const int latchPin1 = 11;   
const int clockPin1 = 10;
 
const int dataPin2  = 8;     
const int latchPin2 = 7;   
const int clockPin2 = 6; 


void setup()
  {
    pinMode(latchPin1, OUTPUT);
    pinMode(dataPin1,  OUTPUT); 
    pinMode(clockPin1, OUTPUT);

    pinMode(latchPin2, OUTPUT);
    pinMode(dataPin2,  OUTPUT); 
    pinMode(clockPin2, OUTPUT);
  }

unsigned long int leds1=0;
unsigned long int leds2=0;

void updateShiftRegister1()
  {
    unsigned int leds16 = int(leds1);
    unsigned int leds32 = int(leds1>>16);
   
    byte A  = lowByte(leds16);   
    byte B  = highByte(leds16);
    byte C  = lowByte(leds32);
    byte D  = highByte(leds32);

    digitalWrite(latchPin1, LOW);
    shiftOut(dataPin1, clockPin1, LSBFIRST, A); 
    shiftOut(dataPin1, clockPin1, LSBFIRST, B); 
    shiftOut(dataPin1, clockPin1, LSBFIRST, C); 
    shiftOut(dataPin1, clockPin1, LSBFIRST, D);
    digitalWrite(latchPin1, HIGH);
  }

void updateShiftRegister2()
  {
    unsigned int leds48 = int(leds2);
    unsigned int leds64 = int(leds2>>16);

    byte E  = lowByte(leds48);   
    byte F  = highByte(leds48);
    byte G  = lowByte(leds64);
    byte H  = highByte(leds64);

    digitalWrite(latchPin2, LOW);
    shiftOut(dataPin2, clockPin2, LSBFIRST, E); 
    shiftOut(dataPin2, clockPin2, LSBFIRST, F); 
    shiftOut(dataPin2, clockPin2, LSBFIRST, G); 
    shiftOut(dataPin2, clockPin2, LSBFIRST, H); 
    digitalWrite(latchPin2, HIGH);
  }

void loop()
{
  int k;
  for (int i=0;i<8;i++ )
    {
      for(int j=0; j<8; j++)
        {
          updateShiftRegister1();
          updateShiftRegister2();

          leds1 = pow(2,32)-1;
          leds2 = pow(2,32)-1;   
          if (k%32 ==0)
            {
              {
                leds1 = pow(2,32)-1;
                leds2 = pow(2,32)-1;
                bitClear (leds1, k);
               
          updateShiftRegister1();
          updateShiftRegister2();
                k++;
              }
            }
           
          else (k%32 !=0);
            {
              {
                int m = k-32;
                leds1 = pow(2,32)-1;
                leds2 = pow(2,32)-1; 
                bitClear (leds2,m);
               
                updateShiftRegister1();
                updateShiftRegister2();
                k++;
              }
            }
          delay (tDelay);
          delayMicroseconds (tDelayUs);
         
        }
    }
}

hypertroxics

Code: [Select]

const int tDelay  = 15; 
const int tDelayUs = 625;       // 64 * 15,625 msec = 1 sec

const int dataPin1  = 12;     
const int latchPin1 = 11;   
const int clockPin1 = 10;
 
const int dataPin2  = 8;     
const int latchPin2 = 7;   
const int clockPin2 = 6; 


void setup()
  {
    pinMode(latchPin1, OUTPUT);
    pinMode(dataPin1,  OUTPUT); 
    pinMode(clockPin1, OUTPUT);

    pinMode(latchPin2, OUTPUT);
    pinMode(dataPin2,  OUTPUT); 
    pinMode(clockPin2, OUTPUT);
  }

unsigned long int leds1=0;
unsigned long int leds2=0;

void updateShiftRegister1()
  {
    unsigned int leds16 = int(leds1);
    unsigned int leds32 = int(leds1>>16);
   
    byte A  = lowByte(leds16);   
    byte B  = highByte(leds16);
    byte C  = lowByte(leds32);
    byte D  = highByte(leds32);

    digitalWrite(latchPin1, LOW);
    shiftOut(dataPin1, clockPin1, LSBFIRST, A); 
    shiftOut(dataPin1, clockPin1, LSBFIRST, B); 
    shiftOut(dataPin1, clockPin1, LSBFIRST, C); 
    shiftOut(dataPin1, clockPin1, LSBFIRST, D);
    digitalWrite(latchPin1, HIGH);
  }

void updateShiftRegister2()
  {
    unsigned int leds48 = int(leds2);
    unsigned int leds64 = int(leds2>>16);

    byte E  = lowByte(leds48);   
    byte F  = highByte(leds48);
    byte G  = lowByte(leds64);
    byte H  = highByte(leds64);

    digitalWrite(latchPin2, LOW);
    shiftOut(dataPin2, clockPin2, LSBFIRST, E); 
    shiftOut(dataPin2, clockPin2, LSBFIRST, F); 
    shiftOut(dataPin2, clockPin2, LSBFIRST, G); 
    shiftOut(dataPin2, clockPin2, LSBFIRST, H); 
    digitalWrite(latchPin2, HIGH);
  }

void loop()
{
  int k;
  for (int i=0;i<8;i++ )
    {
      for(int j=0; j<8; j++)
        {
          updateShiftRegister1();
          updateShiftRegister2();

          leds1 = pow(2,32)-1;
          leds2 = pow(2,32)-1;   
          if (k%32 ==0)
            {
              {
                leds1 = pow(2,32)-1;
                leds2 = pow(2,32)-1;
                bitClear (leds1, k);
               
          updateShiftRegister1();
          updateShiftRegister2();
                k++;
              }
            }
           
          else (k%32 !=0);
            {
              {
                int m = k-32;
                leds1 = pow(2,32)-1;
                leds2 = pow(2,32)-1; 
                bitClear (leds2,m);
               
                updateShiftRegister1();
                updateShiftRegister2();
                k++;
              }
            }
          delay (tDelay);
          delayMicroseconds (tDelayUs);
         
        }
    }
}


or, in this way if I do 32 bits separately, do you think it works?

Grumpy_Mike

#10
May 13, 2019, 07:30 am Last Edit: May 13, 2019, 07:30 am by Grumpy_Mike
Sorry but I can't see much of a match between your code and your schematic.

Your code seems to address four shift registers on each of two sets of pins. That is the code suggest you have two separate chains of four shift registers. Your schematic shows one chain of eight shift registers and that is all.

Your code seems to be using only the least significant four bits of each shift register leaving the other bits always zero. Why are you wasting bits like this.

A schematic should show all your circuit like the circuit attached to the shift registers.

Your code should have an explanation as to what it does and what you expect it to do. You mentioned two codes earlier which one of these is the code you posted?

PaulRB


Go Up