Adjusting timing and delays to make things feel a bit snappier

This commit is contained in:
Kevin Santo Cappuccio 2023-11-15 18:08:19 -08:00
parent d52ed2eda4
commit fb41f849f8
2 changed files with 86 additions and 118 deletions

View File

@ -11,9 +11,7 @@
#include "spi.pio.h"
#include "pio_spi.h"
#define MYNAMEISERIC 0 //on the board I sent to eric, the data and clock lines are bodged to GPIO 18 and 19. To allow for using hardware SPI
#define MYNAMEISERIC 0 // on the board I sent to eric, the data and clock lines are bodged to GPIO 18 and 19. To allow for using hardware SPI
int chipToPinArray[12] = {CS_A, CS_B, CS_C, CS_D, CS_E, CS_F, CS_G, CS_H, CS_I, CS_J, CS_K, CS_L};
PIO pio = pio0;
@ -103,11 +101,10 @@ void isrFromPio(void)
digitalWriteFast(CS_J, LOW);
digitalWriteFast(CS_K, LOW);
digitalWriteFast(CS_L, LOW);
delayMicroseconds(2);
delayMicroseconds(2);
irq_flags = pio0_hw->irq;
pio_interrupt_clear(pio, PIO0_IRQ_0);
hw_clear_bits(&pio0_hw->irq, irq_flags);
}
void initCH446Q(void)
@ -116,14 +113,11 @@ void initCH446Q(void)
uint dat = 14;
uint clk = 15;
if (MYNAMEISERIC)
{
dat = 18;
clk = 19;
}
if (MYNAMEISERIC)
{
dat = 18;
clk = 19;
}
uint cs = 7;
@ -174,9 +168,7 @@ if (MYNAMEISERIC)
digitalWrite(RESETPIN, LOW);
}
void resetArduino (void)
void resetArduino(void)
{
int lastPath = MAX_BRIDGES - 1;
path[lastPath].chip[0] = CHIP_I;
@ -188,10 +180,7 @@ void resetArduino (void)
sendPath(lastPath, 1);
delay(100);
sendPath(lastPath, 0);
sendPath(lastPath, 0);
}
void sendAllPaths(void) // should we sort them by chip? for now, no
{
@ -204,32 +193,29 @@ void sendAllPaths(void) // should we sort them by chip? for now, no
continue;
}
sendPath(i, 1);
if (debugNTCC2)
{
Serial.print("path ");
Serial.print(i);
Serial.print(" \t");
printPathType(i);
Serial.print(" \n\r");
for (int j = 0; j < 4; j++)
{
printChipNumToChar(path[i].chip[j]);
Serial.print(" x[");
Serial.print(j);
Serial.print("]:");
Serial.print(path[i].x[j]);
Serial.print(" y[");
Serial.print(j);
Serial.print("]:");
Serial.print(path[i].y[j]);
Serial.print(" \t ");
if (debugNTCC)
{
Serial.print("path ");
Serial.print(i);
Serial.print(" \t");
printPathType(i);
Serial.print(" \n\r");
for (int j = 0; j < 4; j++)
{
printChipNumToChar(path[i].chip[j]);
Serial.print(" x[");
Serial.print(j);
Serial.print("]:");
Serial.print(path[i].x[j]);
Serial.print(" y[");
Serial.print(j);
Serial.print("]:");
Serial.print(path[i].y[j]);
Serial.print(" \t ");
}
Serial.print("\n\n\r");
}
}
Serial.print("\n\n\r");
}
}
}
void sendPath(int i, int setOrClear)
@ -249,37 +235,37 @@ void sendPath(int i, int setOrClear)
chipToConnect = path[i].chip[chip];
if (path[i].y[chip] == -1 || path[i].x[chip] == -1)
{
//Serial.print("!");
continue;
}
if (path[i].y[chip] == -1 || path[i].x[chip] == -1)
{
// Serial.print("!");
continue;
}
chYdata = path[i].y[chip];
chXdata = path[i].x[chip];
chYdata = path[i].y[chip];
chXdata = path[i].x[chip];
chYdata = chYdata << 5;
chYdata = chYdata & 0b11100000;
chYdata = chYdata << 5;
chYdata = chYdata & 0b11100000;
chXdata = chXdata << 1;
chXdata = chXdata & 0b00011110;
chXdata = chXdata << 1;
chXdata = chXdata & 0b00011110;
chAddress = chYdata | chXdata;
chAddress = chYdata | chXdata;
if (setOrClear == 1)
{
chAddress = chAddress | 0b00000001; // this last bit determines whether we set or unset the path
}
if (setOrClear == 1)
{
chAddress = chAddress | 0b00000001; // this last bit determines whether we set or unset the path
}
chAddress = chAddress << 24;
chAddress = chAddress << 24;
// delayMicroseconds(50);
// delayMicroseconds(50);
delayMicroseconds(60);
delayMicroseconds(30);
pio_sm_put(pio, sm, chAddress);
pio_sm_put(pio, sm, chAddress);
delayMicroseconds(100);
delayMicroseconds(60);
//}
}
}

View File

@ -31,8 +31,6 @@
volatile int sendAllPathsCore2 = 0; // this signals the core 2 to send all the paths to the CH446Q
// https://wokwi.com/projects/367384677537829889
void setup()
@ -50,13 +48,13 @@ void setup()
#endif
initADC();
delay (1);
delay(1);
initDAC();
delay (1);
delay(1);
initINA219();
delay (1);
delay(1);
Serial.begin(115200);
delay (4);
delay(4);
#ifdef FSSTUFF
LittleFS.begin();
#endif
@ -64,7 +62,7 @@ delay (4);
setDac1_8Vvoltage(1.9);
clearAllNTCC();
delay (4);
delay(4);
}
void setup1()
@ -74,16 +72,13 @@ void setup1()
initCH446Q();
#endif
//delay (4);
// delay (4);
initLEDs();
startupColors();
lightUpRail();
showLEDsCore2 = 1;
}
void loop()
@ -92,11 +87,11 @@ void loop()
char input;
unsigned long timer = 0;
//while (1) rainbowBounce(80); //I uncomment this to test the LEDs on a fresh board
//while (1) randomColors(0,90);
// while (1) rainbowBounce(80); //I uncomment this to test the LEDs on a fresh board
// while (1) randomColors(0,90);
menu:
//showLEDsCore2 = 1;
// showLEDsCore2 = 1;
Serial.print("\n\n\r\t\t\tMenu\n\n\r");
Serial.print("\tn = show netlist\n\r");
Serial.print("\tb = show bridge array\n\r");
@ -147,24 +142,24 @@ menu:
break;
}
case 'a':
{
resetArduino(); // reset works
// uploadArduino(); //this is unwritten
}
// case 'a':
// {
// resetArduino(); // reset works
// // uploadArduino(); //this is unwritten
// }
case 'f':
digitalWrite(RESETPIN, HIGH);
clearAllNTCC();
delay(5);
//showLEDsCore2 = 1;
digitalWrite(RESETPIN, LOW);
//delay(5);
//resetArduino();
// delay(1);
sendAllPathsCore2 = 1;
// showLEDsCore2 = 1;
// delay(5);
// resetArduino();
sendAllPathsCore2 = 1;
timer = millis();
#ifdef FSSTUFF
clearNodeFile();
@ -173,11 +168,11 @@ sendAllPathsCore2 = 1;
openNodeFile();
getNodesToConnect();
#endif
digitalWrite(RESETPIN, LOW);
bridgesToPaths();
clearLEDs();
assignNetColors();
//showNets();
// showNets();
#ifdef PIOSTUFF
sendAllPathsCore2 = 1;
@ -192,8 +187,6 @@ sendAllPathsCore2 = 1;
Serial.print("ms");
}
break;
case '\n':
@ -284,7 +277,6 @@ sendAllPathsCore2 = 1;
sendAllPathsCore2 = 1;
}
break;
case 'r':
resetArduino();
@ -357,63 +349,53 @@ sendAllPathsCore2 = 1;
}
unsigned long logoFlashTimer = 0;
void loop1() // core 2 handles the LEDs and the CH446Q8
{
//while (1) rainbowBounce(50); //I uncomment this to test the LEDs on a fresh board
// while (1) rainbowBounce(50); //I uncomment this to test the LEDs on a fresh board
if (showLEDsCore2 >= 1)
{
int rails = showLEDsCore2;
//showNets();
// showNets();
if (rails == 1)
{
lightUpRail();
}
lightUpRail();
}
if (rails > 3)
{
Serial.print("\n\r");
Serial.print(rails);
}
delayMicroseconds(5200);
delayMicroseconds(3200);
leds.show();
delayMicroseconds(9200);
delayMicroseconds(8200);
showLEDsCore2 = 0;
}
if (sendAllPathsCore2 == 1)
{
delayMicroseconds(12200);
delayMicroseconds(6200);
sendAllPaths();
delayMicroseconds(4200);
delayMicroseconds(2200);
showNets();
delayMicroseconds(9200);
sendAllPathsCore2 = 0;
}
if (logoFlash == 2)
{
logoFlashTimer = millis();
logoFlash = 1;
}
}
if (logoFlash == 1 && logoFlashTimer != 0 && millis() - logoFlashTimer > 600)
{
logoFlash = 0;
logoFlashTimer = 0;
//lightUpRail();
// lightUpRail();
leds.setPixelColor(110, 0x550008);
leds.show();
}
}