A valve based computer produces clocks at approx 518 KHz and a trigger pulse every 576 clocks.
Simple monitoring and display is via LCD for every 1000 trigger pulses displaying 576000 clks.
The following code originally written for Arduino_Due works perfectly, and has since been ported to a Raspberry Pico using SIO for high speed monitoring.
The problem - counting the first 1000 trigger pulses gives an error of -2 ie. clks=575998
Afterwards the clock count is perfect and completely error free, displaying clks=576000
What might be causing the loop to miscount the data? or maybe some other problem exists...
case 4: {
lblx:
clkCnt = 0; trigCnt = 0; dnCnt = mjrCyc; // mjrCyc defined as 576
while ( (sio_hw->gpio_in & 0x00002800) != 0x00002800 ); // wait until Trig0 & Clk both Hi
lbly:
while ( (sio_hw->gpio_in & 0x00000800) == 0x00000800 ); // hold on Clk Hi
lblz:
clkCnt++; REG = 0; dnCnt--; // update values
while ( (sio_hw->gpio_in & 0x00000800) == 0x00000000 ); // hold on Clk Lo
do { // hold on Clk Hi
REGX = sio_hw->gpio_in & 0x00002800 ; // catch Trg0 & Clk before Clk goes Lo
REG |= REGX;
} while ((REGX & 0x00000800) == 0x00000800 ); // fwds when Clk goes Lo
REG = ( REG & 0x00002000 ? 1 : 0 ); // if Trg0 was present, set REG = 1
if ( REG == 0 ) goto lblz;
trigCnt++;
( dnCnt >= 0 ? negErr += dnCnt : posErr += dnCnt ); dnCnt = mjrCyc; //mjrCyc=576
if (trigCnt < 1000) goto lblz;
interrupts();
toggleA = !toggleA;
lcd.setCursor(0, 0); // format is lcd.setCursor(pos'n, line)
lcd.print("Clks= "); lcd.print(clkCnt); lcd.print(" ");
lcd.setCursor(15, 0); ( toggleA ? lcd.print("<") : lcd.print(">"));
lcd.setCursor(0, 1); lcd.print(" ");
lcd.setCursor(0, 1); lcd.print("+E="); lcd.print(posErr);
lcd.setCursor(8, 1); lcd.print("-E="); lcd.print(negErr);
delay(300);
noInterrupts();
goto lblx;
break;
}
Many thanks in advance for possible solutions.....