I hope this makes things clearer. It makes things clearer for me to do this. However I did not
mean for this to get this involved since my question was quiet limited in scope. being is there a way to make
x << 8 end up in a different variable such as:
byte data = x << 8; apparently not.
Here goes
I have two tuning words for the final frequencies (freq)
per Analog Devices
Type Name PA SA Description Data Bits Hex Default value
int FTW1 04:09 02 Frequency Tuning Word 1 Bits 47:0 00
int FTW2 0A:0F 03 Frequency Tuning Word 2 Bits 47:0 00
The binary frequency has to be calculated using this formula
int freq = desired frequency * 2^48/ System Clock
in my case that is for a required frequency of 60,000,000
Frequency Binary Data Calc Binary Representation Size Byte
60000000 56294995342131 10111111001001011000101111110010010110001100 44 48
10111111001001011000101111110010010110001100 this is the binary contained in the number below.
Binary Data Calc
56294995342131
if I assign this number to a long long it takes up 48 bits including the leading zeros
I used in my test sketch like this
long long x;
void loop() {
x = 938249922369;
Serial.print(x);
for (int n = 47; n >= 0; n--)
{
result = bitRead(x, n);
Serial.print(result);
}
Serial.println();
This pints out
1010110111110001001
12:18:27.434 -> 000000001101101001110100000011011010011101000001
12:18:27.536 -> 000000001101101001110100000011011010011101000001
12:18:27.604 -> 000000001101101001110100000011011010011101000001
12:18:27.671 -> 000000001101101001110100000011011010011101000001
12:18:27.772 -> 000000001101101001110100000011011010011101000001
12:18:27.840 -> 000000001101101001110100000011011010011101000001
12:18:27.908 -> 000000001101101001110100000011011010011101000001
12:18:27.976 -> 000000001101101001110100000011011010011101000001
They are all 48 bits long. ( of course because they are the same umber over and over again)
Now I have the 6 address that each have to take a data byte out of this string of binary numbers.
However this is not a string or a real number as shown since I printed it one bit at a time. If you copy the binary number and paste it into excel you get a weird decimal number.
But when I do a bitRead(x, bitNum) I do get the actual bit value either 0 or 1,
that is because the long long does store the number in binary format yet it's value
is shown as 938249922369. Think about it, computers only store stuff in binary, they can't store 152 as 152 but as binary
Addresses 04:09 is used for FTW1 that is 6 bytes at 6 consecutive addresses of 04:09 hex
Now what I have to do in code is.
void setData ( long long Data) {
int startPin = 24;
int startBitsInData = length(Data) - 1;
for (int n = startBitsInData ; n >= startBitsInData - 8 ; n--) {
pinMode(startPin, OUTPUT);
digitalWrite(startPin, bitRead(Data, n));
startPin += 2;
}
}
Here: Data is the value of x above,
startPin is the first pin of the D7:D0
Since I want this variable for other data sizes I'm using this
startBitsInData = length(Data)-1 this I have not verified yet
but it should work since the length of the actual number 938249922369 makes no sense at all.
So I loop through the data one byte section at a time assembling the address ( different code)
o4:09 in this case
so we do 04 in this iteration and setup 8 pins with the bit values in first byte one bit at time .
incrementing the pin number by 2 then repeat until 8 bits and pins are set. This data is stored at address 04
With the address I use a similar setup.
so for
setFTW1( address, data)
{
for each address and data I do this in a loop.
{
setAddress(address);
setData(Data);
pulse write pin (pseudo)
data << 8
}
}
It's not that hard just complex enough to need lots of focus, and when your dog tries to get you to play every hour or so it is easy to loose your place.
Thanks all for being so patient,
pamam