Go Down

Topic: Control 40 LED using five TPIC6C595 (Read 4160 times) previous topic - next topic

PaulRB

#15
Sep 29, 2016, 11:23 pm Last Edit: Sep 29, 2016, 11:27 pm by PaulRB
Which is what his code is using but expecting it to cope with 64 bits.
No, the OP's code has binary literals starting "0B" which should allow 64 bits/digits. I don't think it matters if "0B" or "0b" is used. Link

Binary literals can also start "B" without a zero before the B but these are limited to 8 bits. Link

Grumpy_Mike

Quote
I don't think it matters if "0B" or "0b" is used. Link
I do think it matters link:-
https://www.arduino.cc/en/Reference/IntegerConstants
from that page:-

Quote
2 (binary)        B1111011    leading 'B'      only works with 8 bit values (0 to 255)
                                               characters 0-1 valid

PaulRB

I do think it matters link:-
https://www.arduino.cc/en/Reference/IntegerConstants
from that page:-

From my first link, which I think is the relevant one, because there is a 0 before the B/b in the OP's code:
Quote
Integer constants can be written as binary constants, consisting of a sequence of '0' and '1' digits, prefixed by '0b' or '0B'.

Gennady

#18
Sep 30, 2016, 02:25 pm Last Edit: Sep 30, 2016, 04:34 pm by Gennady
Hi!
Yesterday I found a mistake. I have a 40-bit register, and I am sending 64 bits ( because ULL). The three MS-bytes shear lost. The error is that the cycle FOR starts with the SPI.transfer of the LS-byte.
Code: [Select]

l.z =  xArray[indicator] ;
digitalWrite (LE, LOW);
for (int i = 0; i < 8; i = i + 1)

   {
     SPI.transfer (l.b);
   }
digitalWrite (LE, LOW);


I changed the program and removed the cycle. There are suspicions that the SPI.transfer does not operate within the "for" loop (also in case for(int i=7;i<0; i=i-1)  ) .

Now code:
Code: [Select]

l.z =  xArray[indicator] ;
  digitalWrite (LE, LOW);
 
  SPI.transfer (l.b[4]);
  SPI.transfer (l.b[3]);
  SPI.transfer (l.b[2]);
  SPI.transfer (l.b[1]);
  SPI.transfer (l.b[0]);
 
digitalWrite (LE, HIGH);


, and it works.

Small question. How to do Boolean Operator || (logical or) for two ULL 64-bit variable?

ULL z = ULL y ||  ULLx

I understand that it is necessary to break the ULL  variable to 8 bytes and do Boolean Operator || (logical or)  over each two bytes separately?
Code: [Select]

ultra long long xArray[42] ={...............}; // 40 of 64bit words
ultra long long yArray[42] ={...............}; // 40 of 64bit words

ultra long long x ;
ultra long long y ;
ultra long long z ;
ultra long long zForIndication ;

byte  x1 ;
byte  y1;
byte  z1;


union MatrixData
{
 unsigned long long z;
 byte z1[8];
};

MatrixData z;


union MatrixData
{
 unsigned long long y;
 byte y1[8];
};

MatrixData y;


union MatrixData
{
 unsigned long long x;
 byte x1[8];
};

MatrixData x;

loop ()
{


x.x =  xArray[n] ; // were n is number
y.y =  yArray[n] ;

for (int i = 0; i < 8; i = i + 1)

   {
     

z.z1[i] = x.x1[i] || y.y1[i]; //byte words

   }

zForIndication = z.z; //64 bi word

}


Thanks!

Grumpy_Mike

See the bit where you code turns into italics? That is the forum's html interpreter mangling your code by mistaking it for a html command. Now if you were to use code tags that would not happen but some how you are reluctant to do this.

Gennady

#20
Sep 30, 2016, 04:24 pm Last Edit: Sep 30, 2016, 05:55 pm by Gennady
Sorry!
 I was insert code separators!

CrossRoads

You want the resulting bit locations to be a 1 if either variable was a 1 in that location? Use a single |, not two ||
https://www.arduino.cc/en/Reference/BitwiseAnd
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Gennady

Yes!  Will use byte x |  bute y . What about rest of code? Correct?

CrossRoads

"There are suspicions that the SPI.transfer does not operate within the "for" loop (also in case for(int i=7;i<0; i=i-1)  ) ."
It does. For example:
Code: [Select]

digitalWrite (ssPin, LOW);
for (x=0; x<8, x=x+1){
SPI.transfer(dataArray[x]); // transfer 8 bits of data
}
digitalWrite (ssPin, HIGH);

Whether it works after your unions and
SPI.transfer (l.b[4]);
type formats, I  don't know.
Also,
ultra long long xArray[42] ={...............}; // 40 of 64bit words <<< (comment does not match, should be 42)
I haven't seen data type 'ultra long long' before, is that 64  bits?
If so, that array will be 42 x 8 bytes long = 336 bytes of memory.

Is this intended to be a function? It only declares the variable z and the array bytez1. Why not just have them in the area before setup() with the other variables?  No comments, so no idea what is intended.
You have same union MatrixData name 3 or 4 times, they need to be unique if these are function calls.
Code: [Select]

union MatrixData
{
 unsigned long long z;
 byte z1[8];
};



Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Gennady

#24
Oct 01, 2016, 07:08 am Last Edit: Oct 01, 2016, 07:42 am by Gennady
Whether it works after your unions

Yes, after union. But don't work.

"
ultra long long xArray[42] ={...............}; // 40 of 64bit words <<< (comment does not match, should be 42)
I haven't seen data type 'ultra long long' before, is that 64  bits?

40---> 42 2 -spare cell, may be used ultra long long xArray[40] ={...............}; It's array 40 word x64bits= 320bytes. Because only 40 leds.


The challenge is to make "bitwise or"  operation between two 64-bit words (in ULL format) from the two different arrays ( ULL xArrays,  ULL yArray) and send 5 LS bytes of rezult byte zArray by SPI.
I revised the program:
Code: [Select]

ultra long long xArray[40] ={...............}; // 40 of 64bit words
ultra long long yArray[40] ={...............}; // 40 of 64bit words
byte zArray[8];

union MatrixData
{
 unsigned long long y;
 byte y1[8];
};
MatrixData y;

union MatrixData
{
 unsigned long long x;
 byte x1[8];
};
MatrixData x;

loop () {
x.x =  xArray[n] ; // were n is number, generated by some program function
y.y =  yArray[n] ;

for (int i = 0; i < 8; i = i + 1)    {
zArray[i] = x.x1[i] | y.y1[i]; //bitwise or
 }
 //send five LS bytes from byte zArray to 40 LED registr
digitalWrite (LE, LOW);
  SPI.transfer (zArray[4]);
  SPI.transfer (zArray[3]);
  SPI.transfer (zArray[2]);
  SPI.transfer (zArray[1]);
  SPI.transfer (zArray[0]); 
digitalWrite (LE, HIGH);
}
 


It checked that the Arduino is working with 64bits variable, but only in the ULL format.

Can you suggest another idea how to do it?

Thanks!

PaulRB

I don't understand what it is that is causing you a problem. You code seems to be getting more complicated than it needs to be. Can you explain again what is wrong and why the ideas we have suggested do not solve the problem. Also post a short but complete piece of code to demonstrate the problem, which we can amend and compile before posting back for you.

It is a complex piece of code, but here is something I wrote which uses the techniques e are describing.

Go Up