Possible to share RAM adress with logic flip flop?

If the logic flip flop shall receive equal information as the memory address in the fixed memory address to avoid using port register which requires more instruction cycle to receive and send information, is it possible?

The port registers (or most of them, depending on the chip) reside in the RAM region
that can be accessed and manipulated as fast as possible.

What would be the gain of your technique?

How would you map a byte to a bit?

To make fastest access to items such as LED diodes, buttons, motors, and such.

For example:
RAM adress at 2
logic flip flop at 2
If I programming that to turn LED on or off in RAM address 2 then it also send information to logic flip flop #2 to avoid extra PORT write that takes some more instruction cycle than direct to RAM with logic flip flop connected.

That's what I am thinking in later revision of my home cockpit.

Begraphics:
If the logic flip flop shall receive equal information as the memory address in the fixed memory address to avoid using port register which requires more instruction cycle to receive and send information, is it possible?

The RAM is sealed up inside the CPU and is not externally addressable. You need to use the port registers if you want to interface with the outside world.

It could be possible on a Mega via the external memory interface, but why should one do that?

The fastest access you can get is already exposed as ports.

Yes I know about RAM is sealed inside the microcontroller; but, if I get a microprocessor instead microcontroller; then it should be possible?
External RAM share with flip flop in some memory adress for use with LED diodes, stepper motor, and such. Is that the fastest way than SPI, 74HC595, 74HC16x, and port access. Right?

Begraphics:
Yes I know about RAM is sealed inside the microcontroller; but, if I get a microprocessor instead microcontroller; then it should be possible?
External RAM share with flip flop in some memory adress for use with LED diodes, stepper motor, and such. Is that the fastest way than SPI, 74HC595, 74HC16x, and port access. Right?

Do a search on "Memory Mapped I/O". That is what you are talking about. Back in 1979 that is how the Radio Shack TRS-80 accessed it keyboard using a Z80 CPU and a tri-state Buffer. A 256 byte area of the 64k memory space was used. The lower 8bits of the address bus were the row strobes of an 8x8 matrix. A buffer IC was used to drive the rows directly from the Address bus. Another buffer connected the 8 columns to the databus when a Memory Read instruction was decode from this 256 byte region of memory. You could tell if any key was pressed by PEEK(14591). If the returned value was not zero, a key was pressed.
TRS-80 Memory Map

Chuck.

Chuck: Yes, that's how it is the fastest way to update the instruments in my hobby cockpit simulator which I might will use in continually revisions.
Now I have an issue with pointer.

        unsigned update_instruments[70][70];
        unsigned int bb;
        unsigned int ba;
        for ( ; ba >= update_instruments[ba][bb]; ba-- )
        {
          PORTA = update_instruments[ba][bb];
          if ( ba == 0 )
          {
            &jump;
          }
          for ( ; bb > 0; bb-- )
          {
            PORTB = update_instruments[ba][bb];
          }
        }
        int *jump;

When I am trying to compile it, it shows:
:1100: error: 'jump' was not declared in this scope
&jump;
^
/to the file.../filename.ino:1107:14: warning: unused variable 'skip' [-Wunused-variable]
int *jump;
^
exit status 1
'break' was not declared in this scope

Which Arduino are you using? For most an array of 4900 ints would be quite big.

  &jump;

What would you expect that to do?

Need a 1284P with its 16K SRAM to hold an array of 4900 ints (9800 bytes).

Whandall:
Which Arduino are you using? For most an array of 4900 ints would be quite big.

  &jump;

What would you expect that to do?

I am using MEGA2560.
skip if it find the array[ba] = 0 then it will not continue.

byte update_instruments[70];
byte update_port[255];
byte bb;
byte ba;
for ( ba = 255; ba > 0; ba-- )
{
PORTA = update_port[ba];
if ( ba == 0 )
{
goto skip;
}
for ( bb = 70; bb > 0; bb-- )
{
PORTB = update_instruments[bb];
}
}
skip: ;

Now the compiler did that.
In other void ____()
{
Something that way:
Next increment to add value and the next add zero; if the past increment has value then add this that has zero and next increment is zero so that the goto skip can determine if the array has zero which means no more update is necessary in the void loop function.
}

Begraphics:
byte update_instruments[70];
byte update_port[255];
byte bb;
byte ba;
for ( ba = 255; ba > 0; ba-- )
{
PORTA = update_port[ba];
if ( ba == 0 )
{
goto skip;
}
for ( bb = 70; bb > 0; bb-- )
{
PORTB = update_instruments[bb];
}
}
skip: ;

Now the compiler did that.
In other void ____()
{
Something that way:
Next increment to add value and the next add zero; if the past increment has value then add this that has zero and next increment is zero so that the goto skip can determine if the array has zero which means no more update is necessary in the void loop function.
}

byte update_instruments[70];
byte update_port[255];
byte bb;
byte ba;
for(ba=255;ba>0,ba--){
    PORTA = update_port[ba-1]; //the array is [0..254], [255] is outside of array bounds.
    if ( ba == 0 ) break; // I have never liked the goto statement
    for ( bb = 70; bb > 0; bb-- ) {
       PORTB = update_instruments[bb-1]; // same here
       }
    }

Chuck

Why update_instruments[bb-1]; not just only [bb] ?

Begraphics:
Why update_instruments[bb-1]; not just only [bb] ?

You have defined ba as byte ba[255], since the array contains 255 elements, AND starts at zero, the highest offset is 254.

referencing ba[255] is a no-no, it is a reference to a memory byte outside of the array.

kind of like;

char littleArray[20];

littleArray[100]= 7;// offset 100 is NOT inside "char littleArray[20]"

if you want to use update_instruments[bb], change the for loop range to:

for(bb=254;bb!=255;bb--;)//zero is a valid value, and since bb is a byte, decrementing zero results
// in 255

Chuck.

chucktodd:
You have defined ba as byte ba[255], since the array contains 255 elements, AND starts at zero, the highest offset is 254.

referencing ba[255] is a no-no, it is a reference to a memory byte outside of the array.

kind of like;

char littleArray[20];

littleArray[100]= 7;// offset 100 is NOT inside "char littleArray[20]"




if you want to use update_instruments[bb], change the for loop range to:


for(bb=254;bb!=255;bb--;)//zero is a valid value, and since bb is a byte, decrementing zero results
// in 255




Chuck.

But why bb != 255, what does this mean ? Is that a test? Or do you blind-test me so I am able to correct the code to bb >= 0 ?

Begraphics:
But why bb != 255, what does this mean ? Is that a test? Or do you blind-test me so I am able to correct the code to bb >= 0 ?

When you defined the array as:

char ba[255];
byte bb;

ba is valid from ba[0] to ba[254].

if you try to use a for loop:

for(bb=254; bb > 0 ;bb--){}

this loop will not process offset 0, the first element in the array.

for(bb=254; bb > -1 ;bb--){}
// or
for(bb=254; bb >= 0 ;bb--){}

This for loop will never exit. a byte’s range is 0 … 255, when you decrement 0 you get 255. So, the test bb > -1 will always be true and bb >= 0 will also always be true.

so the only termination value is:

for(bb=254; bb != 255 ;bb--){}

The bb != 255 says: while bb not equal to 255 process the for loop.

If you want to process the array from 0 to 254 then:

for(bb=0; bb < 255 ;bb++){}
//or
for(bb=0; bb != 255 ;bb++){}

No tricks, the exclamation point character “!” is a logical NOT operator, don’t confuse it with the BINARY NOT operator “~”.

Logical operator work with TRUE, FALSE.

Binary operators work at the bit level:

byte b;

b = 1;    // or B00000001
~b = 254; // or B11111110  This is read as 'not b'
b & b = 1; // 
b & ~b = 0; 
b | ~b = 255;

Chuck.

chucktodd:
When you defined the array as:

char ba[255];

byte bb;




ba[] is valid from ba[0] to ba[254].

if you try to use a for loop:


for(bb=254; bb > 0 ;bb–){}




this loop will not process offset 0, the first element in the array.



for(bb=254; bb > -1 ;bb–){}
// or
for(bb=254; bb >= 0 ;bb–){}




This for loop will never exit. a byte's range is 0 .. 255, when you decrement 0 you get 255. So, the test **bb > -1** will always be true and **bb >= 0** will also always be true.

so the only termination value is:


for(bb=254; bb != 255 ;bb–){}




The **bb != 255** says: while **bb** not equal to **255** process the for loop.

If you want to process the array from 0 to 254 then:


for(bb=0; bb < 255 ;bb++){}
//or
for(bb=0; bb != 255 ;bb++){}





No tricks, the exclamation point character "!" is a logical NOT operator, don't confuse it with the BINARY NOT operator "~".

Logical operator work with TRUE, FALSE.

Binary operators work at the bit level:


byte b;

b = 1;    // or B00000001
~b = 254; // or B11111110  This is read as ‘not b’
b & b = 1; //
b & ~b = 0;
b | ~b = 255;





Chuck.

Understood the first part of 255.
But I do not clearly understood b & b, B & ~b, and b | ~b.

Begraphics:
Understood the first part of 255.
But I do not clearly understood b & b, B & ~b, and b | ~b.

binary math operators, I figure that if you are going you control ‘memory mapped’ IO, (except with the Arduino’s only the MEGA can actually do memory mapped IO, it get complex) you are going to need to know how to turn on and off individual bits of your “sensor gauge’s”

if you have 8 lights that you need to control, you can store their on/off status in ONE byte.

if you assign each light its own byte you have to waste 7 bytes.

lets associate light0 with bit 0, light1 with bit 1 … light 7 with bit 7.

byte lights=0; // all lights are off

// to turn on light 5 I need to set bit 5 to a 1.  There are multiple ways to do this
// such as 
lights = lights +32;  // because the 5th bit is equal to 2^5 or 32, but this only works if light 5 is
// already off, else bad things happen
// 32  = B00100000;

lights = lights | 32;  //only turns bit 5 on, if it is already on nothing changes.

// the Binary Or operator "|" compares each bit of the the two operands, if either bit is 1 the
// result bit is 1, only if both bits are 0 is the result 0

//  now to turn light 5 off using binary operators
// ~32 = B11011111;

lights = light & (~32); // the & (Binary And) operator compares each bit of the the two operands
// if both bits are 1 the result bit is 1 else the result bit is 0.

Chuck.

chucktodd:
binary math operators, I figure that if you are going you control 'memory mapped' IO, (except with the Arduino's only the MEGA can actually do memory mapped IO, it get complex) you are going to need to know how to turn on and off individual bits of your "sensor gauge's"

if you have 8 lights that you need to control, you can store their on/off status in ONE byte.

if you assign each light its own byte you have to waste 7 bytes.

lets associate light0 with bit 0, light1 with bit 1 .. light 7 with bit 7.

byte lights=0; // all lights are off

// to turn on light 5 I need to set bit 5 to a 1.  There are multiple ways to do this
// such as
lights = lights +32;  // because the 5th bit is equal to 2^5 or 32, but this only works if light 5 is
// already off, else bad things happen
// 32  = B00100000;

lights = lights | 32;  //only turns bit 5 on, if it is already on nothing changes.

// the Binary Or operator "|" compares each bit of the the two operands, if either bit is 1 the
// result bit is 1, only if both bits are 0 is the result 0

//  now to turn light 5 off using binary operators
// ~32 = B11011111;

lights = light & (~32); // the & (Binary And) operator compares each bit of the the two operands
// if both bits are 1 the result bit is 1 else the result bit is 0.




Chuck.

Understood, but isn't it better to using Bits and Bytes functions?