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 "spi.pio.h"
#include "pio_spi.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}; 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; PIO pio = pio0;
@ -103,11 +101,10 @@ void isrFromPio(void)
digitalWriteFast(CS_J, LOW); digitalWriteFast(CS_J, LOW);
digitalWriteFast(CS_K, LOW); digitalWriteFast(CS_K, LOW);
digitalWriteFast(CS_L, LOW); digitalWriteFast(CS_L, LOW);
delayMicroseconds(2); delayMicroseconds(2);
irq_flags = pio0_hw->irq; irq_flags = pio0_hw->irq;
pio_interrupt_clear(pio, PIO0_IRQ_0); pio_interrupt_clear(pio, PIO0_IRQ_0);
hw_clear_bits(&pio0_hw->irq, irq_flags); hw_clear_bits(&pio0_hw->irq, irq_flags);
} }
void initCH446Q(void) void initCH446Q(void)
@ -116,14 +113,11 @@ void initCH446Q(void)
uint dat = 14; uint dat = 14;
uint clk = 15; uint clk = 15;
if (MYNAMEISERIC)
if (MYNAMEISERIC) {
{
dat = 18; dat = 18;
clk = 19; clk = 19;
}
}
uint cs = 7; uint cs = 7;
@ -174,9 +168,7 @@ if (MYNAMEISERIC)
digitalWrite(RESETPIN, LOW); digitalWrite(RESETPIN, LOW);
} }
void resetArduino(void)
void resetArduino (void)
{ {
int lastPath = MAX_BRIDGES - 1; int lastPath = MAX_BRIDGES - 1;
path[lastPath].chip[0] = CHIP_I; path[lastPath].chip[0] = CHIP_I;
@ -189,9 +181,6 @@ void resetArduino (void)
sendPath(lastPath, 1); sendPath(lastPath, 1);
delay(100); delay(100);
sendPath(lastPath, 0); sendPath(lastPath, 0);
} }
void sendAllPaths(void) // should we sort them by chip? for now, no void sendAllPaths(void) // should we sort them by chip? for now, no
{ {
@ -204,8 +193,8 @@ void sendAllPaths(void) // should we sort them by chip? for now, no
continue; continue;
} }
sendPath(i, 1); sendPath(i, 1);
if (debugNTCC2) if (debugNTCC)
{ {
Serial.print("path "); Serial.print("path ");
Serial.print(i); Serial.print(i);
Serial.print(" \t"); Serial.print(" \t");
@ -223,13 +212,10 @@ if (debugNTCC2)
Serial.print("]:"); Serial.print("]:");
Serial.print(path[i].y[j]); Serial.print(path[i].y[j]);
Serial.print(" \t "); Serial.print(" \t ");
} }
Serial.print("\n\n\r"); Serial.print("\n\n\r");
} }
} }
} }
void sendPath(int i, int setOrClear) void sendPath(int i, int setOrClear)
@ -251,7 +237,7 @@ void sendPath(int i, int setOrClear)
if (path[i].y[chip] == -1 || path[i].x[chip] == -1) if (path[i].y[chip] == -1 || path[i].x[chip] == -1)
{ {
//Serial.print("!"); // Serial.print("!");
continue; continue;
} }
@ -275,11 +261,11 @@ void sendPath(int i, int setOrClear)
// 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 volatile int sendAllPathsCore2 = 0; // this signals the core 2 to send all the paths to the CH446Q
// https://wokwi.com/projects/367384677537829889 // https://wokwi.com/projects/367384677537829889
void setup() void setup()
@ -50,13 +48,13 @@ void setup()
#endif #endif
initADC(); initADC();
delay (1); delay(1);
initDAC(); initDAC();
delay (1); delay(1);
initINA219(); initINA219();
delay (1); delay(1);
Serial.begin(115200); Serial.begin(115200);
delay (4); delay(4);
#ifdef FSSTUFF #ifdef FSSTUFF
LittleFS.begin(); LittleFS.begin();
#endif #endif
@ -64,7 +62,7 @@ delay (4);
setDac1_8Vvoltage(1.9); setDac1_8Vvoltage(1.9);
clearAllNTCC(); clearAllNTCC();
delay (4); delay(4);
} }
void setup1() void setup1()
@ -74,16 +72,13 @@ void setup1()
initCH446Q(); initCH446Q();
#endif #endif
//delay (4); // delay (4);
initLEDs(); initLEDs();
startupColors(); startupColors();
lightUpRail(); lightUpRail();
showLEDsCore2 = 1; showLEDsCore2 = 1;
} }
void loop() void loop()
@ -92,11 +87,11 @@ void loop()
char input; char input;
unsigned long timer = 0; unsigned long timer = 0;
//while (1) rainbowBounce(80); //I uncomment this to test the LEDs on a fresh board // while (1) rainbowBounce(80); //I uncomment this to test the LEDs on a fresh board
//while (1) randomColors(0,90); // while (1) randomColors(0,90);
menu: menu:
//showLEDsCore2 = 1; // showLEDsCore2 = 1;
Serial.print("\n\n\r\t\t\tMenu\n\n\r"); Serial.print("\n\n\r\t\t\tMenu\n\n\r");
Serial.print("\tn = show netlist\n\r"); Serial.print("\tn = show netlist\n\r");
Serial.print("\tb = show bridge array\n\r"); Serial.print("\tb = show bridge array\n\r");
@ -147,24 +142,24 @@ menu:
break; break;
} }
case 'a': // case 'a':
{ // {
resetArduino(); // reset works // resetArduino(); // reset works
// uploadArduino(); //this is unwritten // // uploadArduino(); //this is unwritten
} // }
case 'f': case 'f':
digitalWrite(RESETPIN, HIGH); digitalWrite(RESETPIN, HIGH);
clearAllNTCC(); clearAllNTCC();
delay(5); // delay(1);
//showLEDsCore2 = 1; // showLEDsCore2 = 1;
digitalWrite(RESETPIN, LOW);
//delay(5);
//resetArduino();
sendAllPathsCore2 = 1; // delay(5);
// resetArduino();
sendAllPathsCore2 = 1;
timer = millis(); timer = millis();
#ifdef FSSTUFF #ifdef FSSTUFF
clearNodeFile(); clearNodeFile();
@ -173,11 +168,11 @@ sendAllPathsCore2 = 1;
openNodeFile(); openNodeFile();
getNodesToConnect(); getNodesToConnect();
#endif #endif
digitalWrite(RESETPIN, LOW);
bridgesToPaths(); bridgesToPaths();
clearLEDs(); clearLEDs();
assignNetColors(); assignNetColors();
//showNets(); // showNets();
#ifdef PIOSTUFF #ifdef PIOSTUFF
sendAllPathsCore2 = 1; sendAllPathsCore2 = 1;
@ -192,8 +187,6 @@ sendAllPathsCore2 = 1;
Serial.print("ms"); Serial.print("ms");
} }
break; break;
case '\n': case '\n':
@ -285,7 +278,6 @@ sendAllPathsCore2 = 1;
} }
break; break;
case 'r': case 'r':
resetArduino(); resetArduino();
break; break;
@ -357,63 +349,53 @@ sendAllPathsCore2 = 1;
} }
unsigned long logoFlashTimer = 0; unsigned long logoFlashTimer = 0;
void loop1() // core 2 handles the LEDs and the CH446Q8 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) if (showLEDsCore2 >= 1)
{ {
int rails = showLEDsCore2; int rails = showLEDsCore2;
//showNets(); // showNets();
if (rails == 1) if (rails == 1)
{ {
lightUpRail(); lightUpRail();
} }
if (rails > 3) if (rails > 3)
{ {
Serial.print("\n\r"); Serial.print("\n\r");
Serial.print(rails); Serial.print(rails);
} }
delayMicroseconds(5200); delayMicroseconds(3200);
leds.show(); leds.show();
delayMicroseconds(9200); delayMicroseconds(8200);
showLEDsCore2 = 0; showLEDsCore2 = 0;
} }
if (sendAllPathsCore2 == 1) if (sendAllPathsCore2 == 1)
{ {
delayMicroseconds(12200); delayMicroseconds(6200);
sendAllPaths(); sendAllPaths();
delayMicroseconds(4200); delayMicroseconds(2200);
showNets(); showNets();
delayMicroseconds(9200); delayMicroseconds(9200);
sendAllPathsCore2 = 0; sendAllPathsCore2 = 0;
} }
if (logoFlash == 2) if (logoFlash == 2)
{ {
logoFlashTimer = millis(); logoFlashTimer = millis();
logoFlash = 1; logoFlash = 1;
} }
if (logoFlash == 1 && logoFlashTimer != 0 && millis() - logoFlashTimer > 600) if (logoFlash == 1 && logoFlashTimer != 0 && millis() - logoFlashTimer > 600)
{ {
logoFlash = 0; logoFlash = 0;
logoFlashTimer = 0; logoFlashTimer = 0;
//lightUpRail(); // lightUpRail();
leds.setPixelColor(110, 0x550008); leds.setPixelColor(110, 0x550008);
leds.show(); leds.show();
} }
} }