I've added an example for writing the external memory from other sources as the atmega portC output in above examples.
The input could be an ADC, VGA camera module, etc. The ramdisk reads in the data on rising edge of the /WR signal, the /WR signal could be clocked by an external source as well. The below example writes 614kB of data (640x480x2), while clocking with atmega /WR signal (a slow way to do it). You may clock up to 12MB/sec with an external /WR clock (ie the camera's chip rd signal).
// RAMDISK v.1.1 - 8Mbytes - testing with arduino compatible platform
// RAMDISK MODULE requires 3.3Volt signal levels and power supply!
// Not tested with VGA camera chip
// UPDATE: March 12 2014
// Provided as-is, no warranties of any kind
// c 2014 by Pito
/*
RAMDISK MODULE PINS:
|-----------------------------
DATA0 --- D0 L |
DATA1 --- D1 @ E |
DATA2 --- D2 D |
DATA3 --- D3 |
Ground --- GND |
DATA4 --- D4 RAMDISK v1.1 |
DATA5 --- D5 |
DATA6 --- D6 |
DATA7 --- D7 |
NMS --- /MS Module Select (optional)|
NRD --- /RD Read signal, 85ns min |
NWR --- /WR Write signal, 85ns min |
NDATA --- /DATA (A0 with PMP bus) |
3V3 --- 3.3Volts power |
|-----------------------------
LED - indicates rd/wr memory accesses
*/
/*
* NRD - read signal active low, min 85ns, mind the delayed input on atmega mcu
* NWR - write signal active low, min 85ns, max 8us
* NDATA - access to sram data - low, access to controller - high
* NMS - module select - active low (must be hardwired to low with single module)
*/
#include <DigitalIO.h>
// HW interface to the RAMDISK module (an example only, do assign yours control pins):
DigitalPin<12> NRD(OUTPUT); // /RD active LOW
DigitalPin<13> NWR(OUTPUT); // /WR active LOW
DigitalPin<14> NDATA(OUTPUT); // /Data active LOW
// PORTC is the Data bus D0-D7 (an example only)
typedef union {
unsigned long value;
struct {
unsigned char nib1: 4; // lowest nibble
unsigned char nib2: 4;
unsigned char nib3: 4;
unsigned char nib4: 4;
unsigned char nib5: 4;
unsigned char nib6: 4;
unsigned char nib7: 4;
unsigned char nib8: 4; // highest nibble
};
}
nybbles ;
void setup()
{
// init the RAMDISK
ramdisk_init ();
Serial.begin(115200);
}
// init the RAMDISK
inline void ramdisk_init (void){
delay(1);
NRD = 1; // Idle
NWR = 1; // Idle
NDATA = 0; // Idle = data mode
DDRC = 0x00; // sets DATA PORT as the input
// make a dummy read
NRD = 0;
NRD = 1;
}
// load the 24bit address into
inline void loadadr (unsigned long addr)
{
nybbles temp;
temp.value = addr;
NDATA = 1; // adress mode
DDRC = 0xFF; // sets Data output
PORTC = (temp.nib6); // 6th nibble of the address - the highest
NWR = 0; NWR = 1; // write the nibble into the RAMDISK address counter
PORTC = (temp.nib5); // 5th nibble of the address
NWR = 0; NWR = 1;
PORTC = (temp.nib4); // 4th nibble of the address
NWR = 0; NWR = 1;
PORTC = (temp.nib3); // 3rd nibble of the address
NWR = 0; NWR = 1;
PORTC = (temp.nib2); // 2nd nibble of the address
NWR = 0; NWR = 1;
PORTC = (temp.nib1); // 1st nibble of the address - the lowest
NWR = 0; NWR = 1;
NDATA = 0; // data mode
DDRC = 0x00; // sets Data input
}
// block write from external data source - writes nbytes of data from addr
inline void wr_block_ext(unsigned long addr, unsigned long nbytes){
loadadr(addr);
DDRC = 0x00; // sets Data input - feed data from an external source
while (nbytes--){
// example: clocking by /WR from atmega
NWR = 0; NWR = 1; // writes data in on rising edge of /WR
// above could be clocked by external /WR clock source as well
// writing speed up to 12MB/sec possible
}
}
void loop()
{
unsigned char di, d;
unsigned long int timestart, elapsed, elapsedloop, errors, N;
volatile unsigned long int i;
Serial.println("RAMDISK: N-BLOCK EXT INPUT DATA WR TEST (ATMEGA's /WR CLOCKING)");
// writes a block of N-bytes from address 0x11111
// the data are fed in via ramdisk's data bus, bypassing atmega port
// possible inputs - flash ADC, VGA video chip, etc.
// the /WR works as a clock, it clocks in data on /WR rising edge
// you may clock /WR with atmega (this example) or via an external source
timestart = micros();
wr_block_ext(0x11111, 614400L);
elapsed = micros() - timestart;
Serial.print("N. of Block Byte WRITEs: ");
Serial.println(614400L);
Serial.print(614400*1000L/elapsed);
Serial.println(" kB/sec");
while(1);
}
RAMDISK: N-BLOCK EXT INPUT DATA WR TEST (ATMEGA's /WR CLOCKING)
N. of Block Byte WRITEs: 614400
1589 kB/sec