Write HEX value out on Arduino digital lines (4) - arduino

I am attempting to address 16 bytes on an SRAM chip using 74595 to load memory and then read it later. My issue is the addressing to the memory is 4 bits that I want to control from the Arduino. I would prefer a method to write the decimal value out as binary to the 4 lines at once, but not sure of the best or most efficient method.

Related

Design of compression using OpenCL FPGA ,Memory allocation

I am trying to implement lossy compression algorithms using OpenCL ,I have divided the work into two kernels ,one for implementing the algorithm itself and the other one is used for encoding ,means that ,I am trying to concatenate different sized bytes into the stream of the compressed data ,the problem is that ,I am getting high initiation interval due to inefficient memory accesses ,and it takes too much time for the encoding part ,when I opened HTML report ,I got the following message :
**stallable, 13 reads and 25 writes.
Reduce the number of write accesses or fix banking to make this memory system stall-free. Banking may be improved by using compile-time known indexing on lowest array dimension.
Banked on bits 0, 1 into 4 separate banks.
Private memory implemented in on-chip block RAM
My question is ,how could I improve the allocation of the stream ,the way i do it is as follow :
unsigned char __attribute__((numbanks(4),bankwidth(8))) out[outsize];
but it is inefficient ,is there any technique or way that I can use for better utilization?
The way I do encoding is that ,I am adding byte while monitoring the index of last modified bit and byte ,so I am doing exoring and because sometime I got more than one byte or less than one btye so I work byte by byte

How to make .print() macro use F() by default (Arduino)

I usually use base(hardware's UART) serial communication for debugging during development.
This means that most of the text snend to print() will not be send in a final product (limited to repair level only messages).
with mine debugging messages being of a considerable info with loot of tabs and stated variables (and their descriptions), I find that mine 1K5 lined project spends several times more RAM on debugging messages then on program itself.
With one letter being one byte 2000 letters is nothing.
Most of mine non-debugging serial communication (during development is using software serial Tx) and using write function, works with bytes themselves and does not send actual text. (currently mine serial communication routine function and structure uses 6 byte blocks including addressing).
To the point: I use Streaming.h to speed the text addition to serial sending.
It is annoying to keep putting Text strings into F() every single time
F() Function slows the operation of the device because rather then Globally wasting RAM it reads it from flash every time its used and without it mine debuging messages use too much SRAM (arduino loads them as a global variables)
Is there a way of making print() use F() function without editing the Wire.h library ? (which would block me from being able to automatically update the header files)
You should use F() to store you text in FLASH memory, you can't avoid this.
You can define the macro:
#define FPRINT(x) print(F(x))
Serial.FPRINT("text");
Or even like that:
#define SFPRINT(x) Serial.print(F(x))
SFPRINT("test");
Of course, you can replace FPRINT with anything you want, that is not pre-defined (in this case you will get compiler warning).
You can also use printf_P function from <stdio.h> and PSTR macro from <avr/pgmspace.h> (they should in included by default to you program in Arduino IDE).
Typical use with text stored in RAM:
int a = 5;
printf("This is my variable: %d", a);
Result:
Sketch uses 1946 bytes (6%) of program storage space.
Global variables use 39 bytes (1%) of dynamic memory
Use with text stored in FLASH:
int a = 5;
printf_P(PSTR ("This is my variable: %d"), a);
Result:
Sketch uses 1958 bytes (6%) of program storage space.
Global variables use 15 bytes (0%) of dynamic memory

Is there any way to read/write 9-data bit, 2-stop bit and 1- parity bit UART message from/to MCF52235 ColdFire microcontroller

I want to communicate between MCF52235 ColdFire microcontroller and a specific unit which has following message specifications
9-data bits
2- stop bits
one parity bit
However, the MCF52235 ColdFire microcontroller data sheet says it supports
"Data format can be 5,6, 7 or 8 bits with even, odd or no parity".
I wonder is there any tricky way to address this issue.
Thanks

Add to QByteArray with 1 byte the 9-th bit

I have a situation right now when I have after reading the byte stream from COM port in object of QByteArray type exactly and only 1 byte of data. BUT one very non-friendly protocol requires to have 9 bits of data after reading data from COM port.
But according to win32API function: ReadFile(....) I can read from the COM stream ONLY bytes= 1,2,3.....
So - That's why I am reading only 8 bits=1 byte with help of this function and with help of some operations with parity bit I am calculating the value of the 9th bit of generalized data...
So on one hand I have 1 byte (8 bits) of proper(real) data - on another hand I have a value of this 9th bit (0 or 1); 2 objects which in sum must create the value of generalized data.
How I can combine these objects into one & final QByteArray object? Because the global function ReadComData can and must return only QByteArray object.
UARTs cannot "write" 9-bit data. On the wire, your (typically 8-bit) data are usually framed between a start-bit and a stop-bit, so you have 10 bits transmitted for every byte you send. If you have a parity bit, it is transmitted after the last data bit, but before the stop bit. But this is generated by the sending UART, not part of a protocol. A data bus for a typical UART 16550 is only 8-bits wide (you can actually send 5-, 6-, 7-, or 8-bit data).
On the receiving end, the UART has to be configured based on what is on the wire. If your sender is using a parity bit, then you program the UART (via the "COM" port settings) accordingly. The parity bit is just to help check for errors on the wire. It is based on the data bits -- you cannot put another data bit in a parity bit. The receiving UART can be used to check for parity errors (read via the line status register (LSR)), and this can be passed up to you via system calls.
It is possible your protocol is splitting up the data across multiple bytes. If that's the case, then convert two bytes into one 16-bit word and mask the 6 bits you don't want to use.

Data compression for microcontroller

I am doing a project with a PIC microcontroller. I have an ADC sampling and saving data to a RAM memory, once the RAM is filled I need to send it via Bluetooth with a PIC microcontroller.
My data is very redundant, I have about 10-20 consecutive bytes which are the same value, then it changes and still the same for about 10-20 consecutive bytes.
I want to compress the data which is about 512Kbytes to send it faster through bluetooth, 512Kbytes of data takes about 2 second to transfer by Bluetooth at 2Mbps. The decompression will be fast because the data is transferred to a Dual Core ARM Platform so there is no problem with that.
Is there any algorithm to compress data relatively fast for a PIC microcontroller like PIC24 or dsPIC at about 40MIPS ?
Based on that description, it sounds like run-length encoding would be perfect for you. It's a very simple algorithm; it only requires a few lines of code.

Resources