iss wrote: ↑Thu Oct 29, 2020 7:37 pm
thekorex wrote: ↑Thu Oct 29, 2020 5:42 pm ...
Thank you for reporting @
thekorex!
First post is updated again with the
correct sketch!
I was looking for exactly one of these and found the schematics and sketch here. It works great, but I would like to be able to interface a button to execute the DRAM test, which I have done in the below code. But I want it to stop when it fails, I then want to be able to change the DRAM and hit the button again to start a new test. Currently with the 'While (1);' statement it will put the unit in the endless loop where you have to RESET the arduino to start a new test. I don't want to have to restart the arduino.
I have tried to remove the While statement and put in a 'return;' but that generates just a constant loop of FAILED being printed via the serial monitor and I have to reset the Arduino to stop it.
Looks like this in the serial monitor:
Code: Select all
DRAM TESTER Selected: 256K x 1
Pass #1...
FAILED $1
FAILED $3
FAILED $5
FAILED $7
FAILED $9
FAILED $B
FAILED $D
FAILED $F
FAILED $11
FAILED $13
FAILED $15
FAILED $17
FAILED $19
the code is below. any help would be greatly appreciated.
Code: Select all
#include <Bounce2.h>
#include <SoftwareSerial.h>
#define DI 15 // PC1
#define DO 8 // PB0
#define CAS 9 // PB1
#define RAS 17 // PC3
#define WE 16 // PC2
#define XA0 18 // PC4
#define XA1 2 // PD2
#define XA2 19 // PC5
#define XA3 6 // PD6
#define XA4 5 // PD5
#define XA5 4 // PD4
#define XA6 7 // PD7
#define XA7 3 // PD3
#define XA8 14 // PC0
#define M_TYPE 10 // PB2
#define R_LED 11 // PB3
#define G_LED 12 // PB4
#define RXD 0 // PD0
#define TXD 1 // PD1
#define BUS_SIZE 9
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 13; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 205; // the debounce time; increase if the output flickers
/* ================================================================== */
volatile int bus_size;
//SoftwareSerial USB(RXD, TXD);
const unsigned int a_bus[BUS_SIZE] = {
XA0, XA1, XA2, XA3, XA4, XA5, XA6, XA7, XA8
};
//-----------------------------------------------------
void setBus(unsigned int a) {
int i;
for (i = 0; i < BUS_SIZE; i++) {
digitalWrite(a_bus[i], a & 1);
a /= 2;
}
}
void writeAddress(unsigned int r, unsigned int c, int v) {
/* row */
setBus(r);
digitalWrite(RAS, LOW);
/* rw */
digitalWrite(WE, LOW);
/* val */
digitalWrite(DI, (v & 1)? HIGH : LOW);
/* col */
setBus(c);
digitalWrite(CAS, LOW);
digitalWrite(WE, HIGH);
digitalWrite(CAS, HIGH);
digitalWrite(RAS, HIGH);
}
int readAddress(unsigned int r, unsigned int c) {
int ret = 0;
/* row */
setBus(r);
digitalWrite(RAS, LOW);
/* col */
setBus(c);
digitalWrite(CAS, LOW);
/* get current value */
ret = digitalRead(DO);
digitalWrite(CAS, HIGH);
digitalWrite(RAS, HIGH);
return ret;
}
void error(int r, int c)
{
unsigned long a = ((unsigned long)c << bus_size) + r;
digitalWrite(R_LED, LOW);
digitalWrite(G_LED, HIGH);
interrupts();
Serial.print(" FAILED $");
Serial.println(a, HEX);
Serial.flush();
//while(1);
return;
}
void ok(void)
{
digitalWrite(R_LED, HIGH);
digitalWrite(G_LED, LOW);
interrupts();
Serial.println(" PASSED!");
Serial.flush();
//while(1);
return;
}
void blink(void)
{
digitalWrite(G_LED, LOW);
digitalWrite(R_LED, LOW);
delay(1000);
digitalWrite(R_LED, HIGH);
digitalWrite(G_LED, HIGH);
}
void green(int v) {
digitalWrite(G_LED, v);
}
void fill(int v) {
int r, c, g = 0;
v &= 1;
for (c = 0; c < (1<<bus_size); c++) {
green(g? HIGH : LOW);
for (r = 0; r < (1<<bus_size); r++) {
writeAddress(r, c, v);
if (v != readAddress(r, c))
error(r, c);
}
g ^= 1;
}
blink();
}
void fillx(int v) {
int r, c, g = 0;
v &= 1;
for (c = 0; c < (1<<bus_size); c++) {
green(g? HIGH : LOW);
for (r = 0; r < (1<<bus_size); r++) {
writeAddress(r, c, v);
if (v != readAddress(r, c))
error(r, c);
v ^= 1;
}
g ^= 1;
}
blink();
}
void setup() {
int i;
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(115200);
while (!Serial)
; /* wait */
Serial.println();
Serial.print("DRAM TESTER ");
for (i = 0; i < BUS_SIZE; i++)
pinMode(a_bus[i], OUTPUT);
pinMode(CAS, OUTPUT);
pinMode(RAS, OUTPUT);
pinMode(WE, OUTPUT);
pinMode(DI, OUTPUT);
pinMode(R_LED, OUTPUT);
pinMode(G_LED, OUTPUT);
pinMode(M_TYPE, INPUT);
pinMode(DO, INPUT);
digitalWrite(WE, HIGH);
digitalWrite(RAS, HIGH);
digitalWrite(CAS, HIGH);
digitalWrite(R_LED, HIGH);
digitalWrite(G_LED, HIGH);
if (digitalRead(M_TYPE)) {
/* jumper not set - 41256 */
bus_size = BUS_SIZE;
Serial.print("Selected: 256K x 1 ");
} else {
/* jumper set - 4164 */
bus_size = BUS_SIZE - 1;
Serial.print("Selected: 64K x 1 ");
}
Serial.flush();
digitalWrite(R_LED, LOW);
digitalWrite(G_LED, LOW);
//noInterrupts();
for (i = 0; i < (1 << BUS_SIZE); i++) {
digitalWrite(RAS, LOW);
digitalWrite(RAS, HIGH);
}
digitalWrite(R_LED, HIGH);
digitalWrite(G_LED, HIGH);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
if ( (millis() - lastDebounceTime) > debounceDelay) {
if (buttonState == LOW) {
Serial.println("");
interrupts(); Serial.println("Pass #1..."); Serial.flush(); noInterrupts(); fillx(0);
interrupts(); Serial.println("Pass #2..."); Serial.flush(); noInterrupts(); fillx(1);
interrupts(); Serial.println("Pass #3..."); Serial.flush(); noInterrupts(); fill(0);
interrupts(); Serial.println("Pass #4..."); Serial.flush(); noInterrupts(); fill(1);
ok();
lastDebounceTime = millis(); //set the current time
}
else if (buttonState == HIGH) {
lastDebounceTime = millis(); //set the current time
}//close if/else
}//close if(time buffer)
}//close void loop